Jump to content

Scripting Primitive Trigger Boxes. Help Required


MtB

Recommended Posts

In order for a trigger box to play a sound effect I use this script:

 

Begin OnTrigger

PlaySound SoundName

End

 

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 OnTrigger

if DoOnce == 0

PlaySound SoundName

set DoOnce to 1

endif

 

if GetCurrentTime >= 24 && TriggerPrimitive == 1

TriggerPrimitive.enable

endif

 

End

 

 

Attempt 2.

ScriptName aaPlaySoundScript

 

short DoOnce

 

Begin OnTrigger

if DoOnce == 0

PlaySound SoundName

set DoOnce to 1

endif

 

if GetCurrentTime >= 24 && DoOnce == 1

set DoOnce to 0

endif

 

End

 

 

I've tried other variations, also with no success. Can you help?

Link to comment
Share on other sites

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

End

P.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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...