Author Sticky: Post Working Scripts Here
Splat Posted: Thursday, 04 July 04:02AM
Name: Generic NPC pathfinding
Use: Allows you to place waypoint "guide"s to force NPCs to walk in the damn streets, or wherever you want.

Notes: Place waypoints, all with the tag "guide", in your area whereever you want the NPCs to walk along. Then, use ActionMoveToObjectWithGuides() below as opposed to the normal ActionMoveToObject().

Script:
NWScript:
void ActionMoveToObjectWithGuides(object dest, int run=FALSE, float range=1.0f) {

    object curr = OBJECT_SELF;

    while (curr != dest) {

        float dist = GetDistanceBetween(curr, dest);

        int index = 1;

        int searching = 1;

        object guide = GetNearestObjectByTag("guide", curr, index);

        while (GetIsObjectValid(guide) && searching) {

            float dist2 = GetDistanceBetween(dest, guide);

            float dist3 = GetDistanceBetween(guide, curr);

            if (dist2 < dist && dist2 > 2.0f && dist3 > 2.0f) {

                ActionMoveToObject(guide, run, range);

                curr = guide;

                searching = 0;

            }

            index = index + 1;

            guide = GetNearestObjectByTag("guide", curr, index);

        }

        if (searching) {

            guide = dest;

            ActionMoveToObject(guide, run, range);

            curr = guide;

        }

    }

}