# This script makes a treasure chest open when two switches are on. using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /Verse.org/Native } using { /UnrealEngine.com/Temporary/Diagnostics } # This is our main script block. # It runs when the game starts. teamwork_treasure_hunt := class(creative_device): # Wire these two properties to your Switch devices in the UEFN editor. @editable Switch_A_Device : switch_device = switch_device{} @editable Switch_B_Device : switch_device = switch_device{} # Wire this property to your Prop Mover device in the UEFN editor. @editable Treasure_Mover : prop_mover_device = prop_mover_device{} # Wire this property to your Button Solver / HUD Message Device for feedback. # We use a hud_message_device to show on-screen text to players. @editable Message_Device : hud_message_device = hud_message_device{} # This variable holds the state of the switches. # It is a "boolean". A boolean is true or false. # We start with both switches being "off". # var means we can change the value later. var Switch_A_State : logic = false var Switch_B_State : logic = false # This function runs when the script starts. OnBegin() : void = # We listen for events from Switch A. # When Switch A is turned on, we run our handler. Switch_A_Device.TurnedOnEvent.Subscribe(OnSwitchAActivated) # We listen for events from Switch B. # When Switch B is turned on, we run our handler. Switch_B_Device.TurnedOnEvent.Subscribe(OnSwitchBActivated) # This handler runs when Switch A is turned on. OnSwitchAActivated(Agent : agent) : void = set Switch_A_State = true # Show a message so Player 1 knows the partner is needed. Message_Device.Show(Agent) CheckWinCondition() # This handler runs when Switch B is turned on. OnSwitchBActivated(Agent : agent) : void = set Switch_B_State = true CheckWinCondition() # This function checks if we won. CheckWinCondition() : void = # If BOTH states are true, we win! if (Switch_A_State? and Switch_B_State?): OpenTreasure() # Helper function to open treasure using the Prop Mover device. OpenTreasure() : void = # Activate the Prop Mover. It will move the treasure to its end position. # Set the Prop Mover's end position above the chest in the UEFN editor. Treasure_Mover.Begin() Print("Treasure opened! Great teamwork!")