/////////////////////////////////////////
// Player Selection/Switching script
//
// (c) 2006 by Claus N.
// Nighthawk Arts
// www.nighthawk.dk
/////////////////////////////////////////
define anim_state,skill21;
define active,flag1;
//////////////////////////////////////////
// Define all your animation states below
define state_stand,0;
define state_walk,1;
define state_run,2;
define state_spin,3;
define state_bounce,4;
//////////////////////////////////////////
// Animation names
string anim_stand = "stand";
string anim_walk = "walk";
string anim_run = "run";
string anim_spin = "attack";
string anim_bounce = "bounce";
/////////////////////////////////////////
// Pictures
bmap selBG_map = <backg.tga>;
bmap but1_map = <but1.tga>;
bmap but2_map = <but2.tga>;
bmap but3_map = <but3.tga>;
bmap but4_map = <but4.tga>;
bmap but5_map = <but5.tga>;
bmap butc_map = <cancel.tga>;
bmap but1_over_map = <but1-h.tga>;
bmap but2_over_map = <but2-h.tga>;
bmap but3_over_map = <but3-h.tga>;
bmap but4_over_map = <but4-h.tga>;
bmap but5_over_map = <but5-h.tga>;
bmap butc_over_map = <cancel-h.tga>;
/////////////////////////////////////////
// Sounds
sound pl1_snd = <click.wav>;
sound pl2_snd = <click.wav>;
sound pl3_snd = <click.wav>;
sound pl4_snd = <click.wav>;
sound pl5_snd = <click.wav>;
sound cancel_snd = <click.wav>;
sound pl1_over_snd = <flop.wav>;
sound pl2_over_snd = <flop.wav>;
sound pl3_over_snd = <flop.wav>;
sound pl4_over_snd = <flop.wav>;
sound pl5_over_snd = <flop.wav>;
sound cancel_over_snd = <flop.wav>;
sound ent_rightclick = <click.wav>;
sound ent_leftclick = <click.wav>;
sound sound_on_q = <q.wav>;
sound sound_on_e = <e.wav>;
sound sound_on_idle = <idle.wav>;
/////////////////////////////////////////
// Models
string pl1_mdl = <FromBack.mdl>;
string pl2_mdl = <ride.mdl>;
string pl3_mdl = <Tpose.mdl>;
string pl4_mdl = <Tpose.mdl>;
string pl5_mdl = <Tpose.mdl>;
/////////////////////////////////////////
var_nsave snd_handle;
var actorHandle;
/////////////////////////////////////////
string level_str = <level.wmb>;
/////////////////////////////////////////
function butOver(but,pan);
function butClick(but,pan);
/////////////////////////////////////////
panel selectionPan
{
bmap = selBG_map;
flags = refresh;
button = 20,30,but1_map,but1_map,but1_over_map,butClick,null,butOver;
button = 20,60,but2_map,but2_map,but2_over_map,butClick,null,butOver;
button = 20,90,but3_map,but3_map,but3_over_map,butClick,null,butOver;
button = 20,120,but4_map,but4_map,but4_over_map,butClick,null,butOver;
button = 20,150,but5_map,but5_map,but5_over_map,butClick,null,butOver;
button = 20,180,butc_map,butc_map,butc_over_map,butClick,null,butOver;
}
/////////////////////////////////////////
function butOver(but,pan)
{
if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_over_snd,100,10);}
if(but == 2) {snd_handle = snd_play(pl2_over_snd,100,10);}
if(but == 3) {snd_handle = snd_play(pl3_over_snd,100,10);}
if(but == 4) {snd_handle = snd_play(pl4_over_snd,100,10);}
if(but == 5) {snd_handle = snd_play(pl5_over_snd,100,10);}
if(but == 6) {snd_handle = snd_play(cancel_over_snd,100,10);}
}
/////////////////////////////////////////
function butClick(but,pan)
{
mouse_mode = 0;
if(actorHandle == 0) {return;}
you = ptr_for_handle(actorHandle);
actorHandle = 0;
if(!you) {return;}
if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_snd,100,10);ent_morph(you,pl1_mdl);}
if(but == 2) {snd_handle = snd_play(pl2_snd,100,10);ent_morph(you,pl2_mdl);}
if(but == 3) {snd_handle = snd_play(pl3_snd,100,10);ent_morph(you,pl3_mdl);}
if(but == 4) {snd_handle = snd_play(pl4_snd,100,10);ent_morph(you,pl4_mdl);}
if(but == 5) {snd_handle = snd_play(pl5_snd,100,10);ent_morph(you,pl5_mdl);}
if(but == 6) {snd_handle = snd_play(cancel_snd,100,10);}
selectionPan.visible = off;
wait(2);
mouse_mode = 0;
}
/////////////////////////////////////////
function init_mouse()
{
if((mouse_pos.x < selectionPan.pos_x
|| mouse_pos.x > selectionPan.pos_x + bmap_width(selectionPan.bmap))
|| (mouse_pos.y < selectionPan.pos_y
|| mouse_pos.y > selectionPan.pos_y + bmap_height(selectionPan.bmap)))
{
selectionPan.visible = off;
}
wait(1);
mouse_toggle();
}
/////////////////////////////////////////
function selPan_Show(ent)
{
if(ent == 0) {return;}
you = ptr_for_handle(ent);
if(!you) {return;}
temp.x = you.x;
temp.y = you.y;
temp.z = you.z + you.min_z;
vec_to_screen(temp,camera);
selectionPan.pos_x = clamp(temp.x,0,screen_size.x - bmap_width(selectionPan.bmap));
selectionPan.pos_y = clamp(temp.y,0,screen_size.y - bmap_height(selectionPan.bmap));
actorHandle = ent;
selectionPan.visible = on;
}
/////////////////////////////////////////
function animateMe()
{
while(my)
{
if(my.anim_state == state_stand)
{
ent_animate(my,anim_stand,my.skill46,ANM_CYCLE);
my.skill46 += 10 * time;
}
if(my.anim_state == state_walk)
{
ent_animate(my,anim_walk,my.skill46,ANM_CYCLE);
my.skill46 += 6 * time;
}
if(my.anim_state == state_run)
{
ent_animate(my,anim_run,my.skill46,ANM_CYCLE);
my.skill46 += 10 * time;
}
if(my.anim_state == state_spin)
{
ent_animate(my,anim_spin,my.skill46,ANM_CYCLE);
my.skill46 += 8 * time;
}
if(my.anim_state == state_bounce)
{
ent_animate(my,anim_bounce,my.skill46,ANM_CYCLE);
my.skill46 += 8 * time;
}
my.skill46 %= 100;
wait(1);
}
}
/////////////////////////////////////////
function actorClicked
{
if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(event_type == event_rightclick)
{
snd_handle = snd_play(ent_rightclick,100,10);
selPan_Show(handle(my));
wait(1);
mouse_mode = 2;
mouse_on();
}
if(event_type == event_click)
{
snd_handle = snd_play(ent_leftclick,100,10);
while(mouse_left) {wait(1);}
my.active = on;
while(!mouse_left) {wait(1);}
my.active = off;
}
}
/////////////////////////////////////////
function mtl_xzmaterijal_init
{
vec_set(mtl.emissive_blue,mat_model.emissive_blue);
vec_set(mtl.ambient_blue,mat_model.ambient_blue);
vec_set(mtl.diffuse_blue,mat_model.diffuse_blue);
vec_set(mtl.specular_blue,mat_model.specular_blue);
mtl.power=mat_model.power;
mtl.albedo=mat_model.albedo;
mtl.skill1=pixel_for_vec(vector(0,0,0),0,8888);
}
material mtl_xzmaterijal
{
event=mtl_xzmaterijal_init;
effect=
"
texture entSkin1;
dword mtlSkill1;
technique xzmaterijal
{
pass p0
{
Texture[0]=<entSkin1>;
ZWriteEnable=True;
AlphaBlendEnable=True;//was False
AlphaTestEnable=True;
AlphaRef=<mtlSkill1>;
AlphaFunc=Greater;
CullMode=CCW;
ColorArg1[0]=Texture;
ColorOp[0]=Modulate2X;
ColorArg2[0]=Diffuse;
}
}
technique fallback{pass p0{}}
";
}
/////////////////////////////////////////
action entity_slct
{
my.material=mtl_xzmaterijal;
animateMe();
my.enable_click = on;
my.enable_rightclick = on;
my.event = actorClicked;
while(my)
{
if(my.active)
{
my.ambient = 10;
my.anim_state = state_stand;
if(key_q)
{
my.anim_state = state_spin;
snd_stop(my.skill22);
if(!snd_playing(my.skill32))
{
my.skill32 = snd_loop(sound_on_q,100,10);
}
}
else
{
if(key_e)
{
my.anim_state = state_run;
snd_stop(my.skill22);
if(!snd_playing(my.skill32))
{
my.skill32 = snd_loop(sound_on_e,100,10);
}
}
else
{
snd_stop(my.skill32);
if(!snd_playing(my.skill22))
{
my.skill22 = snd_loop(sound_on_idle,100,10);
}
}
}
}
else
{
snd_stop(my.skill22);
snd_stop(my.skill32);
my.ambient = 0;
my.anim_state = state_stand;
}
wait(1);
}
}
/////////////////////////////////////////
on_mouse_right = init_mouse;
/////////////////////////////////////////
function check_panel()
{
if((mouse_pos.x < selectionPan.pos_x
|| mouse_pos.x > selectionPan.pos_x + bmap_width(selectionPan.bmap))
|| (mouse_pos.y < selectionPan.pos_y
|| mouse_pos.y > selectionPan.pos_y + bmap_height(selectionPan.bmap)))
{
selectionPan.visible = off;
}
}
function init_mouse()
{
check_panel();
wait(1);
mouse_toggle();
}
/////////////////////////////////////////
on_mouse_left = init_mouse;