Paste #103068: NPC Pathfinding Bug Script

Date: 2022/11/08 11:37:21 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


show_npc_pathfinding_bug:
    type: task
    debug: true
    script:
        # Define start/end locations
        - define origin <location[npc_start_pos]>
        - define destination <location[npc_end_pos]>
        # Define sub-points to break up pathfinding
        - define distance_between_waypoints 15
        - define waypoints <[origin].points_between[<[destination]>].distance[<[distance_between_waypoints]>]>
        # Ensure all chunks along the way are loaded
        - foreach <[waypoints]> as:waypoint:
            - if !<[waypoint].chunk.is_loaded>:
                - chunkload <[waypoint].chunk> duration:10m
            - narrate <[waypoint].chunk.is_loaded>
        # Create the npc
        - create parrot bird_1 <[origin]> save:bird
        - define bird <entry[bird].created_npc>
        # Send it on its way
        - foreach <[waypoints]> as:waypoint:
            - ~walk <[bird]> <[waypoint]> auto_range lookat:<[waypoint]>

        - narrate "Done - Bird reached destination."