# QuestTutorial.verse using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # 2. THE QUEST GIVER DEVICE: This is the brain quest_giver_device := class(creative_device): # --- VARIABLES (The "Boxes") --- # HasPlayerCompleted: Remembers if the player did the task. # Default is false (they haven't done it yet). # var makes it mutable so we can change it at runtime. var HasPlayerCompleted : logic = false # Reference to the trigger_device that wraps the Crystal Prop # in the Scene Graph. Wire this up in the UEFN Details panel. @editable CrystalTrigger : trigger_device = trigger_device{} # Reference to the HUD message device to show messages. # Wire this up in the UEFN Details panel. @editable QuestHUD : hud_message_device = hud_message_device{} # OnBegin runs once when the match starts. # We subscribe to device events here. OnBegin() : void = # Listen for a player entering the crystal trigger zone. CrystalTrigger.TriggeredEvent.Subscribe(OnPlayerEnterTrigger) # --- EVENT: When a player enters the trigger zone --- # This runs automatically when a player walks near the crystal. OnPlayerEnterTrigger(TriggeringAgent : ?agent) : void = if (Agent := TriggeringAgent?): if (FortChar := Agent.GetFortCharacter[]): # Check if the player hasn't already done the quest. if (HasPlayerCompleted = false): # Flip the variable to true. set HasPlayerCompleted = true # Update the HUD to say "Quest Complete!" # ShowMessage takes a player, so we cast agent -> player. # note: hud_message_device.Show() displays the device's # pre-configured message to one player. if (Player := player[Agent]): QuestHUD.Show(Player) # Give the player XP (Reward!) # note: fort_character.GiveXP is the real API for # granting experience to a character in UEFN. FortChar.GiveXP(100) Print("Player got the crystal! +100 XP") # --- FUNCTION: When the player talks to the NPC --- # Hook this up to an npc_interactable_device's InteractedWithEvent # in the UEFN Details panel, or call it from another device. # note: Wire an npc_interactable_device's InteractedWithEvent to a # trigger_device and subscribe here the same way as CrystalTrigger. OnInteract(TriggeringAgent : ?agent) : void = if (Agent := TriggeringAgent?): if (Player := player[Agent]): if (HasPlayerCompleted = true): QuestHUD.Show(Player) else: # If they talk to the NPC *before* getting the crystal, # show them the pre-configured "find the crystal" message. # note: Configure the device's message text in the # UEFN Details panel for each state, or use a second # hud_message_device for the "not yet complete" prompt. QuestHUD.Show(Player)