# We are creating a script that runs when the game starts. # This script will hold our logic. using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Fortnite.com/AI } using { /UnrealEngine.com/Temporary/SpatialMath } using { /Verse.org/Simulation } # This is our main script structure. # Think of it as the "Brain" of our island feature. loot_goblin_behavior := class(creative_device): # Wire these up in the UEFN Details panel by selecting your placed devices. # Drag your NPC device into the first slot, your trigger into the second. @editable Goblin : npc_spawner_device = npc_spawner_device{} @editable Trigger : trigger_device = trigger_device{} # This function runs once when the island loads. OnBegin() : void = # 4. CONNECT THE EVENT # We want this code to run when someone enters the trigger. # TriggeredEvent is the event that fires when a player activates the trigger. Trigger.TriggeredEvent.Subscribe(OnTriggerActivated) # This function is called when the trigger fires. # 'Agent' is the player who walked in. OnTriggerActivated(Agent : agent) : void = # 1. FIND THE NPC # GetAgents asks the spawner for the NPCs it spawned. # We grab the first one if available, so we use an if-block. Agents := Goblin.GetAgents() if (GoblinAgent := Agents[0]): # 2. GET THE NAVIGATABLE INTERFACE # This is the magic line. We ask the goblin for its movement controller. # If the goblin doesn't have navigation, this fails silently inside the if-block. if (GoblinCharacter := GoblinAgent.GetFortCharacter[]): if (GoblinNav := GoblinCharacter.GetNavigatable[]): # 3. GET THE PLAYER'S POSITION # Cast 'Agent' to a fort_character so we can call GetTransform(). if (PlayerCharacter := Agent.GetFortCharacter[]): TargetPosition := PlayerCharacter.GetTransform().Translation # Create a Navigation Target from that position. # A Navigation Target is just a waypoint in the game world. NavTarget := MakeNavigationTarget(TargetPosition) # 5. TELL THE GOBLIN TO MOVE! # NavigateTo is a suspends function, so we spawn a concurrent task for it. # This lets the rest of the island keep running while the goblin walks. spawn{ GoblinNav.NavigateTo(NavTarget) } Print("Goblin has been dispatched!")