/*:
* @target MV MZ
* @plugindesc Minimum action damage is 5~10 (random).
* @author Caethyril
* @url https://forums.rpgmakerweb.com/threads/161247/
* @help Free to use and/or modify for any project, no credit required.
*/
void (function(alias) {
Game_Action.prototype.evalDamageFormula = function(target) {
return Math.max(alias.apply(this, arguments), 5 + Math.randomInt(6));
};
})(Game_Action.prototype.evalDamageFormula);
randomInt(6)
returns a uniformly-random integer in the range 0~5.)b.defaultAttack(a, b)
Game_Battler.prototype.defaultAttack = function(a, b)
(JavaScript:/*: * @target MV MZ * @plugindesc Minimum action damage is 5~10 (random). * @author Caethyril * @url https://forums.rpgmakerweb.com/threads/161247/ * @help Free to use and/or modify for any project, no credit required. */ void (function(alias) { Game_Action.prototype.evalDamageFormula = function(target) { return Math.max(alias.apply(this, arguments), 5 + Math.randomInt(6)); }; })(Game_Action.prototype.evalDamageFormula);
randomInt(6)
returns a uniformly-random integer in the range 0~5.)
RMMV's core scripts round the final formula result to the nearest integer, rather than floor it. That's relevant becauseMath.random() * 5 + 5
Math.random()
returns a value in the range [0, 1)
(i.e. excluding 1
), so:Math.round(Math.random() * 5)
-> 0, 1, 2, 3, 4, 5
, but 0
and 5
are half as likely as the others.Math.floor(Math.random() * 5)
-> 0, 1, 2, 3, 4
, all equally likely.Math.randomInt(n)
is an RMMV/Z shorthand for Math.floor(Math.random() * n)
.Oh wow... I knew how Math.random works (take any value between 0 and 1, with unlimited decimals), but I never actually realized that 0 can only be reached by rounding down and the top number only by rounding up, while all numbers in between ban be reached by rounding up and rounding down.RMMV's core scripts round the final formula result to the nearest integer, rather than floor it. That's relevant becauseMath.random()
returns a value in the range[0, 1)
(i.e. excluding1
), so:
Math.round(Math.random() * 5)
->0, 1, 2, 3, 4, 5
, but0
and5
are half as likely as the others.Math.floor(Math.random() * 5)
->0, 1, 2, 3, 4
, all equally likely.Math.randomInt(n)
is an RMMV/Z shorthand forMath.floor(Math.random() * n)
.
void (function(alias) {
Game_Action.prototype.evalDamageFormula = function(target) {
return Math.max(alias.apply(this, arguments), 5 + Math.randomInt(6));
};
})(Game_Action.prototype.evalDamageFormula);
The problem with computers is that they never do what you want them to do, and instead do exactly what you tell them to do. It's not really a glitch, the damage formula has been modified exactly in the way you asked it to be@caethyril I have to report a glitch with:
Code:void (function(alias) { Game_Action.prototype.evalDamageFormula = function(target) { return Math.max(alias.apply(this, arguments), 5 + Math.randomInt(6)); }; })(Game_Action.prototype.evalDamageFormula);
It seems to work fine with HP Damage, but if you put HP Recover, well it will still pick 5 + Math.randomInt(6)) over the recovery formula (considered a negative value I suppose), so will damage the target instead of recovering it.
void (function(alias) {
Game_Action.prototype.evalDamageFormula = function(target) {
let normalValue = alias.apply(this, arguments);
if(normalValue >= 0) return Math.max(normalValue, 5 + Math.randomInt(6));
else return normalValue;
};
})(Game_Action.prototype.evalDamageFormula)