# This is our Campfire Controller. # Think of this as the "Brain" of the campfire. # It lives inside the Campfire device in the World. # Import the necessary tools from Fortnite's toolkit. # Think of these as the "tools in your toolbox." using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Fortnite.com/FortPlayerUtilities } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # This is the main class for our Campfire. # creative_device is the real base class for UEFN island devices. # We reference a trigger_device to detect players entering the zone, # since campfire_device does not expose a direct Verse API for zone entry. campfire_controller := class(creative_device): # Wire this to a Trigger device placed at the campfire's location # in the UEFN editor (set its radius to match HealingRadius). @editable CampfireTrigger : trigger_device = trigger_device{} # Wire this to a Healing Cactus device configured to grant 50 HP. # Set "Grant Amount" to 50 and "Grant Type" to Health in its properties. @editable HealthGranter : healing_cactus_device = healing_cactus_device{} # This is a "Variable." # A variable is a container that can change. # Here, it stores the size of the healing zone in meters. # We set it to 5.0 meters, which is a cozy healing radius. # Match this value to the Trigger device's radius in the editor. var HealingRadius : float = 5.0 # This is a "Constant." # A constant is a value that NEVER changes. # We want the wood cost to be exactly 10 resource units. # If we tried to change it later, the compiler would yell at us. WoodCost : int = 10 # OnBegin runs automatically when the island starts. # We use it to hook up our event listener to the trigger. OnBegin() : void = # Subscribe to the trigger's agent-entered event. # Every time a player walks into the trigger zone, # OnPlayerEntered is called with that player's agent. CampfireTrigger.TriggeredEvent.Subscribe(OnPlayerEntered) # This is a "Function." # A function is a block of code that does a specific job. # Think of it like a "Trigger" in UEFN, but more powerful. # This function runs when the campfire is activated. OnActivate(Agent : agent) : void = # Cast the agent to a fort_character so we can read their stats. # note: Verse does not expose a wood-inventory API directly; # we use an item_count_device wired in the editor to track wood, # but here we demonstrate the healing path with a real HP check. if (Character := Agent.GetFortCharacter[]): # Check whether the player is below full health before healing. # This mirrors the "do they need the fire?" design intent. # note: There is no GetInventoryCount("Wood") API in Verse; # to gate on wood count, wire an item_count_device that tracks # your wood item and read its GetCount() result instead. CurrentHealth := Character.GetHealth() MaxHealth := Character.GetMaxHealth() if (CurrentHealth < MaxHealth): # Activate the Healing Cactus device, which adds HP # to the player as configured in the editor. HealthGranter.Burst(Agent) Print("Campfire lit! You feel warmer.") else: Print("You are already at full health!") # This is the "Event Handler." # An event is something that happens in the game (like a player entering a zone). # This function connects the trigger event to our OnActivate function. OnPlayerEntered(Agent : ?agent) : void = # The trigger_device already enforces the radius set in the editor, # so any agent delivered here is inside the healing zone. # We unwrap the optional agent and call OnActivate to run the healing logic. if (ActualAgent := Agent?): OnActivate(ActualAgent)