Seedable PRNG – Persisting your World

This plugin series does not persist generated maps. Instead, it uses a seedable PRNG. Every time you pass the same seed value to a command to generate a map, the same map is generated again. We will use Game Variables to keep track of our seed value(s).

Why aren’t there any functions to persist maps? I decided not to because any built-in function to save and regenerate maps will be limited at some point. In contrast, we have so much more control when using Variables, and they are safely stored and managed by our Save Games.

As you can manage your seed value(s) using the standard RPG Maker Eventing, you can easily decide how the randomization will influence your world and, therefore, the gameplay. Do you want a simple dungeon crawler that randomizes only once on startup? Or every time you start a new mission? Or do you want to have a universe with randomized planets that own randomized fields and caves, too? It’s up to you!

This plugin uses an isolated PRNG. Using the random function inside the Variable Management of the RPG Maker or any other invocation of Math.random will not interfere with it.

Generate and Pass a Seed Value

This plugin provides a small convenient function to generate a seed by passing a list of variables. In this example, the player has landed on a planet/world map and is now entering a cave. We are using…

  • a global seed variable that is randomly set on „New Game“
  • a variable that keeps track of the planet the player is
  • 1 variable for X and Y coordinate respectively of the player’s position on the world map

This way, we can have more than one cave entry, each leading to an individual-looking dungeon.

MZ only: Plugin Commands

The resulting seed value is inserted into a new Variable; in this example, it’s Variable No 5.

MV & MZ: JavaScript Call

const seed = MK.generateSeed(
    $gameVariables.value(1), // global Seed
    $gameVariables.value(2), // planet / worldmap Id
    $gameVariables.value(3), // X-coordinate
    $gameVariables.value(4)  // Y-coordinate
)
MK.rng.setSeed(seed)

In JavaScript, the machine does not consider anything that is right from a //-symbol and, hence, does not use it to add comments.

With some knowledge in RPG Maker, you can replace $gameVariables.value(…) with any number or function call if you need to.

If you want to save the seed in a Variable, do:

const seed = MK.generateSeed(
    $gameVariables.value(1),
    $gameVariables.value(2),
    $gameVariables.value(3),
    $gameVariables.value(4)
)
MK.rng.setSeed(seed)
$gameVariables.setValue(5, seed)  // <-- replace 5 with your Variable Id

The Meta Maze

The Meta Maze is an excellent feature for creating more complicated dungeons. It is not a map generator; instead, it assists you by creating connected, randomly generated rooms. Technically, it auto-generates seed values for you and keeps track of the player’s position, which makes it possible for the player to go back to an already visited room, and it will retain its layout.

Self Switches

Self Switches are saved and managed when you use the Meta Maze. When you want to switch off Self Switches, you can do so (see: Self-Switches).