MV Pausing an Autorun Event and replaying it later from the same point

Hey, I don't think I've ever seen someone find a solution for this, so I assumed it's best to post it in plugin requests.
I need a way to pause an autorun event, and then replay it later from the same point.

Basically, my game is a visual novel with an autorun event being on 99% of the time, and when an autorun event is on, you can't move your character. However, in the autorun loop, there's a moment when you need to move your character. This moment is different, depending on the situation, so having some kind of conditional branch to make the event stop running won't work, I need an actual way to pause the event with (preferably) 1 plugin command / script.
Then, after you interact with a different event on the map, I want the autorun plugin to replay from that very moment, without restarting.

Has anyone ever tried doing that? Is that even possible?

Thanks
Hey,

There are definitely ways to do this. For example:

If the event is supposed to interrupt itself, then you could run this to exit the event:
JavaScript:
let variableId = 127;
$gameVariables.setValue(variableId, this._index); // Store the position in variable 127
this._index = this._list.length;                  // Exit Event Processing

...and put this at the very beginning of the event to jump back to the stored position when the event is restarted:
JavaScript:
// Jump to the position stored in variable 127
// Do not jump backwards if the variable is still set to 0 and this is not the very first event command.
let variableId = 127;
this.jumpTo(Math.max($gameVariables.value(variableId), this._index));

Edit: Correction to the second script command (did not consider the index gets already increased)

Late Edit 1: Not necessary, but another slight change to allow the second script command to be placed lower.
Late Edit 2: To clarify, this is essentially just a slightly fancier way to do this than with events:
Spoiler
JumpToLabel.jpg
Hey,

There are definitely ways to do this. For example:

If the event is supposed to interrupt itself, then you could run this to exit the event:
JavaScript:
let variableId = 127;
$gameVariables.setValue(variableId, this._index); // Store the position in variable 127
this._index = this._list.length;                  // Exit Event Processing

...and put this at the very beginning of the event to jump back to the stored position when the event is restarted:
JavaScript:
let variableId = 127;
this._index = $gameVariables.value(variableId); // Jump to the position stored in variable 127

Edit: Correction to the second script command (did not consider the index gets already increased)
Wouldn't you also have to set the interpreter's event ID, since it will be running the one that restarts the autorun rather than the autorun itself?
Wouldn't you also have to set the interpreter's event ID, since it will be running the one that restarts the autorun rather than the autorun itself?
Definitely did not entirely think this through, but it was supposed to be a more fancy "Jump to Label" command, with the target being the position the last iteration left off.
Right now you would still need to restart the event yourself (due to it being on autorun possibly by turning a switch on).

Although I am not 100% sure if this will work for the intended purpose. If you are planning to pause the event from within a "Call Common Event" command, then just saving/restoring one index may not be enough.
I am not sure if this is what you were looking for, but you need to be very specific on the index. Using a game variable helps keep track of it, yes, however, it is crucial that you know exactly which index you need to the code to be. In my quick test, if I was off by 1 index, I completely skipped an "if" statement and it ran the line of code inside since that was the next index.

Note: I chose not to place comments inside the event commands because that also requires an index check (every comment, every line of script call, etc. has an index).

Event commands:
Spoiler
Index 0: Script: Set the trigger to 0 so that the autorun only runs these commands once. Set the index to include game variable 1 and add 1 to it to move to the next index.
This is important because when I run the code again with the new value inside the game variable, it will account for the new index.
-- (index 1 (command655) is a part of the script call and requires an index)
Index 2: Text: Check to make sure sequence is running as intended.
--
Index 4: (Yes, 4, because the text command uses command 101 and 401) Change HP by -500
Index 5: Change MP by -100
Index 6: Change Gold by +999999
Index 7: Text: Check to make sure sequence is running as intended.
--
Index 9: Set Variable 1 to current index (which is 10)
Index 10: Exit the event at this line
Index 11: If Script: make sure the player cannot interact with this event during this time
Index 12: Exit the event if the player tries to interact with the event (part of If statement)
Index 13: (Nothing)
Index 14: Close the if statement
Index 15: -- This is where the new interaction should begin -- Change HP by +999
Index 16: Change MP by +999
Index 17: Change Gold by -999999
Index 18: Change Entire Party by +5 Levels
Index 19: Show Powerup Animation on Player
Index 20: Text: Show text (will take up 3 indexes)
--
--
--
Index 23: Set Self Switch A to ON
Index 24: (Nothing)

Event Photos:
Spoiler
Page 1 of Event 1:

s1.png

Page 2 of Event 1 (error, set this page to action button, not autorun):
s2.png


Page 1 of Event 2:
s3.png
The character here will "fix" Event 1 for you to show how a cutscene might work. Increase the game variable by 4 to assure the proper index is being run.

Use this.character(1).start() to start the game map event 1. You can also do $gameMap.event(1).start().

Note:
Spoiler
It is important to add 4 to game variable 1 because we need to skip the "If Script" check below the first Exit Event Processing. Otherwise, you will not be able to properly activate the event and it will automatically exit the event, put you in the wrong index, or worse, soft-lock the game. This means that you now need to check the page/list of commands and count to make sure you are in the right place. Or, set up code that will "jump" to the correct place - that will unfortunately cause another form of a loop/index that you need to account for as well.

If all is done correctly, you should see your HP, MP, Gold, and Level change as well as the final message. It should then switch to Self Switch A's page and be complete.

All of this is to say, this is a very rough draft and is not automated. You need to double check your indexes and any work that you add to the event will change that part. Using comments and labels might help and you could grab those with code and help index everything better; it just requires more work that I am able to do currently with limited time.

if you can find a better workaround, please do. Use a different page, do a remote start, and continue from there - or, simply guide the player better instead of giving them a choice in that moment. Or, give them a choice and allow it to turn on a switch that will run a new page of code. Otherwise, you will spend a lot more time just testing to find the correct index, run a lot of extra code checks, etc.

Best of luck!

Original thread: https://forums.rpgmakerweb.com/threads/pausing-an-autorun-event-and-replaying-it-later-from-the-same-point.176812/