Code: Select all
val locSpawn = Location.create(3225, 3220, 0) //Lumbridge
val locDestination = Location.create(3211, 3386, 0) //Varrock
Code: Select all
NPC.configureMovementPath(location)
2. Copy the
Code: Select all
randomWalkTo()
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?