ups there is a lot of stuff in this code - i simplyfied him:
Code:
function player_fight()
{
var animdist;
var rdm;
while(1)
{
if(mouse_left && mouse_mode == 0)
{
vec_set(temp.x,nullvector);
temp.x = 48; //sword range
vec_rotate(temp.x,camera.pan);
vec_add(temp.x,player.x);
trace_mode = ignore_me + ignore_models;
result = trace(my.x,temp.x);
if(result != 0)
{
snd_play(hit_wav,10,0); //sound for hitting a wall
}else{
snd_play(swing_wav,50,0);
}
//use this if you want area damage or use activate_shoot in trace above
temp.pan = 90;
temp.tilt = 90;
temp.z = 96;
damage = player_dmg; //use your own var^^
scan_entity(camera.x,temp);
animdist = 0;
rdm += 1;
if(rdm%2 == 0)
{
while(animdist < 100)
{
ent_animate(player_weapon,"attack_a",animdist,anm_cycle);
animdist += 10 * time;
wait(1);
}
}
if(rdm%2 == 1)
{
while(animdist < 100)
{
ent_animate(player_weapon,"attack_b",animdist,anm_cycle);
animdist += 10 * time;
wait(1);
}
}
while(mouse_left){wait(1);} //delte this if you want to have a cycle - repeat swinging while pressing mouse
}
wait(1);
}
}