MtB Posted March 5, 2010 Share Posted March 5, 2010 In order for a trigger box to play a sound effect I use this script: Begin OnTriggerPlaySound SoundNameEnd To prevent the sound from constantly repeating while the player is inside the trigger box I add the "if DoOnce" command, but that means once the trigger box is activated it plays the sound effect and is then permanently deactivated. Is there a script that can reset/reactivate used up trigger boxes at midnight so that they can be reused the next day? These are two of my feeble an non-working attempts at such a script: Attempt 1.ScriptName aaPlaySoundScript Short DoOnce Begin OnTriggerif DoOnce == 0PlaySound SoundNameset DoOnce to 1endif if GetCurrentTime >= 24 && TriggerPrimitive == 1TriggerPrimitive.enableendif End Attempt 2.ScriptName aaPlaySoundScript short DoOnce Begin OnTriggerif DoOnce == 0PlaySound SoundNameset DoOnce to 1endif if GetCurrentTime >= 24 && DoOnce == 1set DoOnce to 0endif End I've tried other variations, also with no success. Can you help? Link to comment Share on other sites More sharing options...
Cipscis Posted March 5, 2010 Share Posted March 5, 2010 You should probably be using an OnTriggerEnter block instead of an OnTrigger block for something like this. GetCurrentTime will never return a value greater than 24. Try using something like this instead:int bDoOnce float fTimeTriggered Begin OnTriggerEnter player if bDoOnce if GetCurrentTime < fTimeTriggered set bDoOnce to 0 endif else set bDoOnce to 1 set fTimeTriggered to GetCurrentTime PlaySound SoundName endif EndP.S. Please use code or codebox tags when posting code. This forces it to be displayed with a fixed width font and maintains indentation, making it easier to read. If you don't know how to indent your code, here is a web-based utility that can do it for you - Script Validator Cipscis Link to comment Share on other sites More sharing options...
BadPenney Posted March 5, 2010 Share Posted March 5, 2010 Here is an object script that I attached to a trigger box that displays a message repeatedly with only a short delay between events. It could be modified easily to play a sound repeatedly: scn TombstoneSCRIPT short TdoOnce float Ttimer Begin OnTriggerEnter Player if ( TdoOnce == 0 ) ShowMessage EpitaphMessage set TdoOnce to 1 endif End Begin OnTriggerLeave Player if ( TdoOnce == 1 ) set Ttimer to 6 endif End Begin GameMode if ( TdoOnce == 1 ) if ( Ttimer <= 0 ) set TdoOnce to 0 else set Ttimer to (Ttimer - GetSecondsPassed) endif endif End If you replace "ShowMessage EpitaphMessage" with "Playsound Whatever" then it would play a sound one time when the trigger box is activated, and reset within a matter of seconds once the player leaves the trigger box. If I remember correctly, the timer was necessary to allow the player to clear the trigger area before attempting to reset. Link to comment Share on other sites More sharing options...
Recommended Posts