SHARE
TWEET

Fix for Damage Evaluation

a guest Nov 1st, 2015 143 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Bug Fix - Fix Damage Evaluation returning Not-A-Number.
  3. // DamageEvalNotANumberFix.js
  4. // Version: 1.0
  5. //=============================================================================
  6.  
  7. //=============================================================================
  8.  /*:
  9.  * @plugindesc Fixes an issue when evaluating damage formulas that would return
  10.  * value of NaN when no damage formula is entered. Thus fixing a bug that would
  11.  * cause a crash/exception when attempting to draw the hp/mp gauges.
  12.  * @author Liquidize
  13.  */
  14. //=============================================================================
  15.  
  16. (function() {
  17.  
  18. // Overwrites the damage evaluation function to include checking if the returned value is Not-a-Number.
  19. Game_Action.prototype.evalDamageFormula = function(target) {
  20.     try {
  21.         var item = this.item();
  22.         var a = this.subject();
  23.         var b = target;
  24.         var v = $gameVariables._data;
  25.         var sign = ([3, 4].contains(item.damage.type) ? -1 : 1);
  26.         var value = Math.max(eval(item.damage.formula), 0) * sign;
  27.                
  28.                 if (Number.isNaN(value)) {
  29.                         return 0;
  30.                 }
  31.                 return value;
  32.     } catch (e) {
  33.         return 0;
  34.     }
  35. };
  36.  
  37. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top