Save Script Questions

Hey there! I'm relatively new, but I'll just get to the point, to make it easy on all of us.

I plan to make a game with permadeath, where character choices matter, and I need a couple of questions answered.

1. Is it possible to make it to where the game can be force-saved immediately as a character's HP reaches 0 in battle, preferably without having to leave battle first? I need this to be in-place, as an anti-reset measure. Don't want people thinking they can just get away with letting their characters die in battle.

2. Could I edit the code of the game to make it to where the game deletes a save file as soon as the player gets a Game Over? As part of the permadeath feature, if the player's character dies, then their run is done.

Thanks in advance! If any clarifications are needed, go ahead and ask.
I'm not sure you CAN save during battle, can you?


In either case, I personally wouldn't touch a game that did either of those things. Why are you punishing people for playing your game?
I'm not sure you CAN save during battle, can you?

In either case, I personally wouldn't touch a game that did either of those things. Why are you punishing people for playing your game?
The data structures don't really support saving during battle, only before or after. If someone is considering doing this, another mechanism should be used.

Hey there! I'm relatively new, but I'll just get to the point, to make it easy on all of us.

I plan to make a game with permadeath, where character choices matter, and I need a couple of questions answered.

1. Is it possible to make it to where the game can be force-saved immediately as a character's HP reaches 0 in battle, preferably without having to leave battle first? I need this to be in-place, as an anti-reset measure. Don't want people thinking they can just get away with letting their characters die in battle.

2. Could I edit the code of the game to make it to where the game deletes a save file as soon as the player gets a Game Over? As part of the permadeath feature, if the player's character dies, then their run is done.

Thanks in advance! If any clarifications are needed, go ahead and ask.
Before I answer: "Permadeath" is an awful mechanic and you will actually encourage people to cheat. Permadeath only belongs in games where the world is persistant, which is more typical of MMORPG's, not single player games. For example, Starflight has a set time when the world goes boom. So no matter what you do, if you waste too much time, the game is unwinnable. Likewise games like Ultima and Wizardry had perma-death for party characters, but if everyone dies, game over, reboot the PC and try again.

1. You could force it to save once the battle exits, but not during, no. This is basically thinking about how the data is serialized and how a battle is a specific "state" that ceases to exist once the battle completes. So if you could force a save, you'd only be saving the world state, not the battle state. If that happens to be that the player is at 0HP, depending on how you have the game setup, 0HP may just make the characters "unconscious" and in a weird state where the party is dead but you can still wander around.

2. Uh... you could. This isn't wise.

So now let me tell you exactly what will happen.

Players that really interested in the game will "train" the game so saving the game can't be deleted. Players that hate the mechanic and aren't really interested in the story will just not play the game the first time it happens.

From playing games with permadeath mechanics, I say again, it's really a poor game design.

You can :

a) if party members die, make the resurrection penalty steep, this would prevent players from just spamming battles until they win. Either lose 10% of their EXP or make the resurrection item expensive.

😎 If "hero" player dies, save a second file to keep track of deaths, and when the player re-loads after death, chastise them when the number of deaths is different from the save file.
I love how you're both trying to discourage me from this. Without going into detail, allow me to say that most of the people I've approached with the full idea have been completely on-board with both mechanics. Rather than trying to simply "punish the player," the mechanics are in place for the realm of the story, not simply the player. They have to be careful because your actions will shape the world.

That said, there will be plenty of things that make the game forgiving. Many enemies (the only exception really being bosses) will find it hard to kill off any more than the most underleveled party members for the area. There will also be Low Health Warnings ("I'm not doing too well, heal me please!"), Dangerous Area Warnings ("I don't feel comfortable being here. Let's go back."), and a method to send a character with low health back to town, and get a new party member from town. Stuff like that to help out the careful players, but punish the reckless ones that care to ignore it.

Anyways, I have a few ideas. I don't know JavaScript that well, so if someone could help run me through this (or point me to some website that would help me learn how to do this myself), then I would appreciate it.

1. Take on the UNDERTALE method. Write to a file as it happens, and when the game is loaded, call a common event immediately as part of the load process that checks the file, forces switches on and removes characters based on lines in that file (say, if the line "Character 101 is dead." is read, then the death switch for character 101 is turned on, and then character 101 is force-removed from the party.), and maybe chastises the player for cheating, if they did, too.

2. Could I make the Game Over script to check if a certain switch (Mercy Mode, for simplicity's sake) was on, and if Mercy Mode was off, then it deleted the file?
I love how you're both trying to discourage me from this. Without going into detail, allow me to say that most of the people I've approached with the full idea have been completely on-board with both mechanics. Rather than trying to simply "punish the player," the mechanics are in place for the realm of the story, not simply the player. They have to be careful because your actions will shape the world.

That said, there will be plenty of things that make the game forgiving. Many enemies (the only exception really being bosses) will find it hard to kill off any more than the most underleveled party members for the area. There will also be Low Health Warnings ("I'm not doing too well, heal me please!"), Dangerous Area Warnings ("I don't feel comfortable being here. Let's go back."), and a method to send a character with low health back to town, and get a new party member from town. Stuff like that to help out the careful players, but punish the reckless ones that care to ignore it.

Anyways, I have a few ideas. I don't know JavaScript that well, so if someone could help run me through this (or point me to some website that would help me learn how to do this myself), then I would appreciate it.

1. Take on the UNDERTALE method. Write to a file as it happens, and when the game is loaded, call a common event immediately as part of the load process that checks the file, forces switches on and removes characters based on lines in that file (say, if the line "Character 101 is dead." is read, then the death switch for character 101 is turned on, and then character 101 is force-removed from the party.), and maybe chastises the player for cheating, if they did, too.

2. Could I make the Game Over script to check if a certain switch (Mercy Mode, for simplicity's sake) was on, and if Mercy Mode was off, then it deleted the file?
Again, "permadeath" is a very hard mechanic to balance. If you want to approach it from a "I know what you did" aspect like Undertale, rather than "whoops you dead, you can never play again unless you reformat the pc (or hunt down where I stored the cookie)", then that might be palatable. In the case of a game like Starflight, every time you "changed maps" the game state saved, but if you forgot to actually save the game, the game was wrecked.

1.Undertale's method is actually simple. It has 3 save files. One for where the player manually invokes a save, one is a checkpoint, and one is a "final boss state", with the latter being necessary since the game kicks you out when you die and needs a progress marker. Also the switch from neutral to pacifist still requires being able to load the state before the final boss was activated. It also has a flags file which marks down how many times you've met or done something, and one additional flag for marking the no-mercy mode.

So to do "character 101 is dead, you can't get him back by save scumming" type of check, you actually save two files, one is the "save game" the other is the "game state" which is a copy of the tamper switches.

So first, take a look at YEP_SaveEventLocations.js as this plugin does something like that for events on the map.

Second rpg_managers.js

StorageManager.saveToLocalFile = function(savefileId, json) { var data = LZString.compressToBase64(json); var fs = require('fs'); var dirPath = this.localFileDirectoryPath(); var filePath = this.localFilePath(savefileId); if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath); } fs.writeFileSync(filePath, data);};This is why you can't do what you want to do out-of-the-box. There are separate save functions for saving/loading from a local file or if it is in a web browser.

So it defines only a save file, and only this data is saved:

DataManager.makeSaveContents = function() { // A save data does not contain $gameTemp, $gameMessage, and $gameTroop. var contents = {}; contents.system = $gameSystem; contents.screen = $gameScreen; contents.timer = $gameTimer; contents.switches = $gameSwitches; contents.variables = $gameVariables; contents.selfSwitches = $gameSelfSwitches; contents.actors = $gameActors; contents.party = $gameParty; contents.map = $gameMap; contents.player = $gamePlayer; return contents;};So for the sake of argument, you add a contents.tamperswitch=heroisdead; which would always be false unless the player died.

then in the save/load process you re-evaluate the conditions which make heroisdead. If they don't match, cut to the "chastise the player" scene.

If you want to do the "two save file" method, eg to progress through a hard boss, you actually check for the existence of the "alternate save" and a flag denoting the battle is complete.

But as I said earlier, people will cheat. When people do the no-mercy run in Undertale, it saves flags throughout the save games and two other files to indicate the progress across game resets. Players can just delete these extra files and the save game to do a true reset. Or they can edit the save game (in the case of RPG Maker, it would be slightly harder than trivial.)  So you generally want to do things in a way that is "tamper detection" not outright "if variable is X do Y". Like you could do a md5 sum on the save game, and store the md5 sum in a game state, so if any data was edited in the save game, you'd know it's been tampered with. There are also memory-resident based cheating programs for the really depraved and incompetent cheater.

2. This is more obvious.

DataManager.saveGame = function(savefileId) { try { return this.saveGameWithoutRescue(savefileId); } catch (e) { console.error(e); try { StorageManager.remove(savefileId); } catch (e2) { } return false; }};Notice it tries to save the game and if it can't it deletes the save.

rpg_objects.js

// Game OverGame_Interpreter.prototype.command353 = function() { SceneManager.goto(Scene_Gameover); return true;};So to do what you want, put StorageManager.remove(savefileId) before SceneManager.goto(Scene_Gameover);

you can override this with with a plugin instead of editing the javascript.

Just put a check for the switch, so you'd have something like this:

// Game OverGame_Interpreter.prototype.command353 = function() {if($gameSwitches.value(666)){StorageManager.remove(DataManager.latestSavefileId);} SceneManager.goto(Scene_Gameover); return true;};As I said earlier, people will cheat, and in this case they could bypass it by editing or removing this as plugin.
I've moved this thread to JS Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.
@KisaiTenshi, I think we may be thinking different things as for the 'permadeath' thing. The permadeath is closer to roguelike games than anything. It's not anything on the lines of the flash game, You Only Live Once. Simply that, if the main character dies, instead of being able to continue with the main character dead, you have to start the game over. I'm not that much of a spawn of Satan.

Anyways, it looks like I'll have to scour the code much more deeply, as for the Save Events Locations and what-not. As for the tamper switches part, would it be best to do something like... (assuming the tamper switches will all be in one group, which they will be, since that makes everything easier)

content.tamperSwitches = $gameSwitches.slice(firstTamperSwitch, lastTamperSwitch + 1);and, at some point in the code, create a method that is called every time one of the tamper switches is changed that saves a separate file on the user's computer somewhere, for the previously mentioned purposes?

As for the save deletion, it's actually a lot more simple than I thought it'd be. I'll have to keep that in mind. Thanks. As for cheating... Well, I only made this topic so I could learn what all I could do to fight it and go against it. But if players find a way around it, then heck, they went through a good amount of trouble just to ruin the spirit of a game for themselves. That's how I see it, anyways.

Anyways, I find that I have to get to learning JavaScript a lot faster/better now that RPG Maker MV's actually been out for a while. Making a game with just the editor doesn't really fit me.

@Shaz, yeah, I only noticed that this was the best place to put it long after I had posted this. Thanks, anyways.
content.tamperSwitches = $gameSwitches.slice(firstTamperSwitch, lastTamperSwitch + 1);and, at some point in the code, create a method that is called every time one of the tamper switches is changed that saves a separate file on the user's computer somewhere, for the previously mentioned purposes?
Basically "tamper switch" idea is to verify that the user hasn't just reloaded the game mid-battle or whatever. So every time a plot element happens, you force this other file to be updated, and if the player reloads the save to before that state, you know the player is save scumming and you chastise the player or force them to do something. Like in the case of Undertale, there is always a checkpoint file, and the checkpoint file is updated every time you switch areas or use elevators, every time you manually save it overwrites both the checkpoint file and the save.

So either way you can't "time travel", you can only go back to where the last time the game invoked a save. I think it's less cruel to the player to chastise them and maybe penalize them for it than to outright prevent them from backtracking too much. Like in Wizardry, even the MMORPG, if you die, it costs you inventory items to "pray to resurrect", and if you are too underleveled for the area you're in, you could dump your entire inventory and won't get a 100%.
What you're saying is that if the player is hit with an unlucky critical hit, or goes up against an enemy that they weren't ready for, or can't afford potions and is out of healing magic.... then " you, you suck, start over."

That sounds awful. Only the most masochistic of RPGers would play that.

Original thread: https://forums.rpgmakerweb.com/threads/save-script-questions.52259/