MV [SOLVED] Evented Overworld Enemy Timers

Been working on some overworld enemy stuff for my game recently, enemy behaviour has been giving me lots of trouble since I decided to event it rather than just use a plugin.

I'm almost there though, enemies are aggravated when the player gets too close, and back off after chasing for a few seconds. My biggest hurdle left is having multiple enemies chase the player at a time, since my eventing currently only uses a timer and a switch set off when enemies are aggravated. I'm looking into using variables at the moment since that's the only way I could see this working without a plugin, but I've been struggling to get it working so I figured I'd ask the forums

Math.abs($gameMap.event(this._eventId).x - $gamePlayer.x) + Math.abs($gameMap.event(this._eventId).y - $gamePlayer.y) <= 4

1766321822973.png

1766321830531.png

1766321837384.png

1766321843256.png


If anybody's got any advice on how I could get multiple timers going thru eventing, feel free to weigh in 'cause I'm gonna be rattling my brain at this for another month at least
I know you wnat to use eventing, but theres a plugin that is made exactly for purpose... Galv makes it.

But if you want to make it completely evented then the solution would be variables - One variable for each enemy on the screen. Then you make it have a set number: something like 10. The you place it in a loop and subtract one from it with a wait command of 60 frames. Put a conditional branch at the top - INSIDE of the loop - That breaks the loop if the variable reaches zero. Then you place all the rest of what happens after the loop... Like this:

1.png

Explaination: The loop stops eventing from happening until the loop is done - MAKE SURE THE EVENT PAGE IS SET TO PARALLEL or else the entire game will stop until the loop is finished.
Each frame is 1/60 of a second - so 60 frames is one second. So the variable is technically set for 10 second. So the loop will keep looping for ten seconds before stopping. You reset the variable after the loop so you can use the loop again next time.

There you go... But you'll have to use a different variable for each and every enemy you want to have this happen with. That can be a lot...
Hmmm, didn't test it, but maybe this works:

Put an <enemy> notetag on the enemy events.
Add a timer to the enemy event when they're aggravated:

$gameMap.event(this._eventId)._encounterTimer = 120;

You can remove the SYS_EnemyAggro switch requirements. And then have a parallel common event (the first lines are to make safe that if you save and the ._encounterTimer isn't saved, then it's added when the event is on self-switch B page):

$gameMap.events().forEach(event => {
if (event.event().meta.enemy && $gameSelfSwitches.value([this._mapId, event.eventId(), 'B']) && !$gameMap.event(event._eventId)._encounterTimer) {
$gameMap.event(event.eventId())._encounterTimer = 120;
}
if (event.event().meta.enemy && event._encounterTimer && event._encounterTimer > 0) {
event._encounterTimer--;
if (event._encounterTimer <= 0) {
$gameSelfSwitches.setValue(
[this._mapId, event.eventId(), 'C'], true
);
}
}
});
Hmmm, didn't test it, but maybe this works:

Put an <enemy> notetag on the enemy events.
Add a timer to the enemy event when they're aggravated:

$gameMap.event(this._eventId)._encounterTimer = 120;

You can remove the SYS_EnemyAggro switch requirements. And then have a parallel common event (the first lines are to make safe that if you save and the ._encounterTimer isn't saved, then it's added when the event is on self-switch B page):

$gameMap.events().forEach(event => {
if (event.event().meta.enemy && $gameSelfSwitches.value([this._mapId, event.eventId(), 'B']) && !$gameMap.event(event._eventId)._encounterTimer) {
$gameMap.event(event.eventId())._encounterTimer = 120;
}
if (event.event().meta.enemy && event._encounterTimer && event._encounterTimer > 0) {
event._encounterTimer--;
if (event._encounterTimer <= 0) {
$gameSelfSwitches.setValue(
[this._mapId, event.eventId(), 'C'], true
);
}
}
});

Testing rn, I'm getting a syntax error when the common event runs
1766339896639.png

1766339963379.png
1766339984747.png

this is how i've got it set up in engine, maybe im doing something wrong?
MV script box has max lines, it looks to me like you cut out the end there. You can put the } on the same lines to make it fit. (That's not to say there might not be errors, I wrote that quite quickly and like I said I didn't test it.)
MV script box has max lines, it looks to me like you cut out the end there. You can put the } on the same lines to make it fit. (That's not to say there might not be errors, I wrote that quite quickly and like I said I didn't test it.)
Gave it a quick edit and it works! Thank you!!!
Follow up; I'm having an issue with a crash that happens when enemies are aggravated, and it's only crashing some of the time.

1767242536486.png


1767242497488.png

I've tried disabling both plugins listed but I keep getting the error, I'm not really sure what the issue is here but I figure posting it on the forums is worth a shot.
I'm not the best at reading those error traces, but does that error even have to do with what's in this thread? It seems in the error trace there's mention of some Rosedale plugin too?
I'm not the best at reading those error traces, but does that error even have to do with what's in this thread? It seems in the error trace there's mention of some Rosedale plugin too?
I would assume it does since it's still occurring without these plugins, and happens on a completely fresh project.
Hmmm, it says "distancetopoint is not a function". I couldn't at least with quick search find that method in rpg maker base code. But yeah, maybe someone else can tell you what the problem is.
bump for if anyone knows why this is happening, i've been asking some friends in the rm scene and i haven't been able to figure anything out
Could you post a screenshot of your enemies' custom move route? Maybe there's something in there that is wrong?
Update; friend of mine got back to me and was able to get it working.

1768271580523.png

The C page had its own wait command added instead of being done through a movement route. This was causing the event to run irregularly and occasionally crash when running its first page again.

I've been trying to figure this out for weeks. I just needed to use a wait command. I love RPG Maker 😀

Game_MYw9XY0fOW.gif

Original thread: https://forums.rpgmakerweb.com/threads/solved-evented-overworld-enemy-timers.181549/