SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
Update 1.00 was released. Goto here from now on
 

Old stuff:

Stamina Plugin
Author: Silver

Features:
- Disables dashing on the map when you run out of stamina.
- Has a stamina threshold so you don't automatically start dashing again at 1 stamina.
- Comes with an optional stamina bar with an optional percentage value in it.
- Can optionally automatically hide the stamina window.
- The bar changes color depending on the stamina value (NOT a gradient!).
- Does not consume stamina when the player can not walk (example: attempts to dash into a wall).
- Optional: slide the stamina window in/out instead of just hiding it.
- Optional: make the stamina's window invisible but not the stamina bar (use opacity parameter).
- Optional allow the stamina regen to increase in speed the longer you let it consecutively regenerate using a custom function in a parameter.
- Disable stamina consumption on specific maps (like overworlds) by using a map notetag.
- Disable stamina consumption by using a gameswitch.
- Increase/decrease max stamina.
- Optionally show the value, percentage, both or none of the current stamina in the stamina bar.
- Optional Window can slide in/out.
- Max stamina can be manually set in case you'd like to control the max stamina yourself.
- Window can be made invisible so you only see the stamina bar (use opacity parameter).
- You control how the stamina regenerates with a custom parameter-equation.


Planned features (no promises):
- Maybe some day allow player stats like the highest/lowest/average agility/level of all partymembers to influence the max stamina.
- "Perhaps make the stamina bar green when you can dash again so it makes it clear.". I will look into that, maybe make it flash once. Not sure how to best inform the player about this yet.

Known bugs:
- none

Screenshot:
stm bar.png


Script:

 
Code:
//=============================================================================// SilvStamina.js// Version: 1.0//=============================================================================/*: * @plugindesc v1.00 Basic dashing stamina script.   <SilverStamina> * @author Silver * * @param Show Stamina Window * @desc true/false * @default true * * @param Window X * @desc X-location of stamina window. If window-alignment is set to Right, this will act as an offset value instead * @default 10 * * @param Window Y * @desc Y-location of stamina window. If window-alignment is set to Top, this will act as an offset value instead * @default 10 * * @param Window Width * @desc width of the stamina window * @default 170 * * @param Window Height * @desc height of the stamina window * @default 72 * * @param Window Horizontal Alignment * @desc Left/Right * @default Left * * @param Window Vertical Alignment * @desc Top/Bottom * @default Top * * @param Stamina Decrease * @desc Amount of stamina subtracted per update (use a positive number) * @default 1 * * @param Stamina Max * @desc Maximum amount of stamina * @default 300 * * @param Stamina Recovery Delay * @desc delay in update-calls before recovering stamina when not dashing * @default 180 * * @param Stamina Recovery Rate * @desc How fast stamina is recovered (only when recovering) * @default 0.3 * * @param Stamina AutoDash Threshold * @desc Do not automatically dash again before stamina is above this threshold (%) when recovering stamina. (0-100) * @default 40 * * @param Stamina Gauge Rectangle * @desc The gauge rectangle. Format: x y width height * @default 0 -20 132 24 * * @param Stamina Gauge Color 1 * @desc Bar gradient color1 (start of bar) in hex * @default #009900 * * @param Stamina Gauge Color 2 * @desc Bar gradient color2 (end of bar) in hex * @default #CC0000 * * @param Draw Stamina Value * @desc Draw text in stamina bar? Accepted values: absolute/percentage/both/none * @default percentage * * @param Font Size * @desc Size for stamina value * @default 20 * * @param Auto Hide Stamina Window * @desc Automatically hide the stamina window if it's at max stamina for a specific period of time? true/false * @default true * * @param Hide Stamina Window Delay * @desc After how many updates the stamina window should hide itself (if it remains at max stamina) * @default 160 * * @param Stamina Window Opacity * @desc Stamina window opacity. Set to 0 to hide the window (will still show the bar). * @default 255 * * @param Window Slideout Direction * @desc What direction to slide the stamina window out to. NoSlide/Left/Top/Right/Bottom * @default Left * * @param Window Slideout Speed * @desc How fast the window slides in&out * @default 2 * * @param Stamina Regen Formula * @desc The formula for how fast to regenerate stamina over longer period of time. "Base" is the recovery rate. Case sensitive! * @default base + Math.sqrt(x/50); * * @param Disable Stamina Consumption GameSwitch * @desc The gameswitch to use to disable stamina consumption (or -1 to use none). ON = disabled. * @default -1 * * @param Window Z-Index * @desc Window Z-Index. Value must be > 0. * @default 1 * * @param Plugin Command Identifier * @desc Do not change if you do not know what this is! * @default stamina * * @help * ------------------------------------- * Plugin Commands (not case sensitive): * ------------------------------------- * * Stamina Refill * Instantly refills all of your stamina. * * Stamina Set <value> * Instantly sets your stamina to the specified percentage (0-100). * Example to set your stamina bar to 64: Stamina Set 64 * * Stamina Deplete * Instantly sets your stamina to 0. * * Stamina ShowWindow * Shows the stamina window. Does not work if you disabled the stamina window. * * Stamina HideWindow * Hides the stamina window. Does not work if you disabled the stamina window. * Also does not work if the stamina is currently regenerating. * * Stamina RefillHide * Instantly refills all of your stamina and also hides the stamina window. * * Stamina SetMax <value> * Sets a new max-stamina value. * * Stamina IncreaseMax <value> * Increases max stamina by the specified value. You can also use negative values. * ------------------------------------- * Map notetags * ------------------------------------- * * <dstam_disable:> * Prevents stamina consumption on this map. Not that if the "Disable Stamina Consumption GameSwitch" * is turned ON then you consume no stamina anyway. * */var Silv = Silv || {};Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilverStamina>'); })[0].parameters;Silv.DashStamina = Silv.DashStamina || {};Silv.DashStamina.Window = null;Silv.DashStamina.ScreenIsFading = false;Silv.DashStamina.ShowWindow = Silv.Parameters['Show Stamina Window'].toLowerCase() == 'true';Silv.DashStamina.Window_X = parseInt(Silv.Parameters['Window X']);Silv.DashStamina.Window_Y = parseInt(Silv.Parameters['Window Y']);Silv.DashStamina.WindowWidth = parseInt(Silv.Parameters['Window Width']);Silv.DashStamina.WindowHeight = parseInt(Silv.Parameters['Window Height']);Silv.DashStamina.WindowHorizontalAlignment = (Silv.Parameters['Window Horizontal Alignment']).toLowerCase();Silv.DashStamina.WindowVerticalAlignment = (Silv.Parameters['Window Vertical Alignment']).toLowerCase();Silv.DashStamina.StaminaDecrease = parseInt(Silv.Parameters['Stamina Decrease']);Silv.DashStamina.StaminaMax = parseInt(Silv.Parameters['Stamina Max']);Silv.DashStamina.StaminaRecoveryDelay = parseInt(Silv.Parameters['Stamina Recovery Delay']);Silv.DashStamina.StaminaRecoveryRate = parseInt(Silv.Parameters['Stamina Recovery Rate']);Silv.DashStamina.StaminaAutoDashThreshold = parseInt(Silv.Parameters['Stamina AutoDash Threshold']);Silv.DashStamina.StaminaGaugeRectangle = {x: parseInt(Silv.Parameters['Stamina Gauge Rectangle'].split(' ')[0]), y: parseInt(Silv.Parameters['Stamina Gauge Rectangle'].split(' ')[1]), width: parseInt(Silv.Parameters['Stamina Gauge Rectangle'].split(' ')[2]), height: parseInt(Silv.Parameters['Stamina Gauge Rectangle'].split(' ')[3])};Silv.DashStamina.StaminaGaugeColor1 = (Silv.Parameters['Stamina Gauge Color 1']).toUpperCase();Silv.DashStamina.StaminaGaugeColor2 = (Silv.Parameters['Stamina Gauge Color 2']).toUpperCase();Silv.DashStamina.DrawStaminaValue = Silv.Parameters['Draw Stamina Value'].toLowerCase();Silv.DashStamina.FontSize = parseInt(Silv.Parameters['Font Size']);Silv.DashStamina.AutoHideStaminaWindow = Silv.Parameters['Auto Hide Stamina Window'].toLowerCase() == 'true';Silv.DashStamina.HideStaminaWindowDelay = parseInt(Silv.Parameters['Hide Stamina Window Delay']);Silv.DashStamina.WindowOpacity = parseInt(Silv.Parameters['Stamina Window Opacity']);Silv.DashStamina.WindowSlideOutDir = Silv.Parameters['Window Slideout Direction'].toLowerCase();Silv.DashStamina.WindowSlideOutSpeed = parseFloat(Silv.Parameters['Window Slideout Speed']);Silv.DashStamina.RegenFormula = Silv.Parameters['Stamina Regen Formula'];Silv.DashStamina.DisableGameSwitch = parseInt(Silv.Parameters['Disable Stamina Consumption GameSwitch']);Silv.DashStamina.Window_Z = parseInt(Silv.Parameters['Window Z-Index']);Silv.DashStamina.PluginCmdId = Silv.Parameters['Plugin Command Identifier'];// Do not just show the minimap on top of a faded-out screen.var alias_silv_stamina_updateFadeOut = Game_Screen.prototype.updateFadeOut;Game_Screen.prototype.updateFadeOut = function() {    alias_silv_stamina_updateFadeOut.call(this);        if (this._brightness < 255) // (this._fadeOutDuration > 0)    {        Silv.DashStamina.Window.visible = false;        Silv.DashStamina.ScreenIsFading = true;    }    else    {        Silv.DashStamina.ScreenIsFading = false;    }};(function(){//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Utility Functions//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Usage: alert(rgbToHex(0, 51, 255)); // #0033ff  function componentToHex(c) {    var hex = c.toString(16);    return hex.length == 1 ? "0" + hex : hex;  }  function rgbToHex(r, g,  {    return "#" + componentToHex(r) + componentToHex(g) + componentToHex(;  } // Usage: alert( hexToRgb("#0033ff").g ); // "51";function hexToRgb(hex) {    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);    return result ? {        r: parseInt(result[1], 16),        g: parseInt(result[2], 16),        b: parseInt(result[3], 16)    } : null;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Stamina stuff//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Hook into the main loopvar alias_updateMain = Scene_Map.prototype.updateMain;Scene_Map.prototype.updateMain = function(){    alias_updateMain.apply(this, arguments);    Game_Player.prototype.updateStamina();    if (Silv.DashStamina.ShowWindow) { Silv.DashStamina.Window.update(); }}Game_Player.prototype.hasStaminaConsumption = function(){    if ($gameSwitches.value(Silv.DashStamina.DisableGameSwitch)) { return false; }    if (!$gamePlayer.mapConsumeStamina) { return false; }    return true;}// Update stamina amountGame_Player.prototype.updateStamina = function(){        this.isConsumingStamina = ($gamePlayer.isDashing() && $gamePlayer.isMoving() && $gamePlayer.hasStaminaConsumption());    if (this.isConsumingStamina)    {        $gamePlayer.dashStamina -= Silv.DashStamina.StaminaDecrease;        if ($gamePlayer.dashStamina < 0) { $gamePlayer.dashStamina = 0; }        $gamePlayer.isRecoveringStamina = false;        if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }    }    else // not currently consuming stamina    {                if ($gamePlayer.isRecoveringStamina)        {            $gamePlayer.staminaRecoveryTimeCnt++;            if ($gamePlayer.dashStamina < $gamePlayer.dashStaminaMax) // Recover the stamina            {                // Recover stamina                $gamePlayer.dashStamina += $gamePlayer.calculateStaminaRegen(Silv.DashStamina.StaminaRecoveryRate);                if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }                                    if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }            }            else // Already at max stamina, find out when to hide the window if applicable and do so if possible            {                // If the stamina window is used, attempt to autohide it if applicable                if (Silv.DashStamina.ShowWindow && Silv.DashStamina.AutoHideStaminaWindow)                {                    $gamePlayer.hideStaminaWindowDelayCnt += 1;                    if ($gamePlayer.hideStaminaWindowDelayCnt >= Silv.DashStamina.HideStaminaWindowDelay)                    {                        Silv.DashStamina.Window.hideMe();                        $gamePlayer.hideStaminaWindowDelayCnt = 0;                    }                }                                }        }        else // not currently recovering stamina, so find out when to start recovering it and do so if required        {            $gamePlayer.staminaRecoveryTimeCnt = 0;            $gamePlayer.staminaRecoveryDelayCnt += 1;            if ($gamePlayer.staminaRecoveryDelayCnt >= Silv.DashStamina.StaminaRecoveryDelay)            {                $gamePlayer.staminaRecoveryDelayCnt = 0;                $gamePlayer.isRecoveringStamina = true;            }        }    }     $gamePlayer.dashStaminaPerc = $gamePlayer.dashStamina / parseFloat($gamePlayer.dashStaminaMax);}Game_Player.prototype.calculateStaminaRegen = function(){    var base = Silv.DashStamina.StaminaRecoveryRate;    var x = $gamePlayer.staminaRecoveryTimeCnt;    return eval(Silv.DashStamina.RegenFormula);}// Initialize variables in $gamePlayervar alias_Game_PlayerInitialize = Game_Player.prototype.initialize;Game_Player.prototype.initialize = function(){    alias_Game_PlayerInitialize.apply(this, arguments);    this.dashStamina = this.dashStaminaMax = Silv.DashStamina.StaminaMax;    this.staminaRecoveryDelayCnt = 0; // counter for when to start recovering stamina    this.staminaRecoveryTimeCnt = 0; // counter for how long the player has been recovering stamina (in frames)    this.isRecoveringStamina = false;    this.dashStaminaPerc = 1.0;    this.hideStaminaWindowDelayCnt = 0;    this.isConsumingStamina = false;}// Disable dashing when no stamina.var alias_updateDashing = Game_Player.prototype.updateDashing;Game_Player.prototype.updateDashing = function(){    alias_updateDashing.apply(this, arguments);    if ($gamePlayer.dashStamina == 0) { this._dashing = false; };    if ($gamePlayer.isRecoveringStamina && ($gamePlayer.dashStamina < Silv.DashStamina.StaminaAutoDashThreshold)) { this._dashing = false; };} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// DashStamina Window//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////function Window_DashStamina() { this.initialize.apply(this, arguments); }// Inherit from Window_BaseWindow_DashStamina.prototype = Object.create(Window_Base.prototype);// Set ConstructorWindow_DashStamina.prototype.constructor = Window_DashStamina;Window_DashStamina.prototype.standardFontSize = function() { return Silv.DashStamina.FontSize; }var sliding;var isFullySlidedOut;var isFullySlidedIn;var slideDirection = {x: 0, y: 0 };var originalWinLoc = {x: 0, y: 0 };// ConstructorWindow_DashStamina.prototype.initialize = function(x, y, width, height){    Window_Base.prototype.initialize.call(this, x, y, width, height);    this._helpWindow = null;    this._handlers = {};    this._touching = false;    this.deactivate();    this.opacity = Silv.DashStamina.WindowOpacity;    this.sliding = 'none';    this.isFullySlidedOut = false;    this.isFullySlidedIn = true;    originalWinLoc.x = x; // for some reason "this." is not allowed here    originalWinLoc.y = y; // for some reason "this." is not allowed here        this.update();};// UpdateWindow_DashStamina.prototype.update = function(){    if (Silv.DashStamina.ScreenIsFading)    {        this.visible = false;    }    else    {        Window_Base.prototype.update.call(this);        this.drawStaminaWindow(0, 0, Silv.DashStamina.StaminaGaugeRectangle.width);        this.updateSliding();    }};Window_DashStamina.prototype.drawStaminaGauge = function(x, y, width, height, rate){    var fillW = Math.floor(width * rate);    var gaugeY = y + this.lineHeight() - 8;    this.contents.fillRect(x, gaugeY, width, height, this.gaugeBackColor());    this.contents.fillRect (x, gaugeY, fillW, height, this.CalculateBarColour())};Window_DashStamina.prototype.drawStaminaWindow = function(x, y, width){    this.contents.clear();    this.drawStaminaGauge(Silv.DashStamina.StaminaGaugeRectangle.x, Silv.DashStamina.StaminaGaugeRectangle.y, Silv.DashStamina.StaminaGaugeRectangle.width, Silv.DashStamina.StaminaGaugeRectangle.height, $gamePlayer.dashStaminaPerc);    var text;    switch(Silv.DashStamina.DrawStaminaValue) // allowed values: absolute/percentage/both/none    {        case 'absolute':            text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax)            break;        case 'percentage':            text = Math.round($gamePlayer.dashStaminaPerc * 100) + '%';            break;        case 'both':            text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax) + ' (' + Math.round($gamePlayer.dashStaminaPerc * 100) + '%)';            break;        case 'none':            return;            break;        default:            throw 'ERROR: drawStaminaWindow missing case-statement or incorrect Silv.DashStamina.DrawStaminaValue value. Value: ' + Silv.DashStamina.DrawStaminaValue;        break;    }        this.resetTextColor();    this.drawText(text, x, y + 1, width, 'center');}// Calculate what colour the bar should be between the two colors depending on the percentage value of the current-stamina value.Window_DashStamina.prototype.CalculateBarColour = function(){    var c1 = hexToRgb(Silv.DashStamina.StaminaGaugeColor1);    var c2 = hexToRgb(Silv.DashStamina.StaminaGaugeColor2);            var ratio = $gamePlayer.dashStaminaPerc;    var hex = function(x) {        x = x.toString(16);        return (x.length == 1) ? '0' + x : x;    };    var r = Math.ceil(c1.r * ratio + c2.r * (1-ratio));    var g = Math.ceil(c1.g * ratio + c2.g * (1-ratio));    var b = Math.ceil(c1.b * ratio + c2.b * (1-ratio));    var middle = '#' + hex(r) + hex(g) + hex(;    return middle;}Window_DashStamina.prototype.showMe = function(){    //if (this.visible) { return; };    if (this.isFullySlidedIn)    {        this.visible = true;        return;    }        if (Silv.DashStamina.WindowSlideOutDir == 'noslide' || this.visible == false) { this.visible = true; }    else    {        this.sliding = 'in';        switch (Silv.DashStamina.WindowSlideOutDir)        {            case 'top':                slideDirection.x = 0;                slideDirection.y = 1;                break;            case 'left':                slideDirection.x = 1;                slideDirection.y = 0;                break;            case 'right':                slideDirection.x = -1;                slideDirection.y = 0;                break;            case 'bottom':                slideDirection.x = 0;                slideDirection.y = -1;                break;            default:                throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;        }    }}Window_DashStamina.prototype.hideMe = function(){    if (!this.visible || this.isFullySlidedOut) { return; };        if (Silv.DashStamina.WindowSlideOutDir == 'noslide') { this.visible = false; }    else    {        this.sliding = 'out';        switch (Silv.DashStamina.WindowSlideOutDir)        {            case 'top':                slideDirection.x = 0;                slideDirection.y = -1;                break;            case 'left':                slideDirection.x = -1;                slideDirection.y = 0;                break;            case 'right':                slideDirection.x = 1;                slideDirection.y = 0;                break;            case 'bottom':                slideDirection.x = 0;                slideDirection.y = 1;                break;            default:                throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;        }    }}Window_DashStamina.prototype.handleSlidingEnd = function(){    if(this.sliding == 'in')    {        // Stop sliding in        if (slideDirection.x  == 1 && this.x > originalWinLoc.x ||            slideDirection.x  == -1 && this.x < originalWinLoc.x ||            slideDirection.y  == 1 && this.y > originalWinLoc.y ||            slideDirection.y  == -1 && this.y < originalWinLoc.y)        {            this.sliding = 'none';            this.isFullySlidedIn = true;        }    }    else    {        // Stop sliding out        if (this.x < -this.width || x > Graphics._width + this.width ||            this.y < -this.height || x > Graphics._height + this.height)        {            this.sliding = 'none';            this.isFullySlidedOut = true;        }    }}Window_DashStamina.prototype.updateSliding = function(){    if (this.sliding == 'none') { return; }    this.x += slideDirection.x * Silv.DashStamina.WindowSlideOutSpeed;    this.y += slideDirection.y * Silv.DashStamina.WindowSlideOutSpeed;        this.isFullySlidedOut = false;    this.isFullySlidedIn = false;        this.handleSlidingEnd();}var alias_Stamina_SceneBase_StartFadeIn = Scene_Base.prototype.startFadeIn;Scene_Base.prototype.startFadeIn = function(){    alias_Stamina_SceneBase_StartFadeIn.apply(this, arguments)       if (Silv.DashStamina.Window != null) { Silv.DashStamina.Window.visible = false; }};/*var alias_Stamina_SceneBase_StartFadeOut = Scene_Base.prototype.startFadeOut;Scene_Base.prototype.startFadeOut = function(){    alias_Stamina_SceneBase_StartFadeOut.apply(this, arguments)}*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Create the stamina window//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Scene_Map.prototype.createDashWindow = function(){    // Does the map consume stamina?    $gamePlayer.mapConsumeStamina = !('dstam_disable' in $dataMap.meta);    if(Silv.DashStamina.ShowWindow)    {        x = 0;        if (Silv.DashStamina.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.DashStamina.WindowWidth; }        y = 0;        if (Silv.DashStamina.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.DashStamina.WindowHeight; }                if (Silv.DashStamina.Window != null) { this.removeWindow(Silv.DashStamina.Window); }                Silv.DashStamina.Window = new Window_DashStamina(x + Silv.DashStamina.Window_X, y + Silv.DashStamina.Window_Y, Silv.DashStamina.WindowWidth, Silv.DashStamina.WindowHeight);                this.addChild(Silv.DashStamina.Window, Silv.DashStamina.Window_Z);        if (Silv.DashStamina.AutoHideStaminaWindow) { Silv.DashStamina.Window.visible = false; }    }}// Omg why does RPG Maker not have this method by default...Scene_Base.prototype.removeWindow = function(window){    var index = this.children.indexOf(window);    if (index > -1) { this.children.splice(index, 1); }}var alias_createStaminaDisplayObjects = Scene_Map.prototype.createDisplayObjects;Scene_Map.prototype.createDisplayObjects = function(){    alias_createStaminaDisplayObjects.call(this);    this.createDashWindow();};//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Saving & Loading//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////var alias_silv_stamina_makeSaveContents = DataManager.makeSaveContents;DataManager.makeSaveContents = function(){    contents = alias_silv_stamina_makeSaveContents.call(this);    contents.dashStamina = $gamePlayer.dashStamina;    contents.dashStaminaMax = $gamePlayer.dashStaminaMax;    return contents;}var alias_silv_stamina_extractSaveContents = DataManager.extractSaveContents;DataManager.extractSaveContents = function(contents){    alias_silv_stamina_extractSaveContents.call(this, contents);    $gamePlayer.dashStamina = contents.dashStamina;    $gamePlayer.dashStaminaMax = contents.dashStaminaMax;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Plugin Command// Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;Game_Interpreter.prototype.pluginCommand = function(command, args){    _Game_Interpreter_pluginCommand.call(this, command, args);    if (command.toLowerCase() == Silv.DashStamina.PluginCmdId) { PluginCommand(command, args); }}function PluginCommand(cmd, args){    switch(args[0].toLowerCase())    {        case 'refill':            $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;            break;        case 'deplete':            $gamePlayer.dashStamina = 0;            break;        case 'set':            var perc = parseInt(args[1]);            perc = Math.max(0, Math.min(100, perc)); // clamp value between 0-100            $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax * (perc / 100.0);        break;        case 'showwindow':            if (Silv.DashStamina.Window != null)            {                $gamePlayer.hideStaminaWindowDelayCnt = 0;                Silv.DashStamina.Window.visible = true;            }            break;        case 'refillhide':            $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;        case 'hidewindow':            if (Silv.DashStamina.Window != null)            {                $gamePlayer.hideStaminaWindowDelayCnt = Silv.DashStamina.HideStaminaWindowDelay;                Silv.DashStamina.Window.visible = false;            }            break;        case 'setmax':            $gamePlayer.dashStaminaMax = Math.max(1, parseInt(args[1]));            if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }            break;        case 'increasemax':            $gamePlayer.dashStaminaMax += parseInt(args[1]);            if ($gamePlayer.dashStaminaMax < 1) { $gamePlayer.dashStaminaMax = 1; }            if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }            break;        default:            throw 'Stamina PluginCommand invalid command: ' + args[0];            break;    }}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////})();
 
Last edited by a moderator:

Jeremy Cannady

Coldfire
Veteran
Joined
Oct 25, 2015
Messages
449
Reaction score
268
First Language
English
Thanks for making this! It saved me from having too. Thanks for your contribution. 

I will test it out but looking forward to the stamina bar!
Perhaps make the stamina bar green when you can dash again so it makes it clear.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
I see you made the same mistake i did at first, when writing my dash stamina plugin (not relased): You decrease stamina even when the player is not moving or running against a wall.


Also, you refer to the player as $gamePlayer, even when inside the Game_Player class (just use "this" in that case). The Scene_Map should refer to $gamePlayer, instead of the prototype, though (although you can do the whole stamina calculation inside the Game_Player class itself, no need to do this from the outside).
 
Last edited by a moderator:

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
I tried this first but it didn't work:

//replacing  Game_Player.prototype.updateStamina = function()  {     if ($gamePlayer.isDashing())//with  Game_Player.prototype.updateStamina = function()  {     if (this.isDashing())The above causes the stamina to never deplete.

I find the "this" keyword rather confusing in Javascript. Not to mention that 'classes' are insanely messy in this language.

I could indeed call the update from Game_Player. But I need to update the window/sprite for the stamina bar on the map anyway later so I might as well update both from the same 'alias'. The method itself is inside player anyway.
 
Last edited by a moderator:

Jeremy Cannady

Coldfire
Veteran
Joined
Oct 25, 2015
Messages
449
Reaction score
268
First Language
English
I got it to display the stamina on the map, it is a moving gauge. If you need any help with that let me know.

Dash_zpsn5lhru61.png
 
Last edited by a moderator:

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
I see you made the same mistake i did at first, when writing my dash stamina plugin (not relased): You decrease stamina even when the player is not moving or running against a wall.
Fixed.

Also, you refer to the player as $gamePlayer, even when inside the Game_Player class (just use "this" in that case). The Scene_Map should refer to $gamePlayer, instead of the prototype, though (although you can do the whole stamina calculation inside the Game_Player class itself, no need to do this from the outside).
Still unsure as how to do this properly. I still use $gamePlayer.

I got it to display the stamina on the map, it is a moving gauge. If you need any help with that let me know.
I got it. Making the bar was easy. Thanks for explaining me how to make a basic window.

I had some problems making global functions. They work but I hope I did it properly.
 
Last edited by a moderator:

blo0p

Villager
Member
Joined
Nov 4, 2015
Messages
6
Reaction score
2
First Language
English
Thanks for the plugin! It's working great so far!

Is it possible to update the stamina amount by "steps" instead of the "isMoving" parameter? I've been tinkering with it but I can't find the right language to use.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
It's possible but I do not see the benefit of subtracting stamina per step instead of just whenever the player is moving.

Also you would then see the stamina decrease suddenly when you arrive at a new tile making it look weird.
 

blo0p

Villager
Member
Joined
Nov 4, 2015
Messages
6
Reaction score
2
First Language
English
Haha, Yeah I know it seems like an odd feature to implement... 

I might be trying to re-purpose the script in order to restrict the amount of moves a player can make within a "turn". 
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
Okay massive update:

- Refactored a lot of code
- Removed the 'garbage' initialization in $gamePlayer and removed most of the variables there
- Fixed crash when stamina window was hidden
- Fixed bug when AutoHideStaminaWindow was set to false
- Added more parameters and renamed the old ones
- Rewrote the updateStamina() method

- Stamina window no longer shows when the scene is fading out
- Some more stuff

If anyone knows how to put the stamina window underneath the fade-screen (not when transferring but when manually fading through event) please let me know. I currently simply hide the window instead.
 
Last edited by a moderator:

Skywindz

Villager
Member
Joined
Oct 29, 2015
Messages
16
Reaction score
2
First Language
English
At line 333 

    if (Silv.DashStamina.ShowWindow) { Silv.DashStamina.ShowWindow.visible = true; }

This should be the fix if it gives an type error that says "Cannot set property 'Visible' of null."

Originally its

    if (Silv.DashStamina.ShowWindow) { Silv.DashStamina.Window.visible = false; }

Please fix this.

Thanks :3
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
Fixed (problem was in the fade-code, it seems that Scene_Map fade method is called even though only the titlescreen is active).

Note that the fix you posted would get rid of the error but it could cause other problems because you are changing a parameter value.
 
Last edited by a moderator:

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
Added plugin commands and a helpfile.
 

Skywindz

Villager
Member
Joined
Oct 29, 2015
Messages
16
Reaction score
2
First Language
English
Fixed (problem was in the fade-code, it seems that Scene_Map fade method is called even though only the titlescreen is active).

Note that the fix you posted would get rid of the error but it could cause other problems because you are changing a parameter value.
Oh okay.

No worries and thanks.
 

ShadowFox

Adventurer
Member
Joined
Mar 13, 2012
Messages
255
Reaction score
10
First Language
English
Primarily Uses
Very interesting.

Are you planning on having an option of having the stamina set to something else? Like Agility or even a variable?
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
Very interesting.

Are you planning on having an option of having the stamina set to something else? Like Agility or even a variable?
I'm not planning on it. But I could add an option to increase/decrease max-stamina.
 

eivl

Villager
Member
Joined
Jun 12, 2013
Messages
20
Reaction score
1
First Language
English
Primarily Uses
I am also writing a stamina plugin, we are doing a lot of the same thing.

What i can see as differences is that i have the regeneration of the stamina bar to happen as long as the actor is not moving, and holding shift does not matter.

I like that you change color when it gets depleted or filled, i like it so much that i will change it.

I have an optional exhaust mode, so if you empty your bar to 0 you are not able to dash while it fills up (parameter but default is 100%)

Because of this there are some options to consider. 

Since you should not empty your stamina bar to 0 (since exhaust kicks in and you are not able to dash before it is filled up again) you should have different fill speed

I am working on this at the moment.

My idea is to have 3 speeds

Depleted rate : while dashing

Fill rate : while not dashing

Exhausted fill rate : forced to not dash

should there be different fill rate when you stand still or walking? I am not sure. 

I have a plan on having max stamina increase with level and fill rate increase after stat. and using diminishing return to not having this overpowered. 

I did not know how i would do it, but after reading your code i now know what to do! ;)

Also i wonder if i should have items and note tags increase max stamina with an option to have a fixed bar width or an increased bar width. 

How did you fix the fade problem? and what do you do when you change map? I am a bit worried that my bar will break when changing map.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
@eivl

- This plugin already has an exhaust mode

- Different fillspeeds are already on the todo list. Currently stamina is regenerated when not dashing. But I'm too busy with other stuff to fully implement it right now.

- The code to fade the GUI properly is right on top of the plugin in the code (below the parameters). But I need to optimize it.

- Good luck with your own plugin.
 
Last edited by a moderator:

eivl

Villager
Member
Joined
Jun 12, 2013
Messages
20
Reaction score
1
First Language
English
Primarily Uses
@SilverDash thanks for it. Have not tested it, read your script quickly from work ;)
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
175
First Language
Dutch
Primarily Uses
RMMV
I just updated it.

Updates:

- You can now show the value, percentage or both or none in the stamina bar.

- Window can slide in/out (needs more testing).

- Fixed a bug with fading the window in/out when the screen was faded.

- Max stamina can now be set (and is saved&loaded) and 2 new plugin commands for it.

- Some minor refactoring.

- Added window opacity. Set this to 0 if you prefer to hide the entire window and only want the stamina bar.

- Added a new parameter for the formula for the stamina regeneration. Now YOU can determine how and how fast the stamina regens over time with an equation.

- Some more stuff that I can't remember right now :p .

Needs some more testing though. Especially the sliding.

For some reason I can't edit the OP so I just continue here:

Planned features (no promises):

- (Maybe some day) Allowing the highest/lowest/average agility stat of the partymember(s) to determine how much stamina you have.
 
Last edited by a moderator:

Latest Threads

Latest Profile Posts

Zombie status is now complete. I didn't have to do much in the way of changing how healing is applied to undead targets, was just a simple 3 line code. I thought I had to overhaul Game_Action lol. Everything else was doable by events. So.. Zombie: You turn undead. Your element changes to darkness. You're weak to light, you're strong to physical attacks and healing hurts you and revival items will kill you.
My Overworld might be a mix of inspiration from 2D Final Fantasy games, Breath of Fire, Battlechasers: Nightwar, Super Mario World, and Pillars of Eternity. If I can make it more in-depth than just walking from point A to point B, that might do a lot for the gameplay experience. Hmm...
Terribly depressed. Worst birthday I've had in years, no motivation to work on anything. Still no income. At least I've got my computer running again.
Doing RPG Maker News for 19th September 2021

Forum statistics

Threads
115,213
Messages
1,088,082
Members
149,792
Latest member
ShenYQ
Top