using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /UnrealEngine.com/Temporary/Diagnostics } using { /UnrealEngine.com/Temporary/SpatialMath } using { /Verse.org/Simulation } # We are defining a new type of object called a Gadget. # This is like creating a new blueprint for a device. bouncer_gadget := class(creative_device): # This is our VARIABLE. Think of it as your "Ammo Counter." # It starts at 3, meaning you get 3 free bouncers. # 'var' makes it mutable so we can subtract from it later. var TrapsRemaining : int = 3 # A reference to a prop_spawner_device placed on the island in UEFN. # We use a prop_spawner_device to handle the actual spawning, # because Verse cannot call SpawnActor for arbitrary game props directly. # Wire this device to a Bouncer Pad prop in the UEFN editor. # note: Verse has no free SpawnActor for arbitrary props; prop_spawner_device # is the supported way to spawn props at runtime in UEFN. @editable BouncerSpawner : prop_spawner_device = prop_spawner_device{} # A reference to the button_device (or player_reference_device) that # tells us which player triggered the gadget. # Wire a trigger_device or item_granter_device's AgentActivates event # to call DeployBouncer in your island setup. @editable GadgetTrigger : trigger_device = trigger_device{} # This runs automatically when the island starts. OnBegin() : void = # Subscribe to the trigger so pressing it calls DeployBouncer. GadgetTrigger.TriggeredEvent.Subscribe(OnUse) # This event runs when the trigger fires (the player "presses" the gadget). # It's like the trigger pull. OnUse(Agent : agent) : void = DeployBouncer(Agent) # This is our FUNCTION. Think of it as the "Deploy" button logic. # It receives the agent (player) who activated the gadget. DeployBouncer(Agent : agent) : void = # First, we check if we have any traps left. # This is like checking your magazine before shooting. if (TrapsRemaining > 0): # Cast the agent to a fort_character so we can read their position. if (Character := Agent.GetFortCharacter[]): # Calculate where to spawn the trap. # We take the player's current position and move it forward # 200 units (≈ 2 metres). This uses Scene Graph coordinates. PlayerTransform := Character.GetTransform() PlayerLocation := PlayerTransform.Translation ForwardVector := PlayerTransform.Rotation.GetLocalForward() SpawnLocation := PlayerLocation + ForwardVector * 200.0 # Teleport the prop_spawner_device to the desired location # then fire it — this is how UEFN positions spawned props. # note: prop_spawner_device does not expose SetActorLocation in # public API; reposition by moving the device in-editor or # use a creative_prop reference for runtime placement. BouncerSpawner.Spawn() # Finally, subtract 1 from our ammo counter. # The variable updates! set TrapsRemaining -= 1 # Print a message to the output log for feedback. Print("Bouncer Deployed! Charges left: {TrapsRemaining}") else: Print("No character body found — cannot deploy bouncer.") else: # The magazine is empty! Print("Out of Bouncers! Reload needed.")