Your script should have played the sound. Even though your script could use some clean up, it should work.
However, the "sleep_until" in this case has to go. You have the right idea, but we're dealing with multiple players here.
If one player turns on his flashlight and the plyrnum is set to him, then the script moves on to the next "sleep_until" which waits for the player to turn his flashlight off. Well, in the next tick, the next player is selected by the plyrnum, and if that player was just sitting around with his flashlight off, the script would play a sound for him out of nowhere.
In addition, if that next player
did have his flashlight on, he actually wouldn't have the sound play. It would work backwards for whichever player is selected next.
So, I fixed it by just using one "if" test. It tests for whether the current player has his flashlight, and if he does, it just turns it off immediately and then plays the sound. This prevents any issues with the flashlight.
Since all players will have their flashlight shut off when their sound is played, we can safely test for just having the flashlight turned on instead of worrying about both on and off.
I also cleaned up the script and moved the plyrnum script after the taunt script.
Hopefully this script will work for you. If it compiles correctly, tell me. I saw a perfect opportunity for the "cond" test which I've never used before and I want to see if I got it right xD.
On a side note, even if this script works, you should do what Polamee said and just stick those three sounds into one sound tag as permutations. Either way, it will work the same, but it would be much easier to let the game choose randomly than have to script that in.
That way, you can eliminate the "x" variable and just check the flashlight, and then play that one sound. Whatever suits you best.
(global short x 0)
(global short plyrnum 0)
(script continuous change_x
(set x (random_range 0 2))
)
(script continuous taunt
(if
(= (unit_get_current_flashlight_state (unit (list_get (players) plyrnum))) 1)
(begin
(unit_set_desired_flashlight_state (unit (list_get (players) plyrnum)) 0)
(cond
(
(= x 0)
(sound_impulse_start "sound\dialog\marines\fitzgerald\conditional\combat2\actions\shooting" (unit (list_get (players) plyrnum)) 1)
)
(
(= x 1)
(sound_impulse_start "sound\dialog\marines\fitzgerald\conditional\combat2\groupcomm\searchreport" (unit (list_get (players) plyrnum)) 1)
)
(
(= x 2)
(sound_impulse_start "sound\dialog\marines\fitzgerald\conditional\combat2\postcombatcomments\celebration" (unit (list_get (players) plyrnum)) 1)
)
)
)
)
)
(script continuous plyrnum_stuff
(set plyrnum (+ plyrnum 1))
(if
(> plyrnum 15)
(set plyrnum 0)
)
)