Three super-useful new plugins for RPG Maker MZ! (All free)

Hi everyone,

I'm new to the forum and will try to make my case as briefly as possible.

As part of learning to code in Javascript I recently started creating plugins for RPG Maker MZ that I thought would be useful to game developers (thereby combining my love of coding with my love for gaming). So far I have created three major plugins, published under my "stage name" CocoMode:
  1. Enemy Levels - A plugin which enables game developers to implement a leveling system for enemies, which can be simple, complex, or anything in between, depending on the developer's preferences, and includes various features for maximum customization.

    pic1.png


    You can find the plugin + a more detailed description of its many features here on itch.io or here on gumroad.

  2. Customized Dynamically Generated Chest Loot - A plugin which enables game developers to set various conditions in order to dynamically generate loot (type & amount) found in treasure chests throughout the game. Again, the plugin's features allow for maximum customization, and the level of customization "depth" depends on the developer's preferences. The plugin is compatible with my "Enemy Levels" plugin (meaning you can incorporate "leveled" enemy parameters to determine the loot found in treasure chests "guarded" by enemy troops).

    pic1.png


    You can find the plugin + a more detailed description of its many features here on itch.io or here on gumroad.

  3. Revealed Area Map - A plugin which dynamically generates an "area map" for every game map visited by the player. The map shows only the areas already discovered by the player (while others are disguised under "fog-of-war"), and includes many "quality-of-life" features such as the ability to customize (by developer) and place (by developer or player) markers on the map, distribution of fast-travel waypoints throughout the map, creation of game elements (such as "map fragments", etc.) which "reveal" parts of the map not yet directly discovered by the player, and more.

    revealedAreaMap1.png


    You can find the plugin + a more detailed description of its many features here on itch.io or here on gumroad.
All plugins are Free. If you find that you can donate a few dollars to support my work on these plugins and future ones it would be very much appreciated, but it is NOT obligatory.

Any constructive feedback is more than welcome, including problems to be fixed or requests for additional features. Also, it would be nice to hear what you think of the plugins in general, and how useful you find them.

enjoy!

CocoMode
-----------------
31/3/2025 - Fixed a bug in the "Revealed Area Map" plugin which caused the plugin to crash if the user did not define parameters for "map fragments" (which are optional).
-----------------
2/5/2025 - I just finished a complete overhaul of the code for all three plugins, fixing some minor bugs but mainly making the plugins work faster and take less of a toll on system resources. The optimized versions are now available for download.
Oh, I like the treasure chest one, and fairly more sophisticated than mine which tbh I could never get to work.
Spoiler: my old code
JavaScript:
/*:
 * @target MZ
 * @plugindesc A dynamic treasure generation system with rarity, gold generation, and respawn features. Inspired by NWN loot system module.
 * @author Dark_Ansem
 *
 * @param TreasureData
 * @type struct<TreasureContainer>[]
 * @default []
 * @desc Define the treasure containers with loot based on rarity.
 *
 * @param RespawnDelay
 * @type number
 * @default 300
 * @desc Default respawn delay in seconds for containers.
 */

/*~struct~TreasureContainer:
 * @param Tag
 * @type string
 * @desc The tag identifying this container.
 *
 * @param Common
 * @type item[]
 * @default []
 * @desc Items for common loot.
 *
 * @param Rare
 * @type item[]
 * @default []
 * @desc Items for rare loot.
 *
 * @param Exceptional
 * @type item[]
 * @default []
 * @desc Items for exceptional loot.
 */

(() => {
    const pluginName = "TreasureSystem";
    const params = PluginManager.parameters(pluginName);
    const treasureData = JSON.parse(params["TreasureData"] || "[]").map(container => ({
        ...container,
        Common: container.Common ? JSON.parse(container.Common) : [],
        Rare: container.Rare ? JSON.parse(container.Rare) : [],
        Exceptional: container.Exceptional ? JSON.parse(container.Exceptional) : []
    }));
    const defaultRespawnDelay = parseInt(params["RespawnDelay"], 10) || 300;

    // Utility function for rolling dice
    const rollDice = (sides) => Math.floor(Math.random() * sides) + 1;

    // Fetch treasure based on tag and rarity
    const getTreasure = (containerTag, rarity) => {
        try {
            const container = treasureData.find(c => c.Tag === containerTag);
            if (!container) {
                console.error(`Treasure container "${containerTag}" not found.`);
                return null;
            }

            const items = container[rarity];
            if (!items || items.length === 0) {
                console.warn(`No items found for rarity "${rarity}" in container "${containerTag}".`);
                return null;
            }

            return items[Math.floor(Math.random() * items.length)];
        } catch (e) {
            console.error(`Error fetching treasure for tag "${containerTag}" and rarity "${rarity}": ${e.message}`);
            return null;
        }
    };

    // Respawn containers with RPG Maker timing system
    Game_Map.prototype.respawnContainer = function(eventId, mapId, eventData, delay = defaultRespawnDelay) {
        const timer = setTimeout(() => {
            if ($gameMap.mapId() === mapId) {
                this.addEventAtLocation(eventData, eventId);
            }
        }, delay * 1000);

        // Store timer reference for cleanup
        this._respawnTimers = this._respawnTimers || new Map();
        this._respawnTimers.set(eventId, timer);
    };

    // Add event at a specific location
    Game_Map.prototype.addEventAtLocation = function(eventData, eventId) {
        const { x, y } = eventData;
        $dataMap.events[eventId] = eventData;
        const newEvent = new Game_Event($gameMap.mapId(), eventId);
        $gameMap._events[eventId] = newEvent;
        $gameMap.refreshTileEvents();
        $gamePlayer.refresh();
    };

    // Clear all respawn timers
    Game_Map.prototype.clearRespawnTimers = function() {
        if (this._respawnTimers) {
            for (const [eventId, timer] of this._respawnTimers) {
                clearTimeout(timer);
            }
            this._respawnTimers.clear();
        }
    };

    // Cleanup during map transitions
    const alias_Game_Map_terminate = Game_Map.prototype.terminate;
    Game_Map.prototype.terminate = function() {
        this.clearRespawnTimers();
        alias_Game_Map_terminate.call(this);
    };

    // Extend event functionality for treasure logic
    Game_Event.prototype.onOpen = function() {
        if (this.getSelfSwitch("Used")) return;

        this.setSelfSwitch("Used", true);
        const player = $gameParty.members()[0];
        const chestGold = parseFloat(this.event().meta.GoldMultiplier || 1.0);
        const chestTag = this.event().meta.TreasureTag || "Default";

        // Generate Gold
        const goldAmount = Math.floor(player.level * rollDice(20) * chestGold);
        $gameParty.gainGold(goldAmount);
        $gameMessage.add(`You found ${goldAmount} gold!`);

        // Generate Treasure
        const rollNumber = rollDice(20);
        this.makeTreasure(chestTag, "Common");
        if (rollNumber >= 12) this.makeTreasure(chestTag, "Rare");
        if (rollNumber >= 18) this.makeTreasure(chestTag, "Exceptional");
    };

    Game_Event.prototype.makeTreasure = function(containerTag, rarity) {
        const treasure = getTreasure(containerTag, rarity);
        if (treasure) {
            $gameParty.gainItem($dataItems[parseInt(treasure)], 1);
            $gameMessage.add(`You found a ${rarity} item!`);
        }
    };

    Game_Event.prototype.onClose = function() {
        const respawnDelay = parseInt(this.event().meta.RespawnDelay || defaultRespawnDelay, 10);
        this.clearInventory();
        this.respawnContainer(respawnDelay);
    };

    Game_Event.prototype.clearInventory = function() {
        console.log("Inventory cleared.");
    };

    Game_Event.prototype.getSelfSwitch = function(switchKey) {
        return $gameSelfSwitches.value([$gameMap.mapId(), this.eventId(), switchKey]);
    };

    Game_Event.prototype.setSelfSwitch = function(switchKey, value) {
        $gameSelfSwitches.setValue([$gameMap.mapId(), this.eventId(), switchKey], value);
    };

    // Event triggers
    const alias_Game_Event_start = Game_Event.prototype.start;
    Game_Event.prototype.start = function() {
        if (this.event().meta.TreasureTag) {
            this.onOpen();
        } else {
            alias_Game_Event_start.call(this);
        }
    };

    const alias_Game_Event_erase = Game_Event.prototype.erase;
    Game_Event.prototype.erase = function() {
        if (this.event().meta.TreasureTag) {
            this.onClose();
        } else {
            alias_Game_Event_erase.call(this);
        }
    };
})();

The fog of war one is also a nice touch, to avoid everything being revealed at once
Hi @CocoMode -- I get the following error with the enemy levels plugin: "this[_0x112404(...)] is not a function" upon boot. Any ideas what might help with this? I'm using code base 1.9.0 if that helps.

Original thread: https://forums.rpgmakerweb.com/threads/three-super-useful-new-plugins-for-rpg-maker-mz-all-free.175176/