# This is our main script file. # It lives on a device in your island. using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # We create a new type for our Treasure Device. # This is like a blueprint for our special chest. treasure_hunter := class(creative_device): # This is a trigger_device. It is like a radio button. # When the player walks into it, this device fires its event. # Place a trigger_device on your island and connect it here. @editable TriggerDevice : trigger_device = trigger_device{} # This is our main function. It runs when the game starts. OnBegin() : void = # We subscribe to the trigger's activated event. # The game calls our handler whenever a player activates the trigger. TriggerDevice.TriggeredEvent.Subscribe(OnTriggered) # This function runs each time the trigger fires. # Agent is the player (or object) that activated the trigger. OnTriggered(Agent : ?agent) : void = # Here is the magic check! # We try to cast Agent to a fort_character to confirm a real player triggered it. # note: Verse does not expose a bare IsAlive(); instead we check the cast succeeds. if (ActualAgent := Agent?, Character := ActualAgent.GetFortCharacter[]): # If yes, we are safe to do stuff. Print("You found the treasure! 🎉") # note: No generic GiveItem API exists in public Verse; we print a # reward message as a stand-in for wiring an item-granter device. Print("A coin has been added to your inventory!") else: # If we could not confirm a live character, we say so. Print("The treasure is gone! 💨")