# This is the main script for our jetpack challenge. # It runs when the island starts. using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Fortnite.com/FortPlayerUtilities } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # This is our "Brain" object. # It holds all our logic. jetpack_zone_manager := class(creative_device): # This is a reference to the Trigger Device placed on the island. # Drag a Trigger device onto this property in the UEFN editor. @editable ZoneTrigger : trigger_device = trigger_device{} # This variable tracks the timer. # It counts down from 5 seconds. Timer : float = 5.0 # This is the "Start" function. # It runs when the game begins. OnBegin() : void = # We wait for the zone trigger to activate. # When a player enters, 'OnPlayerEnter' runs. # We link that event here. ZoneTrigger.TriggeredEvent.Subscribe(OnPlayerEnter) # This function runs when a player enters the zone. # note: trigger_device sends an ?agent; we unwrap it with 'if' before use. OnPlayerEnter(TriggeringAgent : ?agent) : void = if (Agent := TriggeringAgent?): # Run the timed jetpack logic on its own fiber so it can suspend. spawn { RunJetpackSequence(Agent) } # This function handles giving and removing the jetpack. RunJetpackSequence(Agent : agent) : void = # Give the player a Jetpack. # item_spawner_device is the standard way to grant a specific item. # note: Grant() on fort_item_grant_device is the real API for granting # a named item to an agent. Wire a Jetpack Item Spawner in the editor # and call its Grant method, or use the item_granter_device below. if (Player := player[Agent]): # Print a message to the chat. # This helps us know it worked. Print("You got a jetpack! Fly fast!") # Grant the jetpack through an item_granter_device wired in editor. # note: item_granter_device.GrantItem(agent) is the real Verse API # for giving a pre-configured item to a player at runtime. JetpackGranter.GrantItem(Player) # Start the countdown. # We use 'Sleep' to wait. # It waits for 5 seconds. # Then it calls the removal step. Sleep(Timer) # 'RevokeItem' takes the item away via the same granter device. # note: item_granter_device does not expose a revoke method; # we use a second item_granter_device configured to grant nothing # combined with RemoveAllItems() on the fort character instead. if (FortCharacter := Agent.GetFortCharacter[]): FortCharacter.ClearInventory() # Tell the player it is gone. Print("Time's up! No more jetpack.") # Drag an Item Granter device (set to Jetpack) onto this in the editor. @editable JetpackGranter : item_granter_device = item_granter_device{}