Page 1 of 1

Disco Sound Scripting

Posted: Tue Mar 23, 2004 10:39 am
by diego
I built a disco in my map. It plays 4 songs randomly. It's proven to be a whole lot of fun for us to play in. The problem is that people can play 2 or more songs at the same time. The Songs are different lengths so I can't just put a wait on the trigger. It also appears that when players start pounding away on the disco trigger, it will prevent other triggered sounds in my map from working. This may possibly be causing my map to crash as well. Here is the relevant part of my script:

Code: Select all

main:
	local.master = spawn ScriptMaster

  	local.master aliascache piano sound/bktown/pianoman.mp3 soundparms 1.0 1.0 1.0 0.0 300 1000 auto loaded maps "obj dm"
	local.master aliascache Omega1 sound/bktown/Omega1.mp3 soundparms 1.0 1.0 1.0 0.0 200 400 auto loaded maps "obj dm"
	local.master aliascache Omega2 sound/bktown/Omega2.mp3 soundparms 2.0 1.0 1.0 0.0 400 800 auto loaded maps "obj dm"
	local.master aliascache NtGrl1 sound/bktown/NiteGirl.mp3 soundparms 1.0 1.0 1.0 0.0 200 1000 auto loaded maps "obj dm"
	local.master aliascache snore sound/bktown/snore.mp3 soundparms 2.0 1.0 1.0 0.0 200 500 auto loaded maps "obj dm"	
	local.master aliascache Fire sound/bktown/fireplace.mp3 soundparms 1.0 1.0 1.0 0.0 200 500 auto loaded maps "obj dm"
	local.master aliascache Fire2 sound/bktown/fireplace.mp3 soundparms 1.0 1.0 1.0 0.0 200 500 auto loaded maps "obj dm"	
	local.master aliascache Fire3 sound/bktown/fireplace.mp3 soundparms 1.5 1.0 1.0 0.0 300 600 auto loaded maps "obj dm"	
	local.master aliascache Bugsy sound/bktown/BUGS1.mp3 soundparms 1.0 1.0 1.0 0.0 100 300 auto loaded maps "obj dm"
	local.master aliascache Laugh sound/bktown/Laugh.mp3 soundparms 1.0 1.0 1.0 0.0 200 500 auto loaded maps "obj dm"
	local.master aliascache Alarm sound/bktown/Alarm.mp3 soundparms 1.0 1.0 1.0 0.0 500 1000 auto loaded maps "obj dm"
	local.master aliascache Press sound/bktown/Press.mp3 soundparms 0.5 1.0 1.0 0.0 200 350 auto loaded maps "obj dm"
	local.master aliascache Beavis_1 sound/bktown/Beavis_01.mp3 soundparms 1.0 1.0 1.0 0.0 200 500 auto loaded maps "obj dm"
	local.master aliascache Beavis_2 sound/bktown/Beavis_02.mp3 soundparms 1.0 1.0 1.0 0.0 200 500 auto loaded maps "obj dm"
	local.master aliascache Beavis_3 sound/bktown/Beavis_03.mp3 soundparms 1.0 1.0 1.0 0.0 200 500 auto loaded maps "obj dm"
	local.master aliascache Beavis_4 sound/bktown/Beavis_04.mp3 soundparms 1.0 1.0 1.0 0.0 200 500 auto loaded maps "obj dm"
	local.master aliascache Beavis_5 sound/bktown/Beavis_05.mp3 soundparms 1.0 1.0 1.0 0.0 200 500 auto loaded maps "obj dm"
	local.master aliascache Boiler sound/bktown/BoilerRoom.mp3 soundparms 1.2 1.0 1.0 0.0 500 1000 auto loaded maps "obj dm"
	local.master aliascache Slix_1 sound/bktown/Funky.mp3 soundparms 1.2 1.0 1.0 0.0 500 1000 auto loaded maps "obj dm"
	local.master aliascache Slix_2 sound/bktown/GetDown.mp3 soundparms 1.2 1.0 1.0 0.0 500 1000 auto loaded maps "obj dm"
	local.master aliascache Slix_3 sound/bktown/Alive.mp3 soundparms 1.2 1.0 1.0 0.0 500 1000 auto loaded maps "obj dm"
	local.master aliascache Slix_4 sound/bktown/Love.mp3 soundparms 1.2 1.0 1.0 0.0 500 1000 auto loaded maps "obj dm"
	local.master aliascache Flush sound/bktown/flush.mp3 soundparms 3.0 1.0 1.0 0.0 300 500 auto loaded maps "obj dm"
	
	level waittill prespawn

	exec global/DMprecache.scr
	exec global/door_locked.scr::lock
	//exec global/ambient.scr mohdm7


	level.script=maps/dm/BK_town.scr

	setcvar "g_scoreboardpic" "score"

	level waittill spawn
	level.soundplaying = 0
	level.soundplaying2 = 0
	level.soundplaying3 = 0
	level.soundplaying4 = 0


	// set scoreboard messages
	setcvar "g_obj_alliedtext1" "BK Town" 
	setcvar "g_obj_alliedtext2" ""
	setcvar "g_obj_alliedtext3" "created by:"
	setcvar "g_obj_axistext1" " ""
	setcvar "g_obj_axistext2" "=[BK]=theOmega"
	setcvar "g_obj_axistext3" "=[BK]=DonDiego"

	$speaker2 loopsound Omega1
	$speaker3 loopsound Fire
	$speaker4 loopsound Fire2
	$speaker5 loopsound snore
	$speaker6 loopsound Laugh
	$speaker8 loopsound Press
	$speaker9 loopsound Boiler
	$speaker12 loopsound Fire3

end


//////////////////////////////////////////////////
//SOUND SCRIPTS///////////////////////////////////
//////////////////////////////////////////////////
//Sound script for Maddog's Room//////////////////
//////////////////////////////////////////////////
speakerthread:
if (level.soundplaying == 0)
{
	level.soundplaying = 1
	$speaker playsound piano
	iprintlnbold "Report to your room Maddog!"
	wait 43
	level.soundplaying = 0	
}
//$speaker playsound piano
//iprintlnbold "Report to your room Maddog!"
end

/////////////////////////////////////////////////
//Sound script for Omega's Room//////////////////
/////////////////////////////////////////////////
soundthread:
if (level.soundplaying2 == 0)
{
	level.soundplaying2 = 1
	$speaker2 stoploopsound
	$speaker2 playsound Omega2
	wait 60
	level.soundplaying2 = 0
	$speaker2 loopsound Omega1
}
end

/////////////////////////////////////////////////
//Sound script for NightGirl's Room//////////////////
/////////////////////////////////////////////////
organthread:
if (level.soundplaying3 == 0)
{
	level.soundplaying3 = 1
	$speaker6 stoploopsound
	$speaker6 playsound NtGrl1
	wait 36
	level.soundplaying3 = 0
	$speaker6 loopsound Laugh
}
end

flushthread:
	$speaker14 playsound Flush
	wait 10
end

////////////////////////////////////////////////
//Sound script for Kenny's Room//////////////////
/////////////////////////////////////////////////
alarmthread:
	iprintlnbold "WARNING! SECURITY SYSTEM ACTIVATED!"
	$speaker7 playsound Alarm
	wait 16
end

/////////////////////////////////////////////////
//Sound script for Bunny's Room//////////////////
/////////////////////////////////////////////////
docthread:
	$speaker11 playsound Bugsy
	wait 2
end

/////////////////////////////////////////////////
//Sound script for Cornstalker's Room////////////
/////////////////////////////////////////////////
beavisAthread:
	thread ("Beavis_" + (randomint(5) + 1))
end
////////////////////////////////////////////////
Beavis_1:
	$speaker10 playsound Beavis_1
	wait 2
	level.soundplaying4 = 0
end
////////////////////////////////////////////////
Beavis_2:
	$speaker10 playsound Beavis_2
	wait 3
	level.soundplaying4 = 0
end
////////////////////////////////////////////////
Beavis_3:
	$speaker10 playsound Beavis_3
	wait 17
	level.soundplaying4 = 0
end
////////////////////////////////////////////////
Beavis_4:
	$speaker10 playsound Beavis_4
	wait 9
	level.soundplaying4 = 0
end
////////////////////////////////////////////////
Beavis_5:
	$speaker10 playsound Beavis_5
	wait 1
	level.soundplaying4 = 0
end
////////////////////////////////////////////////
/////////////////////////////////////////////////
//Sound script for Slix's Disco///////////////
/////////////////////////////////////////////////
slixthread:
if (level.soundplaying4 == 0)
{
	iprintlnbold "Disco Fever!"	
	thread ("Slix_" + (randomint(4) + 1))	
}
end
////////////////////////////////////////////////
Slix_1:
	$speaker13 playsound Slix_1
	level.soundplaying4 = 1
	wait 28
	level.soundplaying4 = 0
end
////////////////////////////////////////////////
Slix_2:
	$speaker13 playsound Slix_2
	level.soundplaying4 = 1
	wait 52
	level.soundplaying4 = 0
end
////////////////////////////////////////////////
Slix_3:
	$speaker13 playsound Slix_3
	level.soundplaying4 = 1
	wait 62
	level.soundplaying4 = 0
end
////////////////////////////////////////////////
Slix_4:
	$speaker13 playsound Slix_4
	level.soundplaying4 = 1
	wait 20
	level.soundplaying4 = 0
end

The code for the Slix Disco is at the bottom. I thought the "Wait" statements I put in would prevent people from triggering multiple sounds but it doesn't work. I also have 4 objects called "speaker13" in the room so that I have full surround sound. I don't know if that is a problem or not. But it appears that these scripts kill the Alarm script on occasion.


I probably have errors in other parts of the sound scripts as well. I've tried to keep it simple since I am not very experienced with this. I've built this one mostly from things I've seen in the forums. I've edited out all the non-sound related threads.

triggers and waits

Posted: Tue Mar 23, 2004 1:39 pm
by tltrude
Triggers can be switched on and off with:

$my_trigger triggerable
$my_trigger nottriggerable

Also there is this command, but I have never used it.

$my_speaker playsound disco_music wait
$my_speaker waittill sounddone

Posted: Wed Mar 24, 2004 6:47 am
by diego
Thanks. I'll try disabling the triggers. It will be hard to test on the disco though. Even my old script doesn't mess up when It's just me playing the map. But I have another area I can use it in that should make a noticeable difference.

Posted: Wed Mar 24, 2004 8:30 am
by tltrude
Here is something that should help.

The game will automatically pick a sound at random if they have the same name and are numbered.

slixthread:

$slix_trigger nottriggerable
$speaker13 playsound Slix_ wait // randomly picks Slix1 - 4
$speaker13 waittill sounddone
wait 1
$slix_trigger triggerable

end

Posted: Wed Mar 24, 2004 8:51 pm
by diego
I love keeping it simple. I'll try this new shorter version tonight.

I used the nottrigerrable commands last night on the disco and the Beavis thread. Since I have was never able to get the old code to play multiple sounds on my own, all I know is that the new code still works fine. I'll have to test this area on our server to make sure noone else can break it.

The trigger disabling worked great in the Beavis thread. That trigger originally had a 20 second wait on it so that 2 sounds would not overlap. Now I can make the sounds play back to back if you are still standing in the trigger area without the wait.

Posted: Thu Mar 25, 2004 8:02 am
by diego
Whoa! My map did not like the new script. After trying your latest version, the trigger would always function causing songs to be played everytime i hit it. I reverted to my old script. At first even that wouldn't work. But I deleted my PK3 and created a new one from scratch and it works fine. I guess if it's not broke, don't fix it. I'll just stick with the nottrigerable command.

Posted: Thu Mar 25, 2004 2:44 pm
by nuggets
did you know about the command waittill sounddone

$speaker13 playsound Slix_1 wait
$speaker13 waittill sounddone
thread beavisAthread