MZ Starting a new game from script

Hi,
how to start a new game exactly like RMMZ would do using traditional title menu?
I'm using a plugin to replace Scene_Title with a map.

This is the script I'm using currently in a event
JavaScript:
$gameParty._actors = [];
$gameParty._gold = 0;
$gameParty.initAllItems();

$gameSwitches.clear();
$gameVariables.clear();
$gameSelfSwitches.clear();

DataManager.setupNewGame();
this._commandWindow.close();
this.fadeOutAll();
SceneManager.goto(Scene_Map);

However it doesn't work with Dot Move System plugin enabled (Cannot read property 'massCharacters' of undefined), and with it disabled, it puts the player into airship at start, even if player isn't in an airship on title screen.
Someone else experienced an oddity like this with DotMoveSystem when trying to load a save:
The solution in their case was to add a couple of lines to the end of the script call:
Maybe try adding these lines to the script call, immediately after $gameSystem.onAfterLoad()?
JavaScript:
  $gameTemp.initCharacterTempDatas();
  $gameMap.initMapCharactersCache();
Also, in your case I don't think any of the stuff before DataManager.setupNewGame() is needed, since setupNewGame recreates all the $game objects anyway? So maybe this would work for you: [Edit: see my follow-up post for a correction!]
JavaScript:
// New game.
DataManager.setupNewGame();
this._commandWindow.close();
this.fadeOutAll();
SceneManager.goto(Scene_Map);
// DotMoveSystem compatibility.
$gameTemp.initCharacterTempDatas();
$gameMap.initMapCharactersCache();
If that doesn't work, you could try removing the this._commandWindow.close(); line. (The standard map scene doesn't have a command window, and you say this is running from an event.)

I don't know why it would put you in the airship vehicle, though. Like I said, new game should recreate all game objects, but maybe calling it from the map scene results in conflicts with the remainder of the map's processing for that frame. 😅

Note that issues can arise due to combinations of plugins, and sometimes their load order. E.g. the error might ostensibly be from DotMoveSystem, but it might not happen unless you're also using that title map plugin. That's why we generally recommend people share screenshots of their Plugin Manager for plugin issues, and try to reproduce the problem in as simple an environment as possible (e.g. all irrelevant plugins turned off).
Someone else experienced an oddity like this with DotMoveSystem when trying to load a save:
The solution in their case was to add a couple of lines to the end of the script call:

Also, in your case I don't think any of the stuff before DataManager.setupNewGame() is needed, since setupNewGame recreates all the $game objects anyway? So maybe this would work for you:
JavaScript:
// New game.
DataManager.setupNewGame();
this._commandWindow.close();
this.fadeOutAll();
SceneManager.goto(Scene_Map);
// DotMoveSystem compatibility.
$gameTemp.initCharacterTempDatas();
$gameMap.initMapCharactersCache();
If that doesn't work, you could try removing the this._commandWindow.close(); line. (The standard map scene doesn't have a command window, and you say this is running from an event.)

I don't know why it would put you in the airship vehicle, though. Like I said, new game should recreate all game objects, but maybe calling it from the map scene results in conflicts with the remainder of the map's processing for that frame. 😅

Note that issues can arise due to combinations of plugins, and sometimes their load order. E.g. the error might ostensibly be from DotMoveSystem, but it might not happen unless you're also using that title map plugin. That's why we generally recommend people share screenshots of their Plugin Manager for plugin issues, and try to reproduce the problem in as simple an environment as possible (e.g. all irrelevant plugins turned off).

After a bit of troubleshooting (thanks for pointing into right direction, thought I wasn't doing something to properly start a new game), for some reason, putting either this._commandWindow.close(); or this.fadeOutAll(); into script, causes player to start in an airship, and throw a error into console about neither of them being a function in Game_Interpreter.
I don't know why that happens, maybe interpreter stops working, causing player not to transfer correctly to Scene_Map.
Oh! Yes, I overlooked the fact that since you're using this in a Script command, it's a different context (i.e. a different this) from the original source for those lines (a scene method).

Try this instead?
JavaScript:
// New game.
DataManager.setupNewGame();
SceneManager._scene.fadeOutAll();
SceneManager.goto(Scene_Map);
// DotMoveSystem compatibility.
$gameTemp.initCharacterTempDatas();
$gameMap.initMapCharactersCache();
I think the new game map will just immediately show rather than fading, because that's normally a "previous scene" check. [Edit: ...but that doesn't matter because new game doesn't normally fade in. 😴] There may be other mechanical/visual glitches too, since normally a new game always involves going from the title scene to the map, rather than map to map.
Oh! Yes, I overlooked the fact that since you're using this in a Script command, it's a different context (i.e. a different this) from the original source for those lines (a scene method).

Try this instead?
JavaScript:
// New game.
DataManager.setupNewGame();
SceneManager._scene.fadeOutAll();
SceneManager.goto(Scene_Map);
// DotMoveSystem compatibility.
$gameTemp.initCharacterTempDatas();
$gameMap.initMapCharactersCache();
I think the new game map will just immediately show rather than fading, because that's normally a "previous scene" check. [Edit: ...but that doesn't matter because new game doesn't normally fade in. 😴] There may be other mechanical/visual glitches too, since normally a new game always involves going from the title scene to the map, rather than map to map.
Sorry for the late reply, didn't work on my project for a while. This script works perfectly, and player doesn't start in an airship anymore.
Great! Happy RPG Making~ 😂

Original thread: https://forums.rpgmakerweb.com/threads/starting-a-new-game-from-script.175814/