|
Re: Play sound only one time on key press.
[Re: Realspawn]
#373550
06/10/11 22:14
06/10/11 22:14
|
Joined: Aug 2007
Posts: 1,922 Schweiz
Widi
Serious User
|
Serious User
Joined: Aug 2007
Posts: 1,922
Schweiz
|
Use on_u instead of key_u... Or if you really want key_u:
var soundhandle = 0;
SOUND* hits_snd = "mix1.wav";
{
if (key_u ==1 && !soundhandle)
soundhandle = snd_play(hits_snd,100,0);
}
Last edited by Widi; 06/10/11 22:15.
|
|
|
Re: Play sound only one time on key press.
[Re: Widi]
#373561
06/10/11 23:48
06/10/11 23:48
|
Joined: Jul 2001
Posts: 4,801 netherlands
Realspawn
OP
Expert
|
OP
Expert
Joined: Jul 2001
Posts: 4,801
netherlands
|
mmm i must getting tired Bassicly i want to play a sound every time my player does an attack move. If i add the snd_play i get the annoying echo or the player gets stuck in the animation. Here's my player movement for tonight i give up i really need some sleepzzzzz Although i am happy that i accomplished the movement today learned something at least
action player_code() // attach this action to your player
{
var movement_speed = 10; // movement speed
var anim_percentage;
VECTOR temp;
player = my; // I'm the player
while (1)
{
vec_set (temp.x, my.x); // trace 10,000 quants below the player
temp.z -= 3000;
temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) + 4; // play with 20
temp.x = movement_speed * (key_w - key_s) * time_step;
temp.y = 0;
c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);
if (!key_w && !key_s) // the player isn't moving?
{
ent_animate(my, "idle", anim_percentage, ANM_CYCLE); // play the "stand" animation
anim_percentage += 2 * time_step; // 5 = animation speed
}
else // the player is moving?
{
ent_animate(my, "walkr", anim_percentage, ANM_CYCLE); // play the "walk" animation
anim_percentage += 4 * time_step * (key_w - key_s);
}
{
if (key_c ==1 )
{
ent_animate(my, "attack", anim_percentage, ANM_CYCLE); // play the "walk" animation
anim_percentage += 3 * time_step; // 8 = animation speed
}
if (key_v ==1 )
{
ent_animate(my, "attackk", anim_percentage, ANM_CYCLE); // play the "walk" animation
anim_percentage += 3 * time_step; // 8 = animation speed
}
if (key_b ==1 )
{
ent_animate(my, "atackkk", anim_percentage, ANM_CYCLE); // play the "walk" animation
anim_percentage += 3 * time_step; // 8 = animation speed
}
if (key_f ==1 )
{
ent_animate(my, "attackkkk", anim_percentage, ANM_CYCLE); // play the "walk" animation
anim_percentage += 3 * time_step; // 8 = animation speed
}
if (key_g ==1 )
{
ent_animate(my, "attackkkkk", anim_percentage, ANM_CYCLE); // play the "walk" animation
anim_percentage += 1 * time_step; // 8 = animation speed
}
if (key_g ==1 )
{
ent_animate(my, "attackkkkkk", anim_percentage, ANM_CYCLE); // play the "walk" animation
anim_percentage += 1 * time_step; // 8 = animation speed
}
if (key_u ==1)
{
ent_animate(my, "jump", anim_percentage, ANM_CYCLE); // play the "walk" animation
anim_percentage += 1 * time_step; // 8 = animation speed
}
wait(1);
}
}
}
Last edited by Realspawn; 06/10/11 23:51.
|
|
|
Re: Play sound only one time on key press.
[Re: Theil]
#373586
06/11/11 10:47
06/11/11 10:47
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Just make simple logical "if" comparison in a while loop, like this:
if(run_once == 0)
{
snd_play(attack_wav,80,0);
run_once = 1;
}
You should remember that in while loop everything works each frame again and again. So with this comparison sound will play only once. To play it again, you'll need to set "run_once" back to zero. Set it back to zero when animation fully played, check that by animation percentage.
|
|
|
|