# Define the script. 'scriptable' means it can be attached to devices. script BarnTrapScript is scriptable # These are "Bindings." # They let you drag and drop devices from the Outliner into this script. # This is how we connect the Scene Graph to our code. trigger_volume: Trigger Volume = Trigger Volume'None' prop_mover: Prop Mover = Prop Mover'None' # Variable: A simple on/off switch. # False means the trap is ready. True means it's cooling down. trap_ready: bool = true # Event: This function runs automatically when a player enters the volume. # 'server' means this logic runs on the game server, not just on your computer. @event OnBegin() is server # We need to listen for the 'Entered' event on the trigger. # This is like setting up a microphone. trigger_volume.EnteredEvent.Bind(OnPlayerEntered) # This function is called when the 'Entered' event fires. OnPlayerEntered(player: Player) is server # Check if the trap is ready. if trap_ready == true # Set trap to not ready (cooldown starts). trap_ready = false # Activate the Prop Mover. # This is like flipping the switch on a device. prop_mover.Activate() # Wait 5 seconds, then reset the trap. # We use a simple timer event for this. @event on_reset_timer() is server trap_ready = true # Unbind the timer so it doesn't run again. on_reset_timer.Unbind() # Start the timer. # '5.0' is the time in seconds. on_reset_timer.Set(5.0)