Sometimes a mistake at the start of a battle can leave your players wishing there was a ‘rewind’ button to give them a second chance. So why don’t we try to find a way we can event that possibility?
Actually resetting the battle to Turn 0 isn’t easy without editing code or relying on a plugin, so let’s focus more on simulating the restart of the battle where the enemies are all alive and our party is in a better situation. Since we need a way for our player to choose to restart the battle let’s create a Rewind Time skill that calls a common event. That common event is what will control all of the healing, instead of trying to get the damage formula to work on everyone in the battle.
We could also do this with an item if we wanted any party member to be able to restart the battle, but for this tutorial a skill that only Priscilla can use is fine.
For our first Rewind Time skill, let’s set it up as if our party is fully healed after each battle so that they go into battles with full HP and MP. That makes our common event rather simple, with just two event commands required: Enemy Recover All for the entire troop and Recover All for the entire party. These two commands will restore all of the missing HP and MP along with removing any states and bring back to life the defeated friends and foes.
Then we can playtest and see it in action. The start of our battle would have our party with full health and ready to go.
But a few turns in perhaps we’re low on MP, poisoned, and missing our healer. While we could keep fighting, restarting the battle may give us better options.
So we use the Rewind Time skill
Which gives us another chance to win the battle.
Of course, this option has its downsides. If we don’t fully heal our party after each battle then this skill isn’t really restarting the battle, it’s just offering another way to heal. And it doesn’t take the TP into account, which could make battles easier for our player since they could just wait until their TP was full before rewinding time. So let’s take a look at how we could pay attention to our party’s HP/MP/TP at the start of the battle.
Now, if we want to rewind our party’s health to what it was at the start of the battle then we need to record what that health is. So we need to add a battle event page that runs once at the start of each battle that calls our Rewind Time common event.
We can add a conditional branch to the start of our common event that checks if it is the start of battle (Turn 0) using the script call $gameTroop.turnCount() == 0 . If that is true then we can set variables to our party’s current HP, MP, and TP. For this example we only recorded Priscilla, but for a full game we would need to save every party member’s health. Once each variable is saved, we can use the Exit Event Processing command to end the common event and let us get to the battle.
With our party’s HP/MP/TP saved at the start of the battle, now we need to find a way to restore those values when the Rewind Time skill is used. The default Change HP command can work, but we would need to drop Priscilla’s HP to 0 first since we can only add or subtract if we use that command. So instead of Change HP, let’s use the script call $gameActors.actor(ID).setHp(n) where ID is Priscilla’s actor id (2) and n is the value we want to set her HP to (since we saved that value in a variable, we’ll use $gameVariables.value(1) ). We can also set our actor’s MP and TP using .setMp(n) and .setTp(n) , so to reset Priscilla’s HP, MP, and TP we can use these script calls:
$gameActors.actor(2).setHp($gameVariables.value(1))
$gameActors.actor(2).setMp($gameVariables.value(2))
$gameActors.actor(2).setTp($gameVariables.value(3))
We can still heal the enemies using Enemy Recover All since they start the battle at full health, so our common event ends up looking like this:
While this does work, we obviously end up using a lot of variables if our game has a bunch of party members. Is there a way we can condense these values? Yes, by using arrays in our variables. We can store each of our actor’s HP, MP, and TP in an array, meaning we only need a single variable for each actor. In our Turn 0 conditional branch we’ll set up Control Variable commands for everyone that records their health using the script calls $gameActors.actor(ID).hp, $gameActors.actor(ID).mp, and $gameActors.actor(ID).tp. We could set the variable using:
[$gameActors.actor(ID).hp, $gameActors.actor(ID).mp, $gameActors.actor(ID).tp]
But we can also shorten it by setting a letter (a) to $gameActors.actor(ID), meaning we can write our HP/MP/TP array as [a.hp, a.mp, a.tp]. By default Priscilla’s actor id is 2, so her variable script call would be:
const a = $gameActors.actor(2); [a.hp, a.mp, a.tp]
Then we can copy-paste that command and just change the variable and actor id to record the rest of our party.
When our player uses the Rewind Time skill we can use the a = $gameActors.actor(2); knowledge, along with shortening the variable call with array = $gameVariables.value(1);, to shorten the script calls from $gameActors.actor(2).setHp($gameVariables.value(1)[0]) to a.setHp(array[0]). That makes the script calls to return Priscilla’s health to the battle start this:
const a = $gameActors.actor(2);
const array = $gameVariables.value(1);
a.setHp(array[0])
a.setMp(array[1])
a.setTp(array[2])
Then we can copy-paste again to make sure each actor is healed the right amount.
All together (along with a test message to make sure things are saving properly), we end up with our common event looking like this:
To remove any states our party may have gotten we can use the Recover All command before setting each actor’s health, so that they will be fully healed before returning to the battle-start health. We could condense this down even more, but personally I find having each actor split into their own variable and script helpful for checking for issues with a glance.
So far we’ve only focused on our actor’s HP, MP, and TP, but what about items? You could decide that any items your players use before rewinding time are gone, meaning they need to really think if it’s worth it to restart the battle, but if you want your players to regain all of the items used since the start of the battle then we need to add some more code.
At the start of the battle we can save our player’s current items with this script call:
$gameVariables.setValue(10, Object.assign({}, $gameParty._items));
Which will save all of the item info (including amounts) into the variable.
Then we need to add them back when the skill is used in battle. I don’t know of a script call to set the item amount like how we can set HP, so we’ll need to remove all of our player’s items before we can give them the right number of items from the battle start. So we’ll use these script calls:
//removes all items
$gameParty.items().forEach(function(item){
$gameParty.loseItem(item, 999)
});
//returns stored items
const oldItems = $gameVariables.value(10);
for (const id in oldItems) {
$gameParty.gainItem($dataItems[id], oldItems[id]);
}
To remove every item from our player’s inventory and then give them the right amount after that.
One thing we would need to keep in mind is that if our Rewind Time event uses up an item, then we will need to remove it after returning the saved items since at the start of the battle we still had the used item (time travel is confusing).
Now our players can rewind time in battles! How would you use this system in your games, would you let them rewind in every battle or save it for special boss battles?