Overworld Encounters

So I have an idea for how to do this but it seems pretty over-engineered so I'd like some ideas

Instead of regular random encounters, I'd like to have overworld encounters, ie there are sprites of enemies hanging around and when they touch you it initiates a battle. Here is what I hope to achieve.

1. Different enemies have different behaviors. Some don't even care if you're there and go about their business. Others start to run away when you get too close, and others move towards you when you get too close. Some will only be able to move quickly for a few tiles, where as others can move many squares, either towards or away from you.

2. When you "touch" an enemy sprite, the battle initiates. Touching means either the enemy or you attempt to move in to the tile as the other. A collision.

3. Enemies stay gone after you defeat them, until the map is revisited. So if there are 10 enemy sprites on a map, you could theoretically defeat all 10, but if you leave the map and come back, they also come back.

4. The type of enemy that spawns is semi random. Say there are 5 enemies on a map, each of those 5 could be either a mosquito enemy, a bat enemy, or a lizard enemy. So, theoretically, all 5 could be mosquitos. It just randomly checks when you enter the map what they'll be. This could be done pretty easily with a random variable. The locations of the enemies should also be random. Anywhere on the map, except on places that normally wouldn't be walkable for instance.




Does this sound doable without a plujgin? My idea is to basically have a set area where an enemy "patrols", and if you step on a specific tile near it, that tile would have an event that causes the enemy to move closer to you, but like I said earlier it seems a bit overengineered, and I figure there is probably a much better way to do it.
You don't need to use plugins to do this, this can be accomplished with a bit of work with eventing.

My game uses world encounters rather than random encounters.
I'll attach some pictures, but allow me to explain how this works:
You'll need to create a parallel event on your map (this will be your monster - I'll shorten this to mob)
In your parallel event, you need it to check 2 things: the mobs current location and the players current location.
This is necessary for 2 functions:
Region ID, and to detect collision.

MobEvent1.PNG


You will need to set up regions, otherwise your mobs "wander" AI will set them off in any which direction. I suppose it's not entirely necessary, but if you have a very large map, a mob you spawn close to your town could wind up at the beach 2 continents over, so it's better to restrict it to a specified region.
Additionally, you can control how the mob behaves depending on 2 factors:
Mobs behavior when the player is NOT inside the region.
Mobs behavior when the player is inside the region.

The most obvious way to use these 2 factors is:
When the player is not inside the region, the mob moves randomly.
When the player is inside the region, the mob pursues the player.
But you could really change these to however you want it's behavior to go.
You can create a third behavior (but I don't recommend this) by adding what the mob should do when it is outside of it's region. However, this can result in some weird behavior if you don't account for it. So, I recommend using a plugin like YEP region restrictions to prevent the mob leaving their designated region. (In my previous game, I didn't want to use plugins, so I created a "return home" behavior where if the mob left it's region, it would switch into a mode that would seek it's location - but I was also too dumb to make this work effectively and would often just result in bricking the mobs AI - in my current game, everything has been simplified by using region restrictions.)

MobEvent2.PNG


Finally, you need to assign two conditionals: If Player X is equal to MobX and if Player Y is equal to MobY.
If both are equal, you can create collision behavior. More than likely you will want it to do a "Battle process", but you can get whacky with it if you want.

Using a separate event, you can then specify where and how mobs spawn, but that's an entirely different can of worms that - since I only use this function in small part in my game (as in, I just use "Set Event Location" to move some mobs depending on some variables) it might be better if someone else helps you with point 4
(I imagine creating a series of pre-fab mobs, setting a variable to roll a random number, and using that number to set 1 of the pre-fab mob's location would help do that.)
(Alternatively, set up multiple event pages on your mob and tick the "variable" box. Roll a random variable, and depending on what number is rolled will control which mob event page is active.)
Thanks a ton for sharing this with me! I'm, getting started on this as soon as steam finishes updating

EDIT: So one minor problem, the balloon event keeps triggering (I do like the balloon) over and over. How would I make it only trigger once and then have the movement towards player keep going until the player leaves that region?
If my post isn't clear or you have other questions, let me know :LZScheeze:
Sorry, I edited my comment before I saw your response. Can you check out the edit I added?

EDIT: So one minor problem, the balloon event keeps triggering (I do like the balloon) over and over. How would I make it only trigger once and then have the movement towards player keep going until the player leaves that region?

In addition to that, when I copy your event, the battle isn't starting. I'm guessing that's because your event requires both the event and player have identical coords, but through isn't on and nowhere in your event do you have it set to turn on...so I'm guessing that needs to be added?

In addition to that as well, when you flee, it seems you just teleport the enemy far away. Is there a way to just have the enemy one tile away, and to also have a balloon hovering above it during the wait time?
the balloon event keeps triggering
That's because it's a parallel event. The event will repeatedly run the instructions until it's either told to stop or it reaches a new conditional state. So basically it's running the "pursue player" loop, which means every time it starts this loop, it will play the balloon again...and again....and again...
You will need to work with this limitation, or find an alternative solution to it. In my case, I just worked with it and created my own balloon icon that is static (meaning, it's the same animation frame repeated for all 8 balloon icon frames)
Desktop 2022.07.29 - 09.57.38.04.gif


but through isn't on
Look at the event priority :LZSwink:
Ah I see!!!!

Okay, one last thing...For some reason, my enemy is moving in a very jerky way. How can I get it to be smooth like yours?

I made the balloon thing work by doing this

When the event triggers (ie when the player is in the region), the game checks if the "balloon toggle" switch is off. If it's off, it shows the baloon, and then turns ON the toggle. If it's off, it doesn't show the balloon and moves on to the rest of the event. Then, at the bottom part of the event where you made the enemy move randomly, it also turns off the toggle, so essentially if you aren't in the region, it changes it to show the balloon, but when you are in the region, it only shows it once.

Also...since the enemies have below player priority, couldn't I make arbitrary "ghost" events that are set to below player to keep the enemies in their own regions? The player could walk right on top of them but the enemy couldn't pass them?
For some reason, my enemy is moving in a very jerky way
I'm not clear on what you mean. It may be because the movement frequency is too low. In the "set movement route" option, change the frequency of the mob.

to keep the enemies in their own regions?
Maybe, but that seems like a lot of work.
Try using Yanfly's Region Restrictions to set up a collision box around the enemy's region to prevent them leaving. It's a free plugin, and it has tons of uses outside of just this use case that you can explore later.
rr.PNG


(Ignore the 5 enemy events, that's just a really inefficient method I used to create level scaling enemies)
Even when the frequency is set to 5 (which shouldn't matter, because we change the freq in the event, right?), the enemy takes a step, stops, and then takes another step.

Here's the event
1659058508066.png

However, even with this, very jerky. My guess is it's because the set movement route is set to wait, so it keeps changing the speed and freq over and over and that takes a frame or two?
:LZSlol:
Oh I see now.
The difference is that my mob is moving in a straight line, and your mob has to move diagonally. Since RPG Maker uses a grid for movement, and only processes cardinal directions, the enemy has to take this route to reach you:
right -> up -> right -> up -> right -> etc
If you want it to move in a more consistent straight line, you'd need a plugin that allows for 8 direction movement, but this means you'll need to add diagonal facing sprites for enemies and players.
Ah I see. Well I'll toy with it a little more and see if I can get it up to my liking.
So no matter what I do, the enemies still only move one square at a time regardless of the frequency and stop every square and don't move fluidly (even in a straight line). Any ideas?

In addition to that, I set up an autorun first page that randomizes a variable in to 1-4, and then depending on the result a different type of enemy (with a different type of behavior) appears based on the event page (example, 1 is slime 2 is rat, and the event pages are just set to that variable is greater than the number, etc), and while the behavior of the enemy and the graphic are correct, when the actual battle happens, it always picks the battle processing from the first page. Any ideas?
1659661744734.png

1659661768392.png

1659661786532.png

My guess is it has something to do with how parallel events work?
Peva, I have a lesson about Events on my game-tutorial project (from signature). I teach everything you need to know about configuring them. You can play it direct on your browser.

You basically can configure the frequency and speed to achieve different effects. The only way to properly learn it is through trial and error. 😉
Right, but even with the freq set to the maximum, the enemy still studders. My guess is that the conditional events that happen (making sure the player is in the same zone as the enemy) cause it to stop because the game is checking again, and that processing time slows down the event. Setting it to move manually isn't a problem. Is that just unavoidable with this type of event?
the enemies still only move one square at a time regardless of the frequency and stop every square and don't move fluidly
Run a play test of your game. While the game is running press f2. An FPS counter should pop up in your top left corner. While the FPS counter is active, play around the game a little bit and watch it. Can you report a ball-park average number? And also, did you ever see it drop severely (more than 15%) for a brief moment. If so, when did that happen?

My guess is it has something to do with how parallel events work?
No, I don't believe so. Technically speaking, none of the other event pages are even a "thing" (as far as the game is concerned, they don't exist) unless the requirements are met that set them as active.
Check your database, did you assign the correct fight?
Yes, I did assign the correct troops, but it still always triggers the one set to the first fight.

FPS is steady 60 the entire time, drops to 59 while I'm moving but not while the enemy is. While the enemy is moving, the framerate is steady. Is there anything off in the screenshots I showed you?

Reason I'm concerned about the parallel events processing is because the requirement for page 1 is "Is the variable greater than 1?" and no "Is the variable exactly 1". Well, 3 is greater than 1 so the parallel is still running.

Edit: Well I thought I fixed it by doing this...
1659664059335.png

But even when the variable returned at 4, the enemy graphic was correct but it still put me in the battle with the enemy specified if the variable was 1...

Edit 2: Okay guess I was wrong, it worked on a subsequent text. I has "if escape" set to erase the event, but for some reason, after running away it triggers another battle, the troop from page 2. So weird!

Edit 3: Okay so it seems to only pull the correct troop half the time and pulls the first one the other half. And, after winning the battle or escaping, it always triggers the battle again. What did I mess up in the event to cause this? :LZSoops:
60 sounds like everything should be running fine, but if you want to try anyways, you could look into Yanfly's Fluid Time Step (sorry, "FPS Sync" is what Yanfly calls it, but that's somewhat of a misleading name). This plugin is primarily focused on low-end hardware that struggle to play the game at 60. The plugin effectively bypasses part of the engine that makes the games graphics play independent of any game calculations. By bypassing this, graphics and logic run at the exact same speed. If this does fix the game for you, then it's advised to make sure to include the option to turn this on or off in the menu (a function built into the plugin) because any player (such as myself) that is playing on a monitor that exceeds 60hz will have the game run at speeds faster than intended (and on a 144hz monitor, that means the game would run a little over double speed)

As for the event pages:
give this a try...I'm sure there are some veteran RPG Maker's that would give me for this, but see if it solves your problem, and if the veterans want to offer a better solution they can post it.
Instead of using only variables, use variables and a switch.
So, first set up 4 switches. RandomRoll1, RandomRoll2, RandomRoll3, RandomRoll4
Now, on page 1 of your event: roll the random variable (same as before)
Next create 4 conditionals:
If EnemySpawnSeed = 1
Turn off Switches RandomRoll2 - RandomRoll4
Turn On RandomRoll1
If EnemySpawnSeed = 2
Turn Off RandomRoll1
Turn Off Switches RandomRoll3 - RandomRoll4
Turn On RandomRoll2

etc...
Then set each event page to only be enabled if a specific switch is turned on. Don't use variables to enable/disable the event page

It's a lot of conditionals, which is never ideal, but you could always rework it if you come up with a better solution. In my game I run what some would likely consider an inefficient number of parallel conditionals, but I effectively buffer the effect (or maybe you'd call it asynchronously calculate it) by using hallways between parts of the level.
So basically in the hallway it decides what random monsters will be spawned before you actually go to the map. It's not very dynamic, but it offsets the parallel event from running in the level where the level itself might have a lot of other parallel events running...at least that's how it is in my game since I have a number of puzzle elements that check event locations.
The downside to it not being dynamic and running in it's own event is that each enemy cannot be randomly set, but instead you'd have to have random enemy groups.
So for example that would look like this:
The "RandomRoll1" group is going to set enemy A to bats, B to slimes, C to skelimens, etc.
And every single time RandomRoll1 is chosen, it will always have that same set of chosen enemy teams.
But I suppose in the level itself, to add some randomness, you could have an autorun event that rolls another random number, then using conditionals again, it can set the monsters at different locations. Then if you use erase event or exit event processing, you won't use up headroom of running this event in the background all the time.

Anyways, sorry for the lengthy response. Try to think through the options and maybe you can come up with a better solution :LZSsmile:
OP i like how structured your first Post is. That is a very good layout of what you try to build.
I just say that, because its not often seen but more often needed.

Question:
1.
If you dont Kill the 10 Monsters or only a few, and if you than leave and reenter the map,
do all 10 Monsters respawn random or only the beaten ones?

Suggestion:
Event Frequency needs to be set to the highest setting to allow fluid movement without wait after every step.
60 sounds like everything should be running fine, but if you want to try anyways, you could look into Yanfly's Fluid Time Step (sorry, "FPS Sync" is what Yanfly calls it, but that's somewhat of a misleading name). This plugin is primarily focused on low-end hardware that struggle to play the game at 60. The plugin effectively bypasses part of the engine that makes the games graphics play independent of any game calculations. By bypassing this, graphics and logic run at the exact same speed. If this does fix the game for you, then it's advised to make sure to include the option to turn this on or off in the menu (a function built into the plugin) because any player (such as myself) that is playing on a monitor that exceeds 60hz will have the game run at speeds faster than intended (and on a 144hz monitor, that means the game would run a little over double speed)

As for the event pages:
give this a try...I'm sure there are some veteran RPG Maker's that would give me **** for this, but see if it solves your problem, and if the veterans want to offer a better solution they can post it.
Instead of using only variables, use variables and a switch.
So, first set up 4 switches. RandomRoll1, RandomRoll2, RandomRoll3, RandomRoll4
Now, on page 1 of your event: roll the random variable (same as before)
Next create 4 conditionals:
If EnemySpawnSeed = 1
Turn off Switches RandomRoll2 - RandomRoll4
Turn On RandomRoll1
If EnemySpawnSeed = 2
Turn Off RandomRoll1
Turn Off Switches RandomRoll3 - RandomRoll4
Turn On RandomRoll2

etc...
Then set each event page to only be enabled if a specific switch is turned on. Don't use variables to enable/disable the event page

It's a lot of conditionals, which is never ideal, but you could always rework it if you come up with a better solution. In my game I run what some would likely consider an inefficient number of parallel conditionals, but I effectively buffer the effect (or maybe you'd call it asynchronously calculate it) by using hallways between parts of the level.
So basically in the hallway it decides what random monsters will be spawned before you actually go to the map. It's not very dynamic, but it offsets the parallel event from running in the level where the level itself might have a lot of other parallel events running...at least that's how it is in my game since I have a number of puzzle elements that check event locations.
The downside to it not being dynamic and running in it's own event is that each enemy cannot be randomly set, but instead you'd have to have random enemy groups.
So for example that would look like this:
The "RandomRoll1" group is going to set enemy A to bats, B to slimes, C to skelimens, etc.
And every single time RandomRoll1 is chosen, it will always have that same set of chosen enemy teams.
But I suppose in the level itself, to add some randomness, you could have an autorun event that rolls another random number, then using conditionals again, it can set the monsters at different locations. Then if you use erase event or exit event processing, you won't use up headroom of running this event in the background all the time.

Anyways, sorry for the lengthy response. Try to think through the options and maybe you can come up with a better solution :LZSsmile:
So I did this and it seems to work half the time, and for some reason. It automatically triggers another battle tied to the second page of the event if you win or escape the battle. (I decided to just erase the event if you flee successfully) It should trigger event erase but it seems to fail. Yanfly's plugin did not resolve the stutter stepping. I'm almost certain it's just the event taking too long to recheck the location.

OP i like how structured your first Post is. That is a very good layout of what you try to build.
I just say that, because its not often seen but more often needed.

Question:
1.
If you dont Kill the 10 Monsters or only a few, and if you than leave and reenter the map,
do all 10 Monsters respawn random or only the beaten ones?

Suggestion:
Event Frequency needs to be set to the highest setting to allow fluid movement without wait after every step.
So basically I need to reset the switches and variables tied to the event when exiting the map. This way it recheck when I re-enter. So if I leave the map and re-enter, all 10 monsters will return, regardless of how many I killed. Also, even when the frequency is set to the maximum, they still stutter step.
The Pictures of your Enemy Events have "Autonomous Moveroute Fixed" in your Pictures.
What is moving them?

Original thread: https://forums.rpgmakerweb.com/threads/overworld-encounters.149700/