Sueta

The Wandering NPC

1.8

Citizens2 addon to allow NPC's to randomly wander around with settings.

·Plugin

Vahlokath on the Citizens's IRC channel gave me the idea to create this plugin to extend the wander waypoint provider for citizens. The main issue was that the NPC's when set with the wander waypoint provider, they would just endlessly wander and there are no limits on how far they can go, or climb. You also have no control over the surfaces they can walk on. So this plugin semi addresses that. Keep in mind it's far from realistic on the path finding, and this whole plugin was less than an hours work.

While this project is not abandoned, it is only maintained for bugs, and to keep it working. It will not have new features added to it. For newer features please look at the NPCDestinations plugin.

Features:

  • Define a center point of reference for the NPC and designate a maximum distance they can wander from that.
  • Define the distance to look for the next destination.
    • Crowded areas, smaller can help
  • Define how far up the NPC can go in each destination decision.
    • This can help ensure the NPC does not warp, or climb up the side of buildings, etc.
  • Define the surfaces that the NPC can walk on.
  • Ability to have the NPC pause when players are within a defined radius.
  • Prevent running in circles by enabling pathing history with a configurable amount.
  • NO CONFIG files to edit and changes to each NPC are effective instantly

Usage:
Generate an NPC, and type /waypoint provider wanderingnpc. The plugin will auto assign the trait to the NPC as well as set the center point to the NPC's current location.

You can fine tune the wandering by using the following commands:
/wanderingnpc info

This shows settings on the currently selected NPC for the wanderingnpc trait.

/wanderingnpc setcenter

Sets the centerpoint for the NPC from which it can wander out from.

/wanderingnpc tpcenter

Teleports you to the NPC's center location.

/wanderingnpc maxdistance

Sets the maximum distance from the center the NPC can wander

/wanderingnpc pathdistance

Sets the maximum distance for to look for the next destination

/wanderingnpc climbingdistance

Sets the max height up or down that the NPC can go in a single path finding event. This is not total from the center, but per attempt to move somewhere.

/wanderingnpc pathhistory {#}

Enable or Disable the path history. Helps prevent backtracking. You can also define the # of locations to tract by adding a number to this command.

/wanderingnpc pauseplayer {#}

Tell the NPC to pause when a player is # blocks away. 0 or blank disables this function. This is good if your NPC is a quest giver.

/wanderingnpc addblock

Adds the blocktype selected in your hand to the allowed surfaces that the NPC can choose as a destination

/wanderingnpc removeblock

Removes the blocktype selected in your hand from the allowed surfaces that the NPC can choose as a destination

Permissions:

wanderingnpc.settings
This gives a user the ability to change the NPC's wander settings
wanderingnpc.tpcenter

Ability to teleport to the NPC's center /wanderingnpc tpcenter

wanderingnpc.info

Permission to see the settings /wanderingnpc info

Notes:
The path finding is random and uses the same idea that was in citizens to begin with, I just expanded on that and made a trait around it for configuration. While this could be done without adding commands or a trait, I wanted the ability to change the NPC's settings live and without editing the saves.yml file.

*
If you want to use the /npc path command after setting an NPC to use this. You will have to reset the waypoint provider back to the linear waypoint. Use /waypoint provider linear to reset it. You will also have to set the waypoints again.

Note from Azfaloth regarding soul sand:

Another piece of info you should add in the description is that the npc jump height is very important for some blocks. NPCs will get stuck on things like the edges of soul sand unless the jump height is at least 2. Because soul sand is slightly smaller than normal blocks. This may lead to players reporting bugs for improper movement.

* This plugin uses the plugin Metrics system. If you want to disable it, open /PluginMetrics/Config.yml and set opt-out to true. Mostly for my curiosity :)

Let me know if this is handy for anyone, if enough people chime in, I will work on a better path finding system.

Source:
My GitHub

Similar projects

Plugin →