# This is the main script for our NPC's brain. # It inherits from NPCBehavior, which means it has basic NPC powers. struct SoldierBehavior : NPCBehavior { # VARIABLES: These are our "inventory slots." # TargetPosition is a Vector (X, Y, Z coordinates). # We start with it set to (0,0,0) until we give it an order. TargetPosition : vector = <0,0,0> # IsMoving is a boolean (True/False). # Like a light switch: on or off. IsMoving : bool = false # FUNCTION: This is our custom command. # When we call this, the NPC will start walking. MoveToTarget := func() { # Check if we are already moving. # If yes, do nothing (don't double up on orders). if (IsMoving) { return } # Set the flag to true. The NPC is now "busy." IsMoving = true # Tell the NPC to move to the stored TargetPosition. # This uses a built-in NPC function called 'Move'. Move(TargetPosition) # We'll add logic to stop later, but for now, it just walks! } # EVENT: This runs every frame (like checking your health constantly). OnUpdate := func() { # If we aren't moving, stop checking. Save battery! if (!IsMoving) { return } # Get where the NPC is RIGHT NOW. CurrentPos := GetLocation() # Check distance to target. # If we are close enough (within 50 units), stop. if (Distance(CurrentPos, TargetPosition) < 50.0) { IsMoving = false Stop() # Stop the movement animation } } }