Common event with a timer makes player flee battle automatically.

Title. I'm having a common event for a skill that acts as a detector for hidden chests. It runs for a certain time and then wears off.
Unbenannt.JPG

It's rather simple. I don't know how and why it would do that. Apparently one of my players also said that you could find chests even after the timer runs out. Chests getting activated via the switch on the event so i also don't see how that would be possible.
Need some help on this one.
I'm not sure about the chest part, but about battles ending, that's normal.

For one reason or another, the default code for timers ending is:

Code:
Game_Timer.prototype.onExpire = function() {
    BattleManager.abort();
};

Meaning, when the timer ends, the Battle ends.

You can make a very simple plugin that removes this, or just comment out that BattleManager.abort(); line of code in rpg_objects.js . I know a lot of people frown upon editing the main files, though, so the plugin option is probably better.

This is the entire plugin:

Code:
(function() {

var new_Game_Timer_onExpire = Game_Timer.prototype.onExpire;
Game_Timer.prototype.onExpire = function() {
    //BattleManager.abort();
};

})();

Just save that as a .js file, and install it in your plugins, and timers running out shouldn't end battles anymore.
Thanks for the response @TheTitan99 ! Much appreciated! Very awesome to even provide the code!
Apparently, the Common event isn't working properly in general either. The timer starts, np. But even out of combat it doesn't show the message or anything. Tried to do a "Erase event" too but that's not doing anything either.
Okay, so, I may have an answer for the eventing part! What type of event is this? Is it a Parallel event, or an event that runs when activated?

If it's not Parallel, then the event will not work. The event will read:

Set timer to 1 minute.
Is timer at 0 seconds? No, it's at 1 minute.
Done.

The if condition runs once, and only once, unless the event is Parallel.
It's supposed to run only once. Until the player uses the skill that call upon that event again. Trigger is none, as i would need to input a switch for no reason. So it's neither parallel nor automatic. I just wonder why it then runs at all, but doesn't display the msg.

Scratch that. I just understood what you're saying. Great hint! Didn't know that at all.
So, reading through this common event, there's actually no way it can work how you want. I'll break it down:

The way how events work in RPG Maker is they run through the event commands in order, top to bottom, once only. So, the animation plays once, then the timer is set once, then the switch is set once, and so on. This includes Conditionals.

So, how this common event is currently set up, it runs, and sets the Timer to 1 minute. Right after that, the conditional checks the timer. The timer is at 1 minute. You just set it to 1 minute. So, the conditional knows that the timer is not at 0 seconds. Thus, nothing within the conditional runs.

This is because of just how events work in RPG Maker. That Conditional, that statement that checks if the timer is at 0 seconds, only checks once, right then. It won't wait until the timer is at0 seconds, then run. It simply checks right then and there if the timer is at 0seconds, and if it is at that moment in time, then the event commands in the conditional are run. Seeing as right before the conditional, you set the timer to 1 minute, the conditional can never be true, so the message can never run.
Yeah, as I said, I got what you were saying after reading it again. ALready fixed the issue aswell. Basically what you do, is to call another common event wich turns on a switch, wich activates the actualy common event running on parallel. But yeah, thanks alot for the input and the code ! Much appreciated 😀
You're welcome!
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/common-event-with-a-timer-makes-player-flee-battle-automatically.132120/