Workarround "soundStop / closeSound /spamSound"

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Workarround "soundStop / closeSound /spamSound"

Post by trancelistic »

Hey. I finaly managed to do it. No more single wav's that spams multible times.

-- sequence1:
Make a switch, lever or hidden_pressure_plate what ever to your liking (mine is called lever_sound)
--sequence2:
Step 1: link lever_sound to a lua script "soundStart" with the following code WITHOUT time delay

Code: Select all

function startSprintLoop()
if lever_sound:getLeverState() == "activated" 
then teleToggle:toggle() -- this is just to toggle a teleporter thats not used in the game.
playSound("timeloop") -- play the 12 sec wave file
timer_tele:deactivate() -- needed to prevent loop, crashing the game
loopTimer:deactivate() -- needed to prevent loop, crashing the game
end
end
Step 2: Link lever_sound to a new timer (timerDestroy) with 0.09 second value ->> Linked to the next script with the code:

Code: Select all

function leverSoundStop()
if lever_sound:getLeverState() == "activated" 
then lever_sound:destroy() -- destroys the lever, switch or pressure plate to your liking, instandly. so it prevents being activated again for the next 12 seconds --as timer_tele has a delay for 12 seconds
timerDestroy:deactivate() --needed to prevent loop, crashing the game
end
end
Step 3: Link lever_sound to another timer (timer_tele) with e.g a 12 seconds value ( depends how long your sound is and /or having a teleport active, etc etc)

Sequence3:
timer_tele is linked to another lua script ( that triggers after the 12 seconds as above stats) with the following code:

Code: Select all

spawnLeverloop()
spawn("lever", 11, 15, 5, 2, "lever_sound") --spawns the lever back where it was destoyed in sequence 1, step 2
       lever_sound:addConnector("activate","loopTimer","activate") -- connects that new spawned lever to another timer (loopTimer)
timerDestroy:deactivate() --needed to prevent loop, crashing the game
timer_tele:deactivate() --needed to prevent loop, crashing the game
loopTimer:deactivate() --needed to prevent loop, crashing the game
end
sequence 4:
step 1:
Pressing the new spawned lever_sound trigger will run another timer called "loopTimer" with a 0.01 sec delay/interval
step 2: Timer "looptimer" is linked to a script "soundStart2" with following code:

Code: Select all

function startSprintLoop2()
if lever_sound:getLeverState() == "activated"
then teleToggle:toggle()
playSound("timeloop")
timer_tele:activate() -- a tele in game that be deactivated after 12 seconds by ]"timer_tele"
loopTimer:deactivate() stops timer to prevent crashing the game
end
end
step 2 The timer "loopTimer" is also connected to another timer "timerDestroy"
step 3 "timerDestroy" is connected to the luascript: "stopSound" with the following code:

Code: Select all

function leverSoundStop()
if lever_sound:getLeverState() == "activated" 
then lever_sound:destroy() -- destroys the lever again.
timerDestroy:deactivate() --needed to prevent loop, crashing the game
end
end
Now it keeps on looping without triggering the same sound over and over and without crashing the game.
I've used a lever in this case but it works with a hidden_pressure_plate, etc as well.
Video link:
Post Reply