MZ Trigger a specific common event at the end of every event

In my previous games I had a counter that ticked up whenever the player talked with Any npc. I did that MANUALLY and it was a pain.

This time around I figure I might as well automate it, so I'm looking for a plugin to play a specific common event at the end of every event automatically (similar, for instance, to how visustella allows you to play a common event at the end of every battle). Bonus gratefulness if it can Not play at the end of certain events by reading a <DontCount> tag at the end of the name of said event. (but it's ok if not, worse case scenario i can handle that through a switch).
shouldn't be to hard, but does this also count for ALL pages the event has that
switch with selfswitch or variable?

because if the common event count + 1 after talking to it.
why not just add that common event?

if it has variable +1 on talking, it can increase fast by continues talking to it.
I don't know how MZ handles it, but it shouldn't be to difficult to add, just clarification.
shouldn't be to hard, but does this also count for ALL pages the event has that
switch with selfswitch or variable?

because if the common event count + 1 after talking to it.
why not just add that common event?

if it has variable +1 on talking, it can increase fast by continues talking to it.
I don't know how MZ handles it, but it shouldn't be to difficult to add, just clarification.

This would have to play at the end of every event in the game, so yeah, I think it should play at the end of every page.
This include events for getting loot, opening treasure boxes, map transfers, common events on parallel process, etc.?
This include events for getting loot, opening treasure boxes, map transfers, common events on parallel process, etc.?
Yes

I would like to skip the common events and parallel process, but i can do that through a tag

In fact i tried my hand at it, and This works EXCEPT for some reason it stops random encounters from happening, not sure what it breaks...

Game_Interpreter.prototype.terminate = function() {
if ($gameMap.event(this.eventId()) != null)
{
if ($gameMap.event(this.eventId()).event().name.includes("<Timeless>") )
{
}
else
{
$gameMessage.add($gameMap.event(this.eventId()).event().name ); //this line is for debug purpose, should be removed in the final game
$gameTemp.reserveCommonEvent(2);
}
}
this._list = null;
this._comments = "";
};
Setting list to null probably erases the process that counts steps. Just might mess up your game time as well. IDK.

I'll assume the terminate function already exists and if so, it might have been better to alias it so you don't lose any functionality between your code and other plugins including the original code.
Setting list to null probably erases the process that counts steps.
That's actually in the original - those two last lines are the original function 😉

There are a few logical errors in that code - there's no point in checking if $gameMap.event(this.eventId()) is valid, because there couldn't be a this.eventId() otherwise.

It also doesn't make much sense to check for the event name to include Timeless and have an empty code block afterward - just reverse the conditional to check for it to not include Timeless.

I don't immediately see how this would break encounters, but I think I would do this at a higher level. And if literally the only thing you're doing is incrementing a counter, why don't you just do that instead of calling an entire other common event?

Code:
Game_Interpreter.prototype.terminate = function() {
    if (this.eventId() && !$gameMap.event(this.eventId()).event().name.includes("<Timeless>"))
        $gameVariables.setvalue(42, $gameVariables.value(42) + 1);
    this._list = null;
    this._comments = "";
};
where 42 is the ID of the variable you're counting up.
That's actually in the original - those two last lines are the original function 😉

There are a few logical errors in that code - there's no point in checking if $gameMap.event(this.eventId()) is valid, because there couldn't be a this.eventId() otherwise.

It also doesn't make much sense to check for the event name to include Timeless and have an empty code block afterward - just reverse the conditional to check for it to not include Timeless.

I don't immediately see how this would break encounters, but I think I would do this at a higher level. And if literally the only thing you're doing is incrementing a counter, why don't you just do that instead of calling an entire other common event?

Code:
Game_Interpreter.prototype.terminate = function() {
    if (this.eventId() && !$gameMap.event(this.eventId()).event().name.includes("<Timeless>"))
        $gameVariables.setvalue(42, $gameVariables.value(42) + 1);
    this._list = null;
    this._comments = "";
};
where 42 is the ID of the variable you're counting up.

It broke encounters because of some weird interaction with visustella it turns out. So I ended up moving the code somewhere else (I guess visustella needs to re-write the terminate code; So I move my code to the only function that invokes terminate). Then encountered the problem where events that map transfered the player would break the code utterly, because of course all my code would happen after the map transfer and used the map to set the id, so I ended up with this (Where i have to manually set a flag whenever i do a map transfer to ignore that event... which is not ideal... but at least it works)

Game_Interpreter.prototype.executeCommand = function() {
const command = this.currentCommand();
if (command) {
this._indent = command.indent;
const methodName = "command" + command.code;
if (typeof this[methodName] === "function") {
if (!this[methodName](command.parameters)) {
return false;
}
}
this._index++;
} else {
if ($gameSwitches.value(12))
{
$gameSwitches.setValue(12, false);
}
else
{
if ($gameMap.event(this.eventId()) != null)
{
if ($gameMap.event(this.eventId()).event().name.includes("<Timeless>") )
{
}
else
{
$gameMessage.add($gameMap.event(this.eventId()).event().name );
$gameTemp.reserveCommonEvent(2);
}
}
}
this.terminate();
}
return true;
};


Writing down this mostly for future knowledge in case someone googles this lol.

I will now try to integrate your version of the code in the new location and adding the map transfer failsafe, as yours definitelly looks better. Thanks 🙂

Ah, that said the reason why i don't increment the counter in-code, is that I eventually want to add other stuff to that common event (namely doing things depending on the counter's value, like playing cut-away cutscenes), so a common event is probably best for this use.

Original thread: https://forums.rpgmakerweb.com/threads/trigger-a-specific-common-event-at-the-end-of-every-event.172803/