Modme Forums

Playing a sound that loops when player touches trigger hurt

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: Dextro62
I have an area in my map that hurts the player if they enter it. I would like it to play a looping sound when the player enters the trigger_hurt that then stops when the player leaves the trigger hurt. I'd also like to have it so that only the player in the trigger_hurt hears the sound.
I attempted to script this myself but the sound didn't loop and it only played the first time I touched the trigger.
Any help would be appreciated.


ModmeBot:

Reply By: Abnormal202
I haven't tested it, but see if you can get this to work:

function hurt_trig_sound()
{
	trig = GetEnt("HURT TRIG TARGETNAME","targetname");
	players = GetPlayers();
	while(1)
	{
		foreach( player in players)
		{
			if( player IsTouching(trig))
			{
				player playloopsound ("YOUR ALIAS NAME HERE");
				player.was_in_hurt_trig = true;
			}
			else if(player.was_in_hurt_trig == true)
			{
				player stoploopsound();
				player.was_in_hurt_trig = false;
			}
		}
		wait(0.05);
	}
}
I'm not sure how the looping sound functions work, I haven't used them yet, but see if this works.


ModmeBot:

Reply By: Dextro62
I tried this but the sound didn't play. I added couple of lines of code to display text messages to see what lines of code was running.
It looked like this.

function hurt_trig_sound()
{
	trig = GetEnt("hurt","targetname");
	players = GetPlayers();
	while(1)
	{
		foreach( player in players)
		IPrintLnBold ("after foreach player");
		{
			if( player IsTouching(trig))
			{
				player playloopsound ("d_switch_on2");
				player.was_in_hurt_trig = true;
				IPrintLnBold ("after hurt trig is true");
			}
			else if(player.was_in_hurt_trig == true)
			{
				player stoploopsound();
				player.was_in_hurt_trig = false;
				IPrintLnBold ("after hurt trig false");
			}
		}
		wait(0.05);
	}
}


As soon as the game started the text "after trig hurt is true" kept repeating and didn't stop.