Autosaving at specified points without using plugins?

$gameSystem.onBeforeSave(); if (DataManager.saveGame(slotId)) { StorageManager.cleanBackup(slotId);
Can this script call be used in events to save a game automatically, and specifically in the last used slot of a playthrough to avoid accidental save loss?
If it is, then I also would like to know if there's also a script call that can detect if a playthrough has not used any saves at all, so that the autosave can be skipped with a conditional branch.
Pretty much. This is how MZ does it:

JavaScript:
Scene_Base.prototype.executeAutosave = function() {
    $gameSystem.onBeforeSave();
    DataManager.saveGame(0)
        .then(() => this.onAutosaveSuccess())
        .catch(() => this.onAutosaveFailure());
};
I see, thank you. I noticed MV has DataManager.lastAccessedSavefileId(); to check the most recently accessed save slot; how can I use this to make sure the "autosave" always saves in that slot?
I think I got it. But please let me know if I did something wrong.

Code:
var AutoSave = DataManager.lastAccessedSavefileId();
$gameSystem.onBeforeSave();
if (DataManager.saveGame(AutoSave)) {
  StorageManager.cleanBackup(AutoSave);
}
StorageManager.remove(1);
StorageManager.cleanBackup(1);

This immediately saves the game in the last accessed save slot, whether it's loaded or previously saved on.
If a playthrough has not used saves, the variable defaults to 1 (I'm not sure anything can be done about that), so that is why slot 1 gets immediately auto-deleted with the last 2 lines. They're optional but they make sure saveless playthroughs stay saveless, although the player can still manually save in that slot and then lose progress, so a warning would be needed.
I think I got it. But please let me know if I did something wrong.

Code:
var AutoSave = DataManager.lastAccessedSavefileId();
$gameSystem.onBeforeSave();
if (DataManager.saveGame(AutoSave)) {
  StorageManager.cleanBackup(AutoSave);
}
StorageManager.remove(1);
StorageManager.cleanBackup(1);

This immediately saves the game in the last accessed save slot, whether it's loaded or previously saved on.
If a playthrough has not used saves, the variable defaults to 1 (I'm not sure anything can be done about that), so that is why slot 1 gets immediately auto-deleted with the last 2 lines. They're optional but they make sure saveless playthroughs stay saveless, although the player can still manually save in that slot and then lose progress, so a warning would be needed.
Seems like that would function as you intend.
Seems like that would function as you intend.
I've done a bit of testing and it works like a charm. Thanks a lot for the help, and I do hope this ends up being useful to anyone who finds this.

Original thread: https://forums.rpgmakerweb.com/threads/autosaving-at-specified-points-without-using-plugins.160601/