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:
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():
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.
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.