Script needed to turn back time in a battle

The easiest way I can think of is to just take snapshots of every moment that you would allow people to go to, and then just use reset the game based on the snapshot. It's pretty much like what emulators are doing when you save snapshots (which I think would be a really cool script to have as well) . You don't need to worry about *how* things happened; you only need to worry about *what* things were like at that point in time.

If the snapshot captures everything, it should support all scripts.

And I don't think it would be that bad on memory consumption, especially if you compress the data.
It's a "memory dump" method that saves a temporary file that can be loaded later. So nope, it won't effect the performance.

Being one of those clumsy player that hates the "jump and fall to your death" points of some games that doesn't allow you to save... I've grown to like that cheat feature myself. But.. it's not foolproof as it seems and in some rare case, the "loading" will fail with an error. Much like that buggy F12.

And i am not sure if it's do-able with rgss player, since it's changing its memory area in random, but well.. since we restore EVERYTHING using memory dump, the pointer is being restored as well i guess. 😛

And unless the memory area is hoarded by another program, that rare crash won't happen.

But well.. this is a "revert time"(or cheat) for reality.

Making it into a game battle mechanic isn't a good idea as the restore will restore everything including pointers/cursor locations... well.. everything.. 😛

And depending on the stored data/graphic size.. that temp file can be somewhere around 70-400mb.
It's a "memory dump" method that saves a temporary file that can be loaded later. So nope, it won't effect the performance.


Being one of those clumsy player that hates the "jump and fall to your death" points of some games that doesn't allow you to save... I've grown to like that cheat feature myself. But.. it's not foolproof as it seems and in some rare case, the "loading" will fail with an error. Much like that buggy F12.


And i am not sure if it's do-able with rgss player, since it's changing its memory area in random, but well.. since we restore EVERYTHING using memory dump, the pointer is being restored as well i guess. 😛


And unless the memory area is hoarded by another program, that rare crash won't happen.


But well.. this is a "revert time"(or cheat) for reality.


Making it into a game battle mechanic isn't a good idea as the restore will restore everything including pointers/cursor locations... well.. everything.. 😛


And depending on the stored data/graphic size.. that temp file can be somewhere around 70-400mb.
Memory dump may be a bit excessive.


Instead, you could dump all of the relevant objects in the current scene and then reload that.


For example, on turn 1 you had a potion. On turn 2 you didn't have a potion.


We don't really care that it was used; we just need to know that when you revert to turn 1, you still have the same potion.
Yes, that's what Sarlecc is doing right now. Saving up to a maximum of 6 turns.

But for the item part, well.. you know how scary an inventory with instant item script can go(you made that script) 😉 . 

That's why i am suggesting him to record the usage of item separately each turn. there's only 4 ids max to record per turn anyway. 😛
Not necessarily. My instance items implementation is flawed because I store all of the items in the inventory, rather than re-building the list everytime it is requested.


It was meant to be an extension to the default inventory storage anyways, where you have a hash of ID's and the quantity.


So I don't think an inventory would really cause too many problems. Plus if you compress the data it should be squished significantly.
Probably, not much difference if the OP is using normal inventory, since there are only x6 sets of digits to store on a modern PC.

Just my style, don't want to store informations that will never get used, temporary or not. 😛

And storing the lump sum inventory ids+quantities will need him to store the currently equipped ids as well. Something that can be dealt with easily i guess.

The current 4 ids method has a problem that needs to be solved anyway.

Depending on where he tap that used? listener.

A custom script that makes skills consume items might not be recorded properly.

Skills like steal/turn enemy into items that update item quantity in real time might not be recorded too.

So in this case, that whole "lump sum" of inventory dump might just proves useful. 🙂

Edit:

Oh yes, since you are more experienced on how the item ids are generated in the inventory.

Is it possible for him to store only the normal consumable items (excluding the weapons/armours/key) and restore them later?
It would be useful in the sense that you don't need to worry about all the difference ways you can interact with the inventory.


Some may view it as a "lazy" workaround because clearly there are a lot of ways you could do anything that you might want to reverse.


For example let's say I have a custom attribute that stores...armor points or something on my battlers.


Now you need to handle that somehow, as well as any interaction that goes with it.


Personally I think it would be easier to just dump the battler object; the game does it already when creating save files anyways.
Umm.. $game_party actually..

But well.. a simple record of @item from the way he's doing it will get everything, including skills.

Come to think of it, skills that allow you to steal/learn new skills from enemy might just need that "revert" too. 🙂
If the attributes are stored on the battler, wouldn't we need to dump the actor/enemy objects?
That's what I told from the start...


There is no way to account for every possible custom scripts by manually doing a data storage, it is impossible, and quite honestly, a waste of time even to try.


Simply dump the actors/enemies, and you are done.


Many scripts are using the dump method on actors (some of them even after every single action in battle), and there is no issue with it.
@Tsukihime, Nope, not sure about the enemies yet, because OP said nothing about reverting them.

But we only need 3-4 params for enemy anyway, there's nothing to go wrong with that part. So a dump is truely a waste of memory.

And well... as the game play goes...  reverting enemies' turns along with actors will render the skill into a mere save-point and hold no other advantages for the player.

If that's the case, I'll simply suggest adding game_temp to the save/load index + a full dump of current battle information there, and allow the user to save/load inside a battle scene. 😛

@Sixth, so you are trying to say, "I know the way i write this script will be incompatible, but i am going to write it anyway knowing one day, users will come knocking and complain" while there's still a chance of getting this out clean in the planning stage? 😉

And giving an example that "Someone did it wrongly, so i have the right to do wrong too!" isn't a solution nor persuasive imo.

Note that it's not 1 actor + 1 enemy dump you are suggesting, it's X6 of 2 libraries. Storing 6 sets of informations separately (not overwrite).

So with those huge amount of data, please guarantee there's no significant time lag each time a user cast that skill since you are firm with your suggestion. And continue to support Sarlecc (who's writing this script currently) when there's complains. 😉
@Tsukihime, Nope, not sure about the enemies yet, because OP said nothing about reverting them.


But we only need 3-4 params for enemy anyway, there's nothing to go wrong with that part. So a dump is truely a waste of memory.
It is implied that enemies will need to be reverted as well, because if you have "taken a lot of damage", then that damage may have come from the enemy. As a consequence, that enemy may have used a skill that cost all of its MP, and that MP would need to be returned.


However if NeoFantasy does not actually require the enemy to be reverted (because cases like the one I mentioned do not apply to the game), then that would be fine, given that your solution is specifically tailored for the request.
You need only 3-4 params for enemy, unless the user got custom scripts for enemies, like levels, equips, custom skill requirements (like cooldowns), and the possibilities are endless.


Same with actors.


I'm saying that creating a data storage manually without incompatibilities with other custom scripts is impossible. You can plan all you want, it's not gonna happen.


If you are planning for the default engine, you can do it, sure, but if not, well, it's your choice to waste your time creating a bigass multi-layered hash for all the data you need to store manually. Even creating a data storage like that is confusing enough, let alone operating each value inside without getting lost in those hashes/arrays inside.


I just did a test with a full dump of $game_party + $game_troop with exactly 2500 items (made with instance item script) without any major loading time. The biggest loading time was around 1-2 second(s), but most of the time it was finished under 1 second. This can vary with PC specs, I guess. Ohh, and the project I tested in got a crazy amount of custom scripts as well. I also forgot to wrote that I tested this with "6.times do", so I actually dumped the whole data 6 whole times within 1 second.


Also, you do not need to dump 6 turns at once. You make a queue, and get rid of older data, which means it is "just" 1 whole dump on each turn, not 6x dump, like you wrote.
Yes, only a few params are needed. eg hp/tp/mp/state/state timer(if there's one)

Even dumping the whole game_troops(not enemy) shouldn't result in a huge data, plus it's already dumped in battle_scene

From what Sarlecc said, @subjects holds both party/troops infos that's currently participating in the battle. And from the list he gave, not too big by itself. The biggest will probably be the infos stored inside @item. So a full/part record of @subjects every turn is the easiest way out. Everything is done inside scene_battle i believe.

Information storing part isn't the hard part imo. The hardest might turns out to finding a way to replace the timer on a state. Adding and removing states is easy but the timer, not sure who handles that. 😛

Edit:

Why dump 6 arrays into the default 1 array? The game might not crash but is there a need to dump them all?
I assumed you create a variable which stores the data. That can be an array (a hash is even better, so you can use the turn numbers as keys in it to get the references easily).


If you got only one skill which jumps back 3 turns, than one dump is enough which gets created on the 3rd (or 4th) turn, and gets refreshed on every turn afterwards.


If you got 2 skills, one can jump back 2 turns, the other 4, than you need 2 dumps in the array, one for the 2 turns jump, and one for the other.


And so on...


I just tested with 6 turns, and did it all at once to stress the PC. Doing only one dump produces no lag at all for me.
And well... as the game play goes...  reverting enemies' turns along with actors will render the skill into a mere save-point and hold no other advantages for the player.

If that's the case, I'll simply suggest adding game_temp to the save/load index + a full dump of current battle information there, and allow the user to save/load inside a battle scene. 😛
The skill is meant to be used as a last resort (obviously the player can mess around with it for fun in battle and experiment) If, the player is losing the battle or wants to reset for whatever reason, let's say they regret using a item or want to deal more damage, they would use the skill.. If it were a save point the player could just endlessly reload from a specific point with no penalty, but the whole point of it is risk and reward. When you reset, Character A who used the skill takes x amount of damage and is unable to do any actions for one turn plus the amount reset. So you get the bonus of undoing your mistakes at the penalty of damaging the party member able to cast the skill (skill would be unavailable if character A died)

@Tsukihime: Yes the enemies would have to be reset as well since you are resetting (going back) turns.
I assumed you create a variable which stores the data. That can be an array (a hash is even better, so you can use the turn numbers as keys in it to get the references easily).


If you got only one skill which jumps back 3 turns, than one dump is enough which gets created on the 3rd (or 4th) turn, and gets refreshed on every turn afterwards.


If you got 2 skills, one can jump back 2 turns, the other 4, than you need 2 dumps in the array, one for the 2 turns jump, and one for the other.


And so on...


I just tested with 6 turns, and did it all at once to stress the PC. Doing only one dump produces no lag at all for me.
What if you could do some sort of snapshot that only captures the differences between different points in time?


Like how git keeps track of version control?


Your first snapshot would be huge because it contains everything, but then later snapshots should be significantly smaller.
The way I am setting up the script right now you can/will have three different types of time revert skills: One that reverts actors, one that reverts enemies and one that reverts everything. I've got the storage part down (though sixth's suggestion of a hash vs an array might work better yet) working on the restoring part.

And yea the saving of the data isn't the hard part.

As for lag issues haven't encountered any when storing the data.

@Neo would you calculate damage before the skill is cast or after? If after and it reverts everything back then that actor will come back to life. 😮 If before then if the damage would be enough to knock out the actor then you would be unable to use the skill. Making the above problem nonexistent.

Edit let me rephrase that some seemed weird to me: Normally when you cast a skill it is used on that turn and damage is applied which if you record the turn it would be in the list of stuff to restore. Now you would have to deal damage after the restore part but have it calculate before you even use the skill.
I'd calculate it before, so if it is enough to knock out the character they're knocked out, if it isn't they still receive the damage. 
Since the skill should be something like target "user", the damage formula will work on calculating/dealing the damage.

So all Sarlecc need is to restore before the action is done and NeoFantasy can handle the rest in the skill editor i bet.
But if we do it that way won't the damage be calculated once the skill is activated.

Original thread: https://forums.rpgmakerweb.com/threads/script-needed-to-turn-back-time-in-a-battle.44889/