# This script makes a door open when a player enters a trigger. using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # This is our main device. # It connects to the Prop Mover and the Trigger. smart_door_device := class(creative_device): # These are the parts we will control. # We will set these in the editor later. @editable door_mover : prop_mover_device = prop_mover_device{} @editable player_trigger : trigger_device = trigger_device{} # We track whether the door is already open so we # do not try to open it again while a player is inside. var DoorIsOpen : logic = false # This function runs once when the game starts. OnBegin() : void = # Subscribe to the trigger's events. # AgentEntersEvent fires when a player walks in. # AgentExitsEvent fires when a player walks out. player_trigger.AgentEntersEvent.Subscribe(OnPlayerEnter) player_trigger.AgentExitsEvent.Subscribe(OnPlayerExit) # Called automatically when a player enters the trigger. OnPlayerEnter(Agent : agent) : void = if (not DoorIsOpen?): # If the door is closed, open it. set DoorIsOpen = true door_mover.MoveToEnd() # Called automatically when a player exits the trigger. OnPlayerExit(Agent : agent) : void = if (DoorIsOpen?): # If the door is open, close it. set DoorIsOpen = false door_mover.MoveToBegin()