Lively NPC's plugin?

What this plugin does is allow you to use a common event as a "movement route" for an NPC. Basically, you can set "landmarks" using regions or defining coordinates as well, and have the NPC able to walk to land marks with path finding. You can also have actions be "interrupted" at certain intervals. For instance, you could have a businessman walk around the city and admire the scenery, then he realizes he's late for work and starts running to a specific building, goes to the door and rushes inside. You could also set actions of what the event should do if the game isn't sure how to get the event to their destination, such as have them attempt to take a different route or immediately start to pace around frantically until the obstruction is cleared. You can also set how many attempts the event will try to get around an obstacle before they get frantic, and you could also set how long they have to be frantic until they give up, in which you could also set what happens when they give up. As well as this, you could also choose if you want the event to "know" the route they need to take via using landmarks and walking to one landmark, then the next, etc. Or, you could have them walk between landmarks randomly, only turning after they passed a certain amount of landmarks or are forced to turn, also being able to choose if they can turn 180 degrees. You can also make it so the events are on a timer, so they have to get to the location in a certain time limit (which can also be randomly generated.), so they have to get to "this" location to do "this" thing in "this" amount of time or else "this" happens. You can also change what they do depending on the amount of time they took to get there, and when the timer stops counting after they start doing their thing. (So, they can get where they need to go and get ready to do their thing, but the timer could hit the threshold and they end up doing something else instead.) You could also set a formula calculation for how the timer increases. A good (but kinda weird, I couldn't think of a different example) example for a use of this plugin would be a goat realizing it's stomach hurts as it strolls around the city, then it suddenly realizes it has to use the bathroom. It then has a certain amount of time to get to a specific location to relieve itself before it ends up having an accident and shamefully walking away all sad. (You can also change the dialogue that happens for the goat depending on how it's feeling.) While the goat is going to the location, if it thinks it's being followed by the player (or another event, which you could also do in the plugin, although you can make exceptions of which events this event interacts with and which events this event can/should ignore.) it will start to sweat and try to get away faster. If it does make it to it's "safe zone", it will look around to make sure nobody's watching, if it thinks it's being watched it will try to hold everything in (until the threshold kicks in and it has an accident.). Also, for an event to think it's being watched, it will try to check if it's in another event's "line of sight" rather then checking if it's on screen. So, if the player stares at the goat, the goat will try to hold everything in, but the second the goat notices the player is not facing towards it, it relieves itself. You can also make the goat's decision on whether it ignores or acknowledges the player dependent on which actor is in the party, what states they may have, and certain in-game variables. (or if the player has the invisible flag turned on.)
I can't really help solve the problem (I don't think there is any plugin that could automatically do this stuff for you), but I'm working on a virtual life game as well and debating whether to move it out of RMMV at this point because so much of the default engine is ending up either ignored or altered.


One of the major obstacles is the RPG Maker limitation of events only being able to exist on one map. The two solutions for that are either having all events on one large map (easiest solution, but can cause performance problems if you have many many virtual lifeforms) or having virtual life objects that can somehow exist outside of the map, which could require some extensive rewriting of the game engine...


With very, very careful sequencing you can use cloned events (there are lots of plugins for that) to make characters appear to move from map to map, but even with fixed schedules where characters do the same thing every day, it's difficult to simulate that (example: Salesman Steve walks out of his house on Map A at 8AM to go to work. It takes him 1 hour to walk to the other side of Map A, navigating through a neighborhood street with A* pathfinding. Player leaves Map B and enters Map A at 8:38 AM. Salesman Steve should be a little over halfway to his destination, but what would his exact coordinates be? It's one thing if it's an empty field, but in a neighborhood map, simply setting his location to the average distance point between his starting and ending coordinates could leave him stuck on a roof). When you add randomized behavior to the equation it becomes a major headache.


The other obstacle is actually having to define all the behaviors of the virtual life itself. You can only give the illusion to the player that NPCs are acting autonomously and making decisions on their own, but really it's a bunch of coded instructions telling them what to do. It's not only difficult but very processing/time-intensive to make NPCs that are smart enough to simply make up rules on their own based on the environment. You can make templates like "human" (basic behaviors could be wakes up and goes to work in the morning, goes home in evening, sleeps at night) or "bird" (hops around randomly, flies away when player approaches it) but even after doing that, all unique behaviors for individual NPCs would still have to be tuned by hand to give some variety.


I recommend reading about finite state machines (simple) and behavior trees (more complex), there are even Javascript libraries to help implement these kinds of AI systems.


http://www.ai-junkie.com/architecture/state_driven/tut_state1.html describes how FSMs work in game AI


http://machina-js.org/ FSM framework for Javascript


http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php explanation of behavior tree concepts in games


http://behavior3js.guineashots.com/ behavior tree library for Javascript
This was one of the hardest things to implement on my farm-life game. I'll eventually make a plugin for that, but probably not until next year.

Original thread: https://forums.rpgmakerweb.com/threads/lively-npcs-plugin.62787/