Everything work exept when cick "cancel button" there is no sound.
Here is the code so far, so you can check it.
Is this good to place "sound comand" in 2 diferent places?
Code:
/////////////////////////////////////////
// On mouse-over
bmap pl1_hover = <pl1-h.bmp>;
bmap pl2_hover = <pl2-h.bmp>;
bmap pl3_hover = <pl3-h.bmp>;
bmap pl4_hover = <pl4-h.bmp>;
// Normal
bmap pl1_normal = <play1.bmp>;
bmap pl2_normal = <play2.bmp>;
bmap pl3_normal = <play3.bmp>;
bmap pl4_normal = <play4.bmp>;
// Other bmaps
bmap cancel_but = <cancel.bmp>;
bmap plSelectMap = <backg.bmp>;
/////////////////////////////////////////
// Player models
string pl1_mdl = <pl1.mdl>;
string pl2_mdl = <pl2.mdl>;
string pl3_mdl = <pl3.mdl>;
string pl4_mdl = <pl4.mdl>;
string* ptr_string; // String pointer
/////////////////////////////////////////
// Constants
define numStrings,4;
/////////////////////////////////////////
// Variables
var ptrs_set = 0;
var string_ptrs[numStrings];
/////////////////////////////////////////
// Function prototypes
function plSelect(but,pan);
function plSelect_cancel();
/////////////////////////////////////////
//Sound settings
sound pl1_snd = <c1.wav>;
sound pl2_snd = <c2.wav>;
sound pl3_snd = <c3.wav>;
sound pl4_snd = <c4.wav>;
sound cancel_snd = <cancel.wav>;
var_nsave pl_snd_handle;
function pl_sound(but,pan)
{
if(pl_snd_handle != 0)
{
snd_stop(pl_snd_handle);
}
if(but == 1) {pl_snd_handle = snd_play(pl1_snd,100,10);}
if(but == 2) {pl_snd_handle = snd_play(pl2_snd,100,10);}
if(but == 3) {pl_snd_handle = snd_play(pl3_snd,100,10);}
if(but == 4) {pl_snd_handle = snd_play(pl4_snd,100,10);}
if(but == 5) {pl_snd_handle = snd_play(cancel_snd,100,10);}
}
/////////////////////////////////////////
panel plSelectionPan
{
bmap = plSelectMap;
flags = refresh;
button = 20,20,pl1_hover,pl1_normal,pl1_hover,plSelect,null,pl_sound;
button = 20,60,pl2_hover,pl2_normal,pl2_hover,plSelect,null,pl_sound;
button = 20,100,pl3_hover,pl3_normal,pl3_hover,plSelect,null,pl_sound;
button = 20,140,pl4_hover,pl4_normal,pl4_hover,plSelect,null,pl_sound;
button = 20,180,cancel_but,cancel_but,cancel_but,plSelect_cancel,null,pl_sound;
}
/////////////////////////////////////////
function setStrings()
{
string_ptrs[0] = handle(pl1_mdl);
string_ptrs[1] = handle(pl2_mdl);
string_ptrs[2] = handle(pl3_mdl);
string_ptrs[3] = handle(pl4_mdl);
ptrs_set = 1;
}
/////////////////////////////////////////
sound pl1_sel_snd = <sel1.wav>;
sound pl2_sel_snd = <sel2.wav>;
sound pl3_sel_snd = <sel3.wav>;
sound pl4_sel_snd = <sel4.wav>;
sound cancel_sel_snd = <selcan.wav>;
function plSelect(but,pan)
{
if(!player) {return;}
if(!ptrs_set) {setStrings();}
if(but <= 0 || but > numStrings) {return;}
ptr_string = ptr_for_handle(string_ptrs[but - 1]);
ent_morph(player,ptr_string);
if(pl_snd_handle != 0)
{
snd_stop(pl_snd_handle);
}
if(but == 1) {pl_snd_handle = snd_play(pl1_sel_snd,100,10);}
if(but == 2) {pl_snd_handle = snd_play(pl2_sel_snd,100,10);}
if(but == 3) {pl_snd_handle = snd_play(pl3_sel_snd,100,10);}
if(but == 4) {pl_snd_handle = snd_play(pl4_sel_snd,100,10);}
if(but == 5) {pl_snd_handle = snd_play(cancel_sel_snd,100,10);}
plSelectionPan.visible = off;
mouse_mode = 0;
}
/////////////////////////////////////////
function plSelect_cancel()
{
plSelectionPan.visible = off;
mouse_mode = 0;
}
/////////////////////////////////////////
function showPlslPan()
{
plSelectionPan.pos_x = (screen_size.x - bmap_width(plSelectionPan.bmap)) / 2;
plSelectionPan.pos_y = (screen_size.y - bmap_height(plSelectionPan.bmap)) / 2;
plSelectionPan.visible = on;
mouse_mode = 2;
mouse_on();
}
on_mouse_right = showPlslPan;
/////////////////////////////////////////