MV Progression Functionality for Roguelike Game

Hi everyone,

I am developing a Roguelike game in RPG Maker MV. I know how I would handle what I need with events but I am interested in trying to figure out how to do it with script calls as I think it may be a lot easier/cleaner in the long run. Here's the situation and what I'm interested in learning to do. Maybe you can give me a starting point to work from, or point me towards some resources to learn to do it myself?

In the game you go on adventures that are a series of dungeons. The dungeon you start on is randomly selected from a small pool of 3 dungeons. You can return to town between rooms of the dungeons to shop, and I have found a way to track where you are in which dungeon using variables so it can send you back to the right room when you're down.

However, once you complete a dungeon you also go to town and are then sent to another of the 3 dungeons. I know I could use a series of conditional branches to determine which dungeon the player has already been to and send them to a random of the other two, and then the last one, but I'm wondering if there would be a better way to do this using scripting. Something that would check for which dungeons have been completed and send the player to a random selection of the remaining pool.

I figure with a script, I could more easily scale this number of dungeons up from 3 once we're out of the demo phase. I also figure this is probably simple enough for me to be able to really follow the code or even write it myself with some guidance.

Thanks for your time!
-Cyrus
I would say the easiest approach for this would be to store your dungeons in an array.
Then, based on the randomly selected dungeon, remove that one by its ID from the array, and have it select any other available dungeon left.

Using javascript, something like :

Part 1 : Set up the logic (The part you want to run before your dungeon run, to select random ID)
JavaScript:
var allDungeons = [1, 2, 3]; //Store as many as you need
var completed = $gameVariables.value(1) || []; //Will store the completed dungeons by ID (replace id 1 with what you need)
var remaining = allDungeons.filter(function(id) {
    return !completed.includes(id); // This will add all id's from allDungeons to the list, except the ones present in completed
});

if (remaining.length > 0) { //If remaining has any entry left
    var nextDungeon = remaining[Math.floor(Math.random() * remaining.length)]; // Chose randomly amongst available id's
    $gameVariables.setValue(2, nextDungeon); // Store the chosen dungeon ID in game variable 2 (replace id 2 with what you need)
} else { //If no entries remain
    $gameMessage.add("You've completed all dungeons!"); //This is just for showing a message, replace with whatever you want to  happen
}

Part 2 : Process the dungeons (The part you want to run after every dungeon is finished)
JavaScript:
var completed = $gameVariables.value(1); //Again, the same variable as previous script
var dungeonID = $gameVariables.value(2); //Same here, use the same ID as in the previous script
if (!completed.includes(dungeonID)) completed.push(dungeonID); //This will add current dungeon to the array
$gameVariables.setValue(1, completed); //Updates the "completed" variable


This code is not tested or anything, but should give you an idea of what's possible (correct me if I'm wrong though 😀 )
I would say the easiest approach for this would be to store your dungeons in an array.
Then, based on the randomly selected dungeon, remove that one by its ID from the array, and have it select any other available dungeon left.

Using javascript, something like :

Part 1 : Set up the logic (The part you want to run before your dungeon run, to select random ID)
JavaScript:
var allDungeons = [1, 2, 3]; //Store as many as you need
var completed = $gameVariables.value(1) || []; //Will store the completed dungeons by ID (replace id 1 with what you need)
var remaining = allDungeons.filter(function(id) {
    return !completed.includes(id); // This will add all id's from allDungeons to the list, except the ones present in completed
});

if (remaining.length > 0) { //If remaining has any entry left
    var nextDungeon = remaining[Math.floor(Math.random() * remaining.length)]; // Chose randomly amongst available id's
    $gameVariables.setValue(2, nextDungeon); // Store the chosen dungeon ID in game variable 2 (replace id 2 with what you need)
} else { //If no entries remain
    $gameMessage.add("You've completed all dungeons!"); //This is just for showing a message, replace with whatever you want to  happen
}

Part 2 : Process the dungeons (The part you want to run after every dungeon is finished)
JavaScript:
var completed = $gameVariables.value(1); //Again, the same variable as previous script
var dungeonID = $gameVariables.value(2); //Same here, use the same ID as in the previous script
if (!completed.includes(dungeonID)) completed.push(dungeonID); //This will add current dungeon to the array
$gameVariables.setValue(1, completed); //Updates the "completed" variable


This code is not tested or anything, but should give you an idea of what's possible (correct me if I'm wrong though 😀 )
This is awesome! Pretty sure I'm following how it works (thank you for all the notes!). Gonna give it a try later.
This code is not tested or anything, but should give you an idea of what's possible (correct me if I'm wrong though 😀 )
I might gonna mess with is too, but is the part one runs once or everytime? and part 2 every each map?
as I could use this kind as well 🙂
This is awesome! Pretty sure I'm following how it works (thank you for all the notes!). Gonna give it a try later.
Feel free to let me know the outcome. 🙂

I might gonna mess with is too, but is the part one runs once or everytime? and part 2 every each map?
as I could use this kind as well 🙂
Part 1 is used when you want to select the random ID of the dungeon you want the player to play.
It should theoretically select a random ID amongst any available ones, since it substract the completed ones from the dungeon id list and adds them to "remaining". Then it just selects a random ID from the array and updates gameVariable 2 (Dungeon ID)

Part 2 is used after the dungeon is finished, it simply updates gameVariable 1 (Completed Dungeons) by adding current dungeon to the list.


There are several ways to structure it I believe, but I would say it should be pretty modular and easy to event however you like ^^
There are several ways to structure it I believe, but I would say it should be pretty modular and easy to event however you like ^^
in my case, I need to use the MapId's so it is used for randomizing 10 maps out of x maps (20~50).
every 5 maps a savepoint.

so I need to alter it anyway, as if it is to initilize it on part 1 (like on boot or first level, than change it on the other map).
but I need to add switches as well, so it can be ignored, else initilize a new group.

I might use a param struct if that is possible else a pre-made list and make it automatically with a simple scriptcall
to control it similar like:

JavaScript:
    function initDungeons(complete, remain, ...dungeons) {
        var allDungeons = dungeons; //[1, 2, 3]; //Store as many as you need
        var completed = $gameVariables.value(complete) || []; //Will store the completed dungeons by ID (replace id 1 with what you need)
        var remaining = allDungeons.filter(function(id) {
            return !completed.includes(id); // This will add all id's from allDungeons to the list, except the ones present in completed
        });

        if (remaining.length > 0) { //If remaining has any entry left
            var nextDungeon = remaining[Math.floor(Math.random() * remaining.length)]; // Chose randomly amongst available id's
            $gameVariables.setValue(remain, nextDungeon); // Store the chosen dungeon ID in game variable 2 (replace id 2 with what you need)
        } else { //If no entries remain
            $gameMessage.add("You've completed all dungeons!"); //This is just for showing a message, replace with whatever you want to  happen
        }
    };


    function checkDungeon(complete, remain) {
        var completed = $gameVariables.value(complete); //Again, the same variable as previous script
        var dungeonID = $gameVariables.value(remain); //Same here, use the same ID as in the previous script
        if (!completed.includes(dungeonID)) completed.push(dungeonID); //This will add current dungeon to the array
        $gameVariables.setValue(complete, completed); //Updates the "completed" variable
    };

so it would be easier as a plugin, quick call, easy change values, without worries on typo's 🙂
in my case, I need to use the MapId's so it is used for randomizing 10 maps out of x maps (20~50).
every 5 maps a savepoint.

so I need to alter it anyway, as if it is to initilize it on part 1 (like on boot or first level, than change it on the other map).
but I need to add switches as well, so it can be ignored, else initilize a new group.

I might use a param struct if that is possible else a pre-made list and make it automatically with a simple scriptcall
to control it similar like:

JavaScript:
    function initDungeons(complete, remain, ...dungeons) {
        var allDungeons = dungeons; //[1, 2, 3]; //Store as many as you need
        var completed = $gameVariables.value(complete) || []; //Will store the completed dungeons by ID (replace id 1 with what you need)
        var remaining = allDungeons.filter(function(id) {
            return !completed.includes(id); // This will add all id's from allDungeons to the list, except the ones present in completed
        });

        if (remaining.length > 0) { //If remaining has any entry left
            var nextDungeon = remaining[Math.floor(Math.random() * remaining.length)]; // Chose randomly amongst available id's
            $gameVariables.setValue(remain, nextDungeon); // Store the chosen dungeon ID in game variable 2 (replace id 2 with what you need)
        } else { //If no entries remain
            $gameMessage.add("You've completed all dungeons!"); //This is just for showing a message, replace with whatever you want to  happen
        }
    };


    function checkDungeon(complete, remain) {
        var completed = $gameVariables.value(complete); //Again, the same variable as previous script
        var dungeonID = $gameVariables.value(remain); //Same here, use the same ID as in the previous script
        if (!completed.includes(dungeonID)) completed.push(dungeonID); //This will add current dungeon to the array
        $gameVariables.setValue(complete, completed); //Updates the "completed" variable
    };

so it would be easier as a plugin, quick call, easy change values, without worries on typo's 🙂
Totally, making it functionnal instead of procedural is a big improvement ^^
Making it easier to call and use, and scaling it to multiple sets of different dungeons (you could have dungeons within dungeons for example)

I'm just used to think procedural as its a more "human" approach ^^
There is also a wide variety of possible usage using this technique. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/progression-functionality-for-roguelike-game.176678/