Restricting NPC Random Movement

There are a few NPCs I want to have a random movement pattern, but I also want to restrict them so that they only move in a designated area of the map and don't step out of it. I know the key involves using Region ID stuff, detecting the event's location and just simply having them step back if the hit a region square, or somehow only keeping them on certain region squares. But that's all I really got, I don't know how to do this and I've spent the past hour and a half trying to find a tutorial to explain how to restrict movements to region id in a way I can understand, step by step, but I'm just not finding anything. Any help here would be extremely appreciated, thank you.
I don't know if this trick works quite the same in MZ--but in XP, events can't cross other events by default. If I want an NPC to stay in their little box--for example, have someone move randomly behind a bar counter--I just make a little fence out of empty events to keep them from straying! You can minimize the number of events necessary for this by mapping with it in mind. Create a little bottleneck with relevant set pieces, and you should only need a couple of events to form your wall.

Again, I know that the event settings are different in later engines (above/below/equal to player and all that) but it might be worth a try!
If you're using Visustella's events and movement core you can paint the map with a region and in the event's note tag, add the restriction like this:

1734841267969.png
I don't know if this trick works quite the same in MZ--but in XP, events can't cross other events by default. If I want an NPC to stay in their little box--for example, have someone move randomly behind a bar counter--I just make a little fence out of empty events to keep them from straying! You can minimize the number of events necessary for this by mapping with it in mind. Create a little bottleneck with relevant set pieces, and you should only need a couple of events to form your wall.

Again, I know that the event settings are different in later engines (above/below/equal to player and all that) but it might be worth a try!
I'm not sure, wouldn't that also restrict the player's movement? I think it'd only restrict the NPC is the events were equal to player (those are the only unpassable ones).
If you're using Visustella's events and movement core you can paint the map with a region and in the event's note tag, add the restriction like this:

View attachment 326547
I'm not using any plug ins for this game yet. My plan is to only get an add on if/when needed since I don't really know much about add ons yet.
I'm not sure, wouldn't that also restrict the player's movement?
How? The player can walk on top of an empty event that has priority above or below player without issue.

I think it'd only restrict the NPC is the events were equal to player
No, that's not what you were told.
How? The player can walk on top of an empty event that has priority above or below player without issue.
But NPCs can't pass over events no matter the priority?
No, that's not what you were told.
I wasn't told anything?

I don't know if this trick works quite the same in MZ--but in XP, events can't cross other events by default. If I want an NPC to stay in their little box--for example, have someone move randomly behind a bar counter--I just make a little fence out of empty events to keep them from straying! You can minimize the number of events necessary for this by mapping with it in mind. Create a little bottleneck with relevant set pieces, and you should only need a couple of events to form your wall.

Again, I know that the event settings are different in later engines (above/below/equal to player and all that) but it might be worth a try!
Tried it, it works ~ thank you very much!
I wasn't told anything?
events can't cross other events by default. If I want an NPC to stay in their little box--for example, have someone move randomly behind a bar counter--I just make a little fence out of empty events
Ah, I got confused the way you said it point blank like that @ATT_Turan - because
they said they didn't know for MZ and there's above/same/below (can't assume an event like an NPC can't cross another event if they're not the same priority). No one told me that it doesn't matter if the NPC is same as player while others are below/above.
There are a few ways to do it.

1) Plugins like Visustella events and movement is a good example
If you're using Visustella's events and movement core you can paint the map with a region and in the event's note tag, add the restriction like this:

View attachment 326547
2) Run a parallel event:
get the x and y coordinates of the event
if x and y is within a box, events move random
if x = > a certain number, move left
if x = < a certain number, move right....etc

*note if you have more than 1 events in the box, you might want to script a collision script if there is a chance the 2 events might collide into each other

I tested RPG Maker MZ, events and players will not collide if the event is above / below / does not exist yet. That applies to other events as well.
My point was merely that it would've taken you about 30 seconds to test what @TeiRaven said, rather than posting that you didn't think it would work and asking whether it actually does 😉

I see that you did, in fact, try it and see that it works, so you're all set - it just wasn't really a necessary detour. (or, of course, there's looking it up - there have been a good number of threads discussing it)

Good luck with your project!

2) Run a parallel event:
...
if you have more than 1 events in the box, you might want to script a collision script...
That seems like...an extreme solution? 🤣

Given the simplicity of dropping some empty events or of using existing plugins to use region IDs, I can't imagine why anyone would want to outsource random movement and collision checking into a parallel event. It's technically a way to do it, but not one I think anyone ever should 😛
My point was merely that it would've taken you about 30 seconds to test what @TeiRaven said, rather than posting that you didn't think it would work and asking whether it actually does 😉

I see that you did, in fact, try it and see that it works, so you're all set - it just wasn't really a necessary detour. (or, of course, there's looking it up - there have been a good number of threads discussing it)

Good luck with your project!


That seems like...an extreme solution? 🤣

Given the simplicity of dropping some empty events or of using existing plugins to use region IDs, I can't imagine why anyone would want to outsource random movement and collision checking into a parallel event. It's technically a way to do it, but not one I think anyone ever should 😛
well i try not to use too much plugin, once i used plugins to solve all my problems, but ended up the plugins crash into each other, especially common one like Visustella, Elibook, CGMZ, Galv.....these people made the best plugins and makes the project very interesting, however due to the complicity of the plugins, more than once, these plugins tend to clash on each other.
VisuStella has some unsolvable compatibility problems since they hide their code but any compatibility issues from the other ones should be fixable.

Also Galv Move Route Extras has a move random on region function

Original thread: https://forums.rpgmakerweb.com/threads/restricting-npc-random-movement.174085/