RPGM DynamicMenu Plugin - Proof of Concept [WIP]

J0571N

New Member
Feb 13, 2020
1
0
Hey everyone!

I wanted to share a work-in-progress (WIP) plugin I've been tinkering with for RPG Maker MZ. Please note that this is not a finished product, and I'm far from being an expert, but I thought it might be helpful or interesting for others.

DynamicMenu Plugin Overview:
Description: The DynamicMenu plugin provides a plugin command to dynamically generate and display choices based on a game data within RPG Maker MZ.

Features:

  • Generates and displays choices for actors, items, skills, etc., using the provided plugin command.
  • Allows for storing the selected item index and an array of item names in variables.
Known Issues:

  • Selecting 'Back' in some menus does not correctly return to the last menu.

  • In certain menus, the "Back" option might be missing.

  • Handling of Player vs. Other Actor Events: The RPG Maker MZ engine handles player and other actor events (NPCs, monsters, etc.) differently. While the player character shares some similarities with other events, there are notable distinctions in how they are managed within the engine's context.
    • Player-Centric Functions: Certain functions and functionalities within the engine are designed specifically for the player actor, causing limitations when applied to other events.
    • Contextual Differences: The distinction between the player and other events creates challenges in utilizing code that is tailored solely for the player, making it incompatible or non-functional for other events.
    • Code Limitations: Many functions or operations are exclusively available and functional within the context of the player actor, restricting their use or applicability to other in-game events.
      Note: As a consequence, some functionalities within the DynamicMenu plugin may primarily cater to the player character due to these inherent engine limitations.
Sample Code:
### Core Function: `showChoices`

The `showChoices` function is a pivotal part of the plugin's functionality. It is responsible for dynamically generating a list of choices based on the provided item list, allowing players to select from a range of in-game options such as actors, items, or skills.

**Functionality Overview:**
- **Displays Choices:** Utilizes the provided item list to generate a list of selectable options.
- **Handles Selections:** Enables players to choose an item, and in the case of the 'Back' option, allows navigation to the previous menu or exit.
- **Variable Management:** Stores selected item details and choices in designated variables for further processing within the game.

JavaScript:
/**
* Function to display choices and return the selected item based on actual game data.
* @param {any[]} itemList - The list of items.
* @param {number} selectedVariableId - The selected variable ID.
* @param {number} choicesVariableId - The choices variable ID.
* @returns {Promise<{id: number, name: string}>} - The selected item's ID and name.
*/
async function showChoices(itemList, selectedVariableId, choicesVariableId, lastChoice) {
    let itemNames = itemList.map(item => item ? item.name : '').filter(Boolean);

    // Add 'Back' option to the choices
    itemNames.push(lastChoice);

    $gameVariables.setValue(choicesVariableId, itemNames);
    console.log('Generated Choices:', itemNames);

    $gameMessage.setChoices(itemNames, 0, -1);

    return new Promise(resolve => {
        $gameMessage.setChoiceCallback(index => {
            const selectedChoiceIndex = index + 1;
            if (selectedChoiceIndex === itemNames.length) {
                // If 'Back' is selected, resolve with null or a specific value representing 'Back'
                resolve({ id: -1, name: 'Back' });
                return;
            }

            const selectedItemIndex = itemList.findIndex(item => item && item.name === itemNames[selectedChoiceIndex - 1]);
            if (selectedItemIndex !== -1) {
                const selection = itemList[selectedItemIndex];
                console.log('Selected Item:', selection.name);
                console.log('Selected Item ID:', selection.id);
                const id = selection.id;
                const name = selection.name;
                $gameVariables.setValue(selectedVariableId, selection);

                console.log('Saved selection', $gameVariables.value(selectedVariableId));

                resolve({ id, name });
            }
        });
    });
}

Download Link:
75 mb compressed/ 255 mb uncompressed.


Purpose and Clarifications:
I'd like to emphasize a few points:

  1. Work in Progress: This plugin is a proof of concept and is not a finalized version. There might be other ways to achieve similar functionality, perhaps simpler or even more complex. I'm open to feedback and suggestions.
  2. Learning Process: I'm not an expert in plugin development. This project is part of my learning journey with RPG Maker MZ, and I'm sharing it to learn and possibly help others who might be exploring similar functionalities.
  3. Potential Improvements: There's room for improvement and optimization within the code. It's a starting point, and I'm looking to refine it further.

Conclusion:
I'm excited about the progress so far, and I'm eager to continue working on this plugin. I'd appreciate any constructive feedback or suggestions to enhance this concept further.

Feel free to test it out and share your thoughts!