MOG_VariableHud.js extension

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.
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();
    };

})();
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!

Original thread: https://forums.rpgmakerweb.com/threads/mog_variablehud-js-extension.105318/