NPCs can walk around the virtual world as the players. The movement is controlled in server-side extension.
Some NPCs' movement is fixed to a predefined path. For these NPCs, we can dispatch the path directly without path finding algorithm. In the following example, we will repeatedly control the NPC to walk between two points.
As we treat the NPC as a normal player in the logic, we will use the same walking mechanism from the player. The NPC will dispatch a public message with specific walking path to other players in the same room. Every client will then move the NPC according to the path. We have an npcLoop
function in server-side extension. We will put the NPC movement logic there.
function npcLoop(){
if (theNpcUser != null) {
theNpcUser.updateMessageTime();
var rooms = theNpcUser.getRoomsConnected();
if (theNpcUser.getVariable("isoPosX").getValue() == 8){
_server.dispatchPublicMessage("|path|4,16;", _server. getCurrentZone...