Although very basic, it works.
Go to
org.hyperion.rs2.event.impl
And create the class NPCWalkEvent
Code:
package org.hyperion.rs2.event.impl;
import org.hyperion.rs2.event.Event;
import org.hyperion.rs2.model.Location;
import org.hyperion.rs2.model.NPC;
import org.hyperion.rs2.model.World;
public class NPCWalkEvent extends Event {
public NPCWalkEvent(long delay) {
super(delay);
}
@Override
public void execute() {
for (NPC npc : World.getWorld().getNPCs()) {
int radius = npc.getWalkingRadius();
Location spawnLocation = npc.getSpawnLocation();
Location walkTo = Location.create((int) (spawnLocation.getX() + Math.random() * radius),
(int) (spawnLocation.getY() + Math.random() * radius), spawnLocation.getZ());
npc.getWalkingQueue().addStep(walkTo.getX(), walkTo.getY());
}
}
}
Go to the NPC class and add these methods:
Code:
/**
* The maximum walking distance from spawn
*/
private int walkingRadius;
/**
* The NPCs spawning location
*/
private Location spawnLocation;
public int getWalkingRadius() {
return walkingRadius;
}
public void setWalkingRadius(int radius) {
this.walkingRadius = radius;
}
public Location getSpawnLocation() {
return spawnLocation;
}
public void setSpawnLocation(Location spawnLocation) {
this.spawnLocation = spawnLocation;
}
Go to World.java and search for
Code:
private void registerGlobalEvents()
To this method add:
Code:
submit(new NPCWalkEvent(3000));
The 3000 is the delay between the previous and next calculation. If you want the NPC to stand still longer you can increase the delay.
Now to make this work, you will need to go to your NPC spawn loader and set the NPCs spawn location and NPC walking radius. I can show you how I did it, but you most likely handle spawns differently than I do, so this requires a little bit of hacking on your part.
In my NPCLoader class
Code:
int x = Integer.parseInt(locationElement.getAttribute("X"));
int y = Integer.parseInt(locationElement.getAttribute("Y"));
int z = Integer.parseInt(locationElement.getAttribute("Z"));
int radius = Integer.parseInt(walkElement.getAttribute("RADIUS"));
Location spawnLocation = Location.create(x, y, z);
npc.setLocation(spawnLocation);
npc.setWalkingRadius(radius);
I hope you enjoyed this tutorial and now have sexy walking NPCs.
Goodbye