using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # We are creating a "Device" which is a container for our logic. # Think of this as the "Island" object that holds our specific trap. one_shot_trap := class(creative_device): # This is our "Family Tree" reference. # We are telling Verse: "Hey, inside this Island, there is a device # named 'LootTrigger'. Connect it to this script." # Drag your trigger device onto this property in the UEFN details panel. @editable LootTrigger : trigger_device = trigger_device{} # We also grab the Item Granter and the Prop Mover. # If these aren't connected in the details panel, # Verse will complain. Accuracy is key! @editable LootBox : item_granter_device = item_granter_device{} @editable LootBoxProp : prop_mover_device = prop_mover_device{} # This is our "Inventory Slot" (Variable). # It starts as false, meaning the trap is READY. # marks this as mutable so we can change it later. var IsTrapUsed : logic = false # OnBegin runs automatically when the game starts. # This is where we bind our event listener to the trigger. OnBegin() : void = # This is the "Event Handler." # It says: "Whenever LootTrigger sends a 'TriggeredEvent' signal, # run the function below." LootTrigger.TriggeredEvent.Subscribe(OnLootTriggerTriggered) # This function runs every time the trigger is activated. # It receives the agent (player) who stepped on the trigger. OnLootTriggerTriggered(TriggeredAgent : ?agent) : void = # THE BOUNCER LOGIC # Check if the trap has already been used. if (IsTrapUsed = false): # It hasn't been used! Let's activate the trap. # 1. Enable the Item Granter (gives the loot) LootBox.Enable() # 2. Enable the Prop Mover (shows the loot box) LootBoxProp.Enable() # 3. IMPORTANT: Mark the trap as used so it can't happen again. set IsTrapUsed = true # Optional: Disable the trigger itself so it doesn't send signals anymore. # This is like unplugging the smoke signal. LootTrigger.Disable() # If IsTrapUsed is already true, the if block simply doesn't run. # The trap was already used — do nothing. # You could enable a separate "Already Looted" device here if you wanted.