MOG_VariableHud.js extension

bvlgari

Villager
Member
Joined
Jan 14, 2018
Messages
29
Reaction score
4
First Language
english
Primarily Uses
RMMV
This plugin offers a pretty easy way of setting up variable huds in the game. By default, in the plugin parameters the dev can set the maximum value of variables, up to 20 vars. Besides that, there is a plugin command that allows to change in game, the maximum value of a certain variable.
Code:
set_variable_max : VARIABLE_ID : MAX_VALUE
The MAX_VALUE section only allows determined numbers.

What i would like to ask, if someone could give me a hand, is how to adapt this plugin command to use a Variable ( a different one) to set the maximum value of certain variable, not using determined numbers.

Code:
set_variable_max : VARIABLE_ID : \v[n]
Something like this.
This should give more flexibility to the plugin since the maximum values could be now set from external inflows of the game and be random numbers/ unlimited.

I know this is very specific, but im asking anyways.
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
147
Reaction score
166
First Language
Danish
Primarily Uses
RMMV
I wrote you a plugin for this. Just remember to put it after the MOG_Variablehud plugin.
I have only tested it with th MOG_Variablehud plugin.
It should be noted that I have changed the Game_Variables change listener, so every time a variable is changed it updates the max values of the variable hud.

Code:
//=============================================================================
// VariableHud_VariableMax.js
//=============================================================================

/*:
 * @plugindesc MOG_VariableHud extension. This plugin adds the possibilty to use a variable as the max
 * value of a variable hud.
 * @author Magnus0808
 *
 * @help You can now use \v[x] to use variable x as a value.
 * E.g set_variable_max : 1 : \v[12]
 */
(function() {
    
    for (var i = 0; i < Moghunter.variableHud_Max; i++) {
        Moghunter.variableHud_ValueLimit[i] = String(Moghunter.parameters['Hud ' + String(i + 1) + ' Maximum Value'] || 999);
    };   
    
    
    Scene_Map.prototype.createVariableHuds = function() {
        this._variableHud = [];
        for (var i = 0; i < Moghunter.variableHud_Max; i++) {
            if (!$gameSystem._variableHudData[i]) {
                 $gameSystem._variableHudData[i] = {}
                 var vis = String(Moghunter.variableHud_VisibleInt[i]) === "true" ? true : false;
                 $gameSystem._variableHudData[i].id = i;
                 $gameSystem._variableHudData[i].visible = vis;
                 $gameSystem._variableHudData[i].maxValue = this.getMaxValue(i);             
                 $gameSystem._variableHudData[i].showMax = String(Moghunter.variableHud_ShowMax[i]) == "true" ? true : false;             
                 $gameSystem._variableHudData[i].gauge = String(Moghunter.variableHud_ShowGauge[i]) == "true" ? true : false;
                 $gameSystem._variableHudData[i].gaugeX = Number(Moghunter.variableHud_gaugeX[i]);
                 $gameSystem._variableHudData[i].gaugeY = Number(Moghunter.variableHud_gaugeY[i]);
                 $gameSystem._variableHudData[i].autoFade = String(Moghunter.variableHud_AutoFade[i]) == "true" ? true : false;
            };
            this._variableHud[i] = new VariableHud(i);
            this._variableHud[i].mz = 120;
            this._hudField.addChild(this._variableHud[i]);           
        };
    };
    
    Scene_Map.prototype.updateMaxValues = function() {
        for (var i = 0; i < Moghunter.variableHud_Max; i++) {
            $gameSystem._variableHudData[i].maxValue = this.getMaxValue(i);
        }
    }
    
    Scene_Map.prototype.getMaxValue = function(i) {
        var maxString = Moghunter.variableHud_ValueLimit[i];   
        var regex = /\\v\[(\d*)\]/
        var match = regex.exec(maxString);
        
        if(match) {
            return $gameVariables.value(Number(match[1]));
        } else {
            return Number(maxString);
        }   
    }
    
    var _mog_variableHud_pluginCommand = Game_Interpreter.prototype.pluginCommand
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _mog_variableHud_pluginCommand.call(this,command, args)
        if (command === "hide_variable_hud") {
            var varID = Number(args[1]) - 1;
            if ($gameSystem._variableHudData[varID]) {
                $gameSystem._variableHudData[varID].visible = false;
            };
        } else if (command === "show_variable_hud") {
            var varID = Number(args[1]) - 1;
            if ($gameSystem._variableHudData[varID]) {
                 $gameSystem._variableHudData[varID].visible = true;
            };       
        };
        if (command === "set_variable_max")  {
            var id = Number(args[1]);
            var maxvalue = args[3] != null ? String(args[3]) : "0";       
            for (var i = 0; i < Moghunter.variableHud_Max; i++) {
                var vid = Moghunter.variableHud_VariableID[i];
                if ($gameSystem._variableHudData[i] && vid === id) {
                    Moghunter.variableHud_ValueLimit[i] = maxvalue;
                    $gameSystem._variableHudData[i].maxValue = Scene_Map.prototype.getMaxValue(i);
                };
            };
        };
        return true;
    };
    
    Game_Variables.prototype.onChange = function() {
        $gameMap.requestRefresh();
        Scene_Map.prototype.updateMaxValues();
    };

})();
 

Attachments

bvlgari

Villager
Member
Joined
Jan 14, 2018
Messages
29
Reaction score
4
First Language
english
Primarily Uses
RMMV
Wow, I really had lost hope in this request! This will give a lot more of depth in the use of this plugin. Thanks dude, tested and works awesome!
Credits by your username?.
Cheers!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

On my journey of character rework: I had this character, she was meant to be just a princess that joins your party. And at long term she was just uninteresting... So I tweaked her to be a rebel agaisn't the royalty before meeting up with the party.

Quick tip for any other ametuer pixel artists! When trying to create a colour palette, enabling Antialiasing can speed up the process of creating different shades! Just place your lightest colour and your darkest colour next to each other, select both pixels, and stretch it out!
Revolutionizing the JRPG Industry: Knocking on Doors.

Take that, murderhobos.
Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.

Forum statistics

Threads
106,054
Messages
1,018,580
Members
137,843
Latest member
Betwixt000
Top