MZ Assistance with a Time Reversal Skill

Greetings All,

Hope everyone is well. I was hoping to get some assistance in implementing a Time Reversal skill that reverts the HP of the target (Friendly or Enemy) to whatever their HP was at the start of the previous turn.

I was able to get the fundamentals down thanks to this sort of two part script created by @Astfgl66

Part 1: A troop event that commences on Turn 1 and occurs every turn that records the HP of all enemies and actors:

JavaScript:
var turn = $gameTroop._turnCount
if (turn === 1) {
$gameTroop._log = [0,{actors:[],enemies:[]}];
} else {
$gameTroop._log.push({actors:[],enemies:[]});
}
$gameParty.battleMembers().forEach(function(member){
$gameTroop._log[turn].actors[member._actorId] = {hp:member._hp}
})
$gameTroop.members().forEach(function(member,index){
$gameTroop._log[turn].enemies[index] = {hp:member._hp}
})

Part 2: A script listed as a note tag on the skill itself that runs at the end of the skill application focused on the function Game_Action.prototype.apply():

JavaScript:
<JS Post-Apply>
var turn = $gameTroop._turnCount
var turnDes = turn - 1; if (turnDes < 1) {turnDes = 1;}
if (target.isActor()) {
target._hp = $gameTroop._log[turnDes].actors[target._actorId].hp
} else {
var index = $gameTroop.members().indexOf(target)
target._hp = $gameTroop._log[turnDes].enemies[index].hp
}
</JS Post-Apply>

The skill works, but only if used on Turn 2. After Turn 2 the skill no longer functions. I've tried setting the Troop Event conditions to different turns but no luck. I'm rather new to coding, so I can't quite wrap my head around how to correct this. I would ask the creator of the script but they seem to have been inactive for a while. Any advice would be greatly appreciated!

For additional information, I'm using Visustella's Battle Core.
can you show a screenshot of the entire window when looking at the troop so we can see the all the information about the troop event? if its only working on turn 2 and the skill looks for the log entry for the previous turn, then the issue may be that the event's span is set to battle and only ever gets ran the one time at the start
Sure! It's the only common event I have set currently for the troop I'm testing it on. The other event tabs are for turning particular switches on and off to activate other mechanics unrelated to this one.
have you tried changing the condition on the troop event to "turn end" or changing it to turn 1+1x?
Even though your span is set to turn, your condition is only valid on turn 1 and itll only ever run once.
This sounds so cool!
have you tried changing the condition on the troop event to "turn end" or changing it to turn 1+1x?
Even though your span is set to turn, your condition is only valid on turn 1 and itll only ever run once.
Oh wow, changing it to Turn 1+1x fixed it! Thank you so much for the help! Works correctly on any turn now!
This sounds so cool!
Right?! Was looking into ways of changing up healing/anti healing and really stuck with this type of skill haha
I may use this in the future… it is just such a cool way to do healing!

Original thread: https://forums.rpgmakerweb.com/threads/assistance-with-a-time-reversal-skill.181356/