Making an NPC walk from Lumbridge to Varrock?

Various development-related discussions
Post Reply
User avatar
FiftyTifty
Noob
Posts: 9
Joined: Mon Mar 06, 2023 6:53 pm
Been thanked: 1 time

Making an NPC walk from Lumbridge to Varrock?

Post by FiftyTifty »

Now that I have a basic script going that spawns a few NPC instances, I'd like to make them move about. I've made two attempts, with their own problems.

Code: Select all

val locSpawn = Location.create(3225, 3220, 0) //Lumbridge
val locDestination = Location.create(3211, 3386, 0) //Varrock
1. Use

Code: Select all

NPC.configureMovementPath(location)
- The NPC doesn't path beyond the first region (tile? area?) that they're currently in. Using locDestination, which should take them to Varrock, has the NPCs walk around Lumbridge castle and stand facing the castle wall on the exact same tile.

2. Copy the

Code: Select all

randomWalkTo()
functions from the Adventurer bot - Nothing happens when I added this. No errors, the NPCs just path about their spawn point as they would without being made to pathfind to a given location.

For the second method, here's the code (redid the function names, and changed the entity type to NPC):

Code: Select all

/**
 * @param loc the location to walk to.
 * @param radius tiles around the location the bot could walk to.
 * @author Kermit
 */
fun npcWalkToWithinRadius(npc: NPC, loc: Location, radius: Int) {
    if(!npc.walkingQueue.isMoving) {
        GlobalScope.launch {
            val newLoc = loc.transform(
                RandomFunction.random(radius,-radius),
                RandomFunction.random(radius,-radius), 0)
            npcWalkToIterator(npc, newLoc)
        }
    }
}


/**
 * The iterator for long-distance walking. Limited by doors and large obstacles like mountains.
 * @param loc the location to find a path to.
 * @author Ceikry
 */
private fun npcWalkToIterator(npc: NPC, loc: Location){
    var diffX = loc.x - npc.location.x
    var diffY = loc.y - npc.location.y
    while(!npc.location.transform(diffX, diffY, 0).withinDistance(npc.location)) {
        diffX /= 2
        diffY /= 2
    }
    GameWorld.Pulser.submit(object : MovementPulse(npc, npc.location.transform(diffX, diffY, 0), Pathfinder.SMART) {
        override fun pulse(): Boolean {
            return true
        }
    })
}

fun FyTySpawnNPC()
{
    for (iCounter in 0..2)
    {
        listNPCs.add(spawnNPC(1, locSpawn, Direction.NORTH, false, true, false))
        listTickCounters.add(RandomFunction.random(1, 10))
        npcWalkToWithinRadius(listNPCs[iCounter], locDestination, 5)
    }

}
/code]

My guess is that the code for making bots pathfind doesn't apply to NPC entities. So, what's the approach here?
User avatar
Ceikry
Site Admin
Posts: 585
Joined: Wed Aug 10, 2022 11:48 pm
Location: Draynor Village
Has thanked: 82 times
Been thanked: 103 times

Re: Making an NPC walk from Lumbridge to Varrock?

Post by Ceikry »

You are attempting to do something the NPC system is fundamentally incapable of, because NPCs are not designed to go that far. In fact, there's mechanics in place that *stop* NPCs from moving that far.

Also, even if NPCs didn't have their own movement mechanics, you physically can't pathfind from lumbridge to varrock in one go, that's just fundamentally not how movement works in runescape.
Nerds
User avatar
FiftyTifty
Noob
Posts: 9
Joined: Mon Mar 06, 2023 6:53 pm
Been thanked: 1 time

Re: Making an NPC walk from Lumbridge to Varrock?

Post by FiftyTifty »

Ceikry wrote: Wed Mar 08, 2023 3:02 pm You are attempting to do something the NPC system is fundamentally incapable of, because NPCs are not designed to go that far. In fact, there's mechanics in place that *stop* NPCs from moving that far.

Also, even if NPCs didn't have their own movement mechanics, you physically can't pathfind from lumbridge to varrock in one go, that's just fundamentally not how movement works in runescape.
Huh, so there's actual code to keep NPCs close to their spawns.

Right, so long distance movement needs to be broken up into smaller movement parts. Makes sense. Is it possible to make NPCs move to another region (or whatever the terminology is for a group of 63x63 tiles)? Or is that not doable either, and they are constrained to the region they spawn in?
Post Reply