# This is our main script. It lives on a device. # We call this "MyTrapDispenser". using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Fortnite.com/Playspaces } using { /UnrealEngine.com/Temporary/Diagnostics } using { /Verse.org/Simulation } MyTrapDispenser := class(creative_device): # This is our variable. It is like a counter. # We start with 1 item inside the machine. # var lets us change it later. var items_left : int = 1 # This trigger device detects when a player # walks close enough to the dispenser. # Place a trigger_device in your island and # connect it to this property in UEFN. TriggerDevice : trigger_device = trigger_device{} # OnBegin runs automatically when the island starts. OnBegin() : void = # Subscribe to the trigger so we hear the "doorbell". TriggerDevice.TriggeredEvent.Subscribe(OnPlayerTouch) # This is our recipe. # It takes an agent (which includes players) as an input. GiveItem(Agent : agent) : void = # Try to get a fort_character from the agent so # we can work with the player in the world. if (FortChar := Agent.GetFortCharacter[]): # Check if we have items left. if (set items_left > 0): # Grant the player a Launch Pad consumable. # item_spawner_device is the closest real device # for spawning pickups; direct inventory grants # for trap consumables require an item_granter_device # wired in UEFN — see note below. # note: Verse has no built-in runtime API to grant # a named trap consumable directly. Use an # item_granter_device placed in your island and # wired to this class (see TrapGranter property). TrapGranter.GrantItem(Agent) # Take one away from our counter. set items_left -= 1 # Tell the player "Here you go!" Print("You got a Launch Pad!") else: # No items left. Tell the player. Print("Machine is empty!") # This is the event handler (the doorbell). # It runs when a player touches the trigger device. OnPlayerTouch(Agent : ?agent) : void = # Unwrap the optional agent safely. if (RealAgent := Agent?): # Run our recipe to give the item. GiveItem(RealAgent) # After giving the item, turn off the device. # This makes it stop working for everyone else. TriggerDevice.Disable() # Wire an item_granter_device in UEFN to this property. # Set that device to grant a Launch Pad with quantity 1. # note: item_granter_device is the real Verse API for # granting specific inventory items (including trap # consumables) to a player at runtime. TrapGranter : item_granter_device = item_granter_device{}