I would like to make a skill that deals additional damage based on the difference between the actor's ATK multiplier and the enemy's ATK multiplier.
Theoretically saying :
a.atk * 4 - b.def * 2 + (a.atk - b.atk)
is this correct ?
Damage Formulas 101
● ARCHIVED · READ-ONLY
-
-
Maybe? The syntax is correct, that formula will function in RPG Maker.I would like to make a skill that deals additional damage based on the difference between the actor's ATK multiplier and the enemy's ATK multiplier.
Theoretically saying :
a.atk * 4 - b.def * 2 + (a.atk - b.atk)
is this correct ?
Whether it does what you want is kind of up to you. You say you want "the difference between the actor's ATK multipler and the enemy's ATK multiplier," but there's no such thing in the engine and you're not multiplying them by anything in your formula (well, you're multiplying the actor's ATK at the beginning).
The last bit of your formula is just adding (or subtracting) the difference between their ATK parameters. Is that what you mean?
If you don't think your formula is doing what you want, try to reword what your goal is. -
@crackkillz There's another way to reference the attack value of an equipped weapon:
user.equips()[0].params[2]
Would return the attack stat (param 2) of the first equip slot (equips()[0]).
You can reference an actors base strength stat, before any bonuses from gear of buffs with:
user.paramBase(2)
Conversely, you can reference ONLY the bonus values of a parameter using:
user.paramPlus(ID)
Where "ID" is the number of the param you want to check. -
it actually works. But, I forgot to explain about the multiplier... i will explain itMaybe? The syntax is correct, that formula will function in RPG Maker.
Whether it does what you want is kind of up to you. You say you want "the difference between the actor's ATK multipler and the enemy's ATK multiplier," but there's no such thing in the engine and you're not multiplying them by anything in your formula (well, you're multiplying the actor's ATK at the beginning).
The last bit of your formula is just adding (or subtracting) the difference between their ATK parameters. Is that what you mean?
If you don't think your formula is doing what you want, try to reword what your goal is.
Bonus damage is based on the difference between A.atk and B.atk, but it will be multiplied based on the difference , so the higher the difference --- the higher bonus damage.
Notes and example :
- Actor A ATK is 50, meanwhile Actor B ATK is 20
the difference is : 50-20 = 30 points.
- difference multiplier :
0 - 30 points : x1 bonus (bonus 0-30 damage)
31 - 50 points : x3 bonus (bonus 93-150 damage)
50 - 99 points : x5 bonus (bonus 250- 495 damage)
> 99 points : x10 bonus (bonus 990+ damage)
- if B.atk is higher than A.atk , no bonus damage. it will just do normal damage. -
Erm...okay? None of that is in the formula you posted, so we can't tell you if you did it correctly.- difference multiplier :
0 - 30 points : x1 bonus (bonus 0-30 damage)
31 - 50 points : x3 bonus (bonus 93-150 damage)
50 - 99 points : x5 bonus (bonus 250- 495 damage)
> 99 points : x10 bonus (bonus 990+ damage)
- if B.atk is higher than A.atk , no bonus damage. it will just do normal damage.
But if you're confident you have that part and you wanted to check that how you're fitting it into the rest of the formula is mathematically correct, then yes. -
So I don't know where I'm going wrong with this code, but it's sort of working as intended with a minor hiccup. I think I know what the hiccup is, but would like some clarification on it.
Code:v[3] = (v[3]||0) + 1; if (v[3] >= 10) {(100 + a.mat + v[3]) * 2 - b.mdf * 2; a.addBuff(4, 2); b.mdf*10} else {(100 + a.mat + v[3]) * 2 - b.mdf * 2}
So the way the spell is supposed to work is when using it, the Fire variable (which is 3) should increase by one. If the variable is less than 10 it should do the normal formula damage of (100 + a.mat + v[3]) * 2 - b.mdf * 2
That works perfectly fine. However, once the variable hits 10 or more, it should do the same damage but add a buff to the player. Before I didn't have the b.mdf*10 and the spell wouldn't do any damage and just applied the buff. I added it, and when the variable hits 10, all damage from that spell now does a flat 100 (I continued using the spell 4 times in playtesting and all 4 did 100 damage). I think the issue revolves around the b.mdf*10 but without it the spell only applies the buff and doesn't do any damage. -
The problem is in your if. Expanding it onto separate lines:So I don't know where I'm going wrong with this code, but it's sort of working as intended with a minor hiccup. I think I know what the hiccup is, but would like some clarification on it.
Code:v[3] = (v[3]||0) + 1; if (v[3] >= 10) {(100 + a.mat + v[3]) * 2 - b.mdf * 2; a.addBuff(4, 2); b.mdf*10} else {(100 + a.mat + v[3]) * 2 - b.mdf * 2}
if (v[3] >= 10) {(100 + a.mat + v[3]) * 2 - b.mdf * 2;<- Right here, this isn't doing anything. It's just an equation floating in space. You're not setting a variable to the result of this equation, and it's not the last number to be used as the damage result
a.addBuff(4, 2); b.mdf*10}So you're adding the buff and returning magic defense * 10 as the damage
Per the instructions in the first post of this thread, whatever you want to do as your damage has to be the last number in the formula. So delete that mdf*10 thing and swap the order of addBuff and the other equation so the equation is last. -
Oh my god dude thank you so much! It turns out the problem was the damage not being in the last part of the first formula. Once I put the a.addBuff(4, 2); code before the damage part it began to work properly!The problem is in your if. Expanding it onto separate lines:
if (v[3] >= 10) {(100 + a.mat + v[3]) * 2 - b.mdf * 2;<- Right here, this isn't doing anything. It's just an equation floating in space. You're not setting a variable to the result of this equation, and it's not the last number to be used as the damage result
a.addBuff(4, 2); b.mdf*10}So you're adding the buff and returning magic defense * 10 as the damage
Per the instructions in the first post of this thread, whatever you want to do as your damage has to be the last number in the formula. So delete that mdf*10 thing and swap the order of addBuff and the other equation so the equation is last. -
Now I have an entirely new issue. I was trying to expand the code to make it so if the enemy has an elemental weakness, the variable increases by 2 instead of 1. This piece of gimmick is to encourage players to utilize elements that are strong against foes to quickly build alignment. This current code I'm using works perfectly as intendedCode:
v[3] = (v[3]||0) + 1; if (v[3] >= 10) {a.addBuff(4, 2); (100 + a.mat + v[3]) * 2 - b.mdf * 2} else {(100 + a.mat + v[3]) * 2 - b.mdf * 2}
So I thought I needed to add an if statement checking the b.elementRate(2) as 2 is the for Fire that I'm testing this code with. I used this code and it does no damage and doesn't increase the variable. I have the element rate set to 150% on the enemy I'm testing.
Code:v[3] = (v[3]||0) b.elementRate(2) > 0 ? + 2 : + 1; if (v[3] >= 10) {a.addBuff(4, 2); (100 + a.mat + v[3]) * 2 - b.mdf * 2} else {(100 + a.mat + v[3]) * 2 - b.mdf * 2}
I really do apologize with how often I come here for help....and sometimes I really do feel like it's for dumb things, but I get lost easily sometimes and tend to need help with what I'm doing. -
So split it up like we did before.So I thought I needed to add an if statement checking the b.elementRate(2) as 2 is the for Fire that I'm testing this code with. I used this code and it does no damage and doesn't increase the variable.
This is invalid syntax. The ternary operator can only contain a right or left side operand, it can't contain the actual operator. The way this reads is two separate statements:Code:v[3] = (v[3]||0) b.elementRate(2) > 0 ? + 2 : + 1;
v[3]=v[3] || 0 b.elementRate ... etc<- This just produces a floating "+2" or "+1" that doesn't mean anything
It should work fine if you put the operator in the correct place and separate it from the previous operator with parentheses.
Code:v[3] = (v[3]||0) + (b.elementRate(2) > 0 ? 2 : 1);
Incidentally, you know that elementRate > 0 is true by default? That number is what damage gets multiplied by, so all actors and enemies start with an elementRate for every element of 1. Greater than 1 will indicate they're vulnerable to that element, less than 1 is a resistance. -
So split it up like we did before.
This is invalid syntax. The ternary operator can only contain a right side operand, it can't contain the actual operator. The way this reads is two separate statements:
v[3]=v[3] || 0 b.elementRate ... etc<- This just produces a floating "+2" or "+1" that doesn't mean anything
It should work fine if you put the operator in the correct place and separate it from the previous operator with parentheses.
Code:v[3] = (v[3]||0) + (b.elementRate(2) > 0 ? 2 : 1);
Ah okay. I didn't realize that. So anytime I wanna use do something to a variable in the formula, but have conditions set with it, I should be using + to connect the variable to the condition right?
Incidentally, you know that elementRate > 0 is true by default? That number is what damage gets multiplied by, so all actors and enemies start with an elementRate for every element of 1. Greater than 1 will indicate they're vulnerable to that element, less than 1 is a resistance.
This I was aware of, but I wanted to test the code to make sure the variable increase was actually for 2 and not just 1 first. If it didn't increase it by 2, then I would know I did something wrong in the formula as it should automatically read as a true statement. -
Erm...sure?Ah okay. I didn't realize that. So anytime I wanna use do something to a variable in the formula, but have conditions set with it, I should be using + to connect the variable to the condition right?
All operators in JavaScript (just like in the math you're used to) have the formatvalue operator value
e.g. 2 + 2
All of those things produce a value which you could then use on one side of another operator if you so wished. e.g.(2 + 2) * 4
The ternary operator isn't different except, per its name, it uses 3 things to create its end value instead of 2. It still produces and functions as a value - you wouldn't try to say, in the example above,(/ + 2) * 4- that clearly doesn't mean anything. -
Ah alright. Thank you again for the help, I really hate being a bother and it really does seem like obvious things once they are pointed out. Hopefully one day I can reliably do this without constantly pondering the forum
-
Hi experts, I am trying to make a formula that does not return 0 if the defense is very high. The below script doesn't work. I've tried a few other script but still does not work. Any suggestion what am I doing wrong?
Tried this and doesn't work
if (a.atk*4 - b.def*2 === 0) 2; else a.atk*4 - b.def*2
Tried this also doesn't work
(a.atk * 4 - b.def * 2)+2 -
Try this:
Math.max(a.atk*4 - b.def*2, 2) -
Yes! It worked. I guess the formula means take the max of the two number right? I tried it with an extra and it still works. Yay. Thanks!Math.max(a.atk*4 - b.def*2, 2)
Math.max(a.atk*4 - b.def*2, 1 + Math.random() * 3) -
You already got the correct way to do this, but just to let you know why this doesn't work - you're asking if the result of your damage formula is equal to 0. There are only specific pairs of values which could possibly make that be exactly zero.Hi experts, I am trying to make a formula that does not return 0 if the defense is very high...Any suggestion what am I doing wrong?
if (a.atk*4 - b.def*2 === 0) 2; else a.atk*4 - b.def*2
What's much more likely is that the result is a negative number which the engine then turns into 0 when it pops up the damage dealt. So the correct condition would be:if (a.atk*4 - b.def*2 <= 0) -
I have a question with paramPlus(), i dont understand how can I usedPlease note:
A discussion has already been started about different things you can do with these formulas so please direct those comments and question to the appropriate thread.
https://forums.rpgmakerweb.com/index.php?threads/rmmv-damage-formula-ideas-and-help.47099/
A link to the list of script equivalents of event commands
https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-script-call-list.46456/
Damage Formulas 101
MV Edition
You probably wondered how to make a skill do more damage against enemies with a state, or heal more if player has a state, or deal exactly half of enemy's HP. And so on.
All of that and more can be done through custom damage formula.

Basics:
Type - sets what does the formula damage or heal.
None - Nothing, no damage will be dealt.
HP Damage - HP will be damaged
MP Damage - MP will be damaged
HP Recover - HP will be restored
MP Recover - MP will be restored
HP Drain - Deals damage to enemy HP and restores that much HP for attacker
MP Drain - Deals damage to enemy MP and restores that much MP for attacker
Element - Sets which element to use. Normal attack - means will use same element as weapon.
Variance - How will damage fluctuate. E.g. If skill formula says it deals 100 damage and variance is 20%, the skill will deal between 80 and 120 damage.
Critical - Can skill critically hit, dealing increased damage by 300%.
And now, the actual fun part - formulas!
It decides how much damage will opponent take or ally will heal.
Let's dissect one of basic formulas that come with RPG Maker MV - Fire
100 + a.mat * 2 - b.mdf * 2
What do things like a and b mean?
a - attacker
b - defender
So if Actor Glasses were to cast Fire on a Slime. a would be Glasses and b would be Slime.
Meaning the takes double of Glasses mat (Magic Attack) parameter and subtracts double of Slime's mdf (Magic Defense) parameter and adds that to the 100 in the beginning ofthe formula.
E.g. Glasses has 100 mat and Slime has 20 mdf. If we were to convert fomula using those numbers, we'd have - 100 + 100*2 - 20*2, after calculation we see with those parameters Fire would deal 260 damage if there were no variance.
But only last number in the formula deals damage. If you had 2 lines of formula. (semicolon ; tells where line ends for the program)
E.g. a.atk; a.atk*2
Only a.atk*2 would be calculated for damage.
Are there more letters other than a and b for the formulas?
Yes. There are variables. Which are used like this: v[ID]. ID - index of the variable.
So you could have a skill that gets stronger the higher variable is.
E.g. v[10] * 2 - b.def * 3
Is there a way to make skill even more complex, e.g. if some variable is over 100, deal extra damage?
Yes, in that case we can use if else statements.
How if else statement looks:
Code:
Code (Text):
if (statement)
{
formula1;
}
else
{
formula2;
}
But how to write it to the damage formula?
It only has 1 line!
Just write everything together~
Code (Text):
if (statement) { formula1; } else { formula2; }
E.g.:
Code (Text):
if (v[10] > 100) { a.atk*4 - b.def*2 } else { a.atk*2 - b.def*2 }
Which can be shortened to this if you're using only 1 line of formula.
Code (Text):
if (statement)
formula1;
else
formula2;
E.g.:
Code (Text):
if (v[10] > 100) a.atk*4 - b.def*2; else a.atk*2 - b.def*2;
And you can shorten it even further using ternary operator (my favorite one):
statement ? formula1 : formula2;
E.g.:
Code (Text):
v[10] > 100 ? a.atk*4 - b.def*2 : a.atk*2 - b.def*2;
Symbols for statements:
> - more than
< - less than
>= more than or equal to
<= less than or equal to
=== equal to
&& and
|| or
!== not equal
! not
Examples:
v[10] > 100 ? 1000 : 100; (If variable 10 is more than 100, it'll deal 1000 damage, else it'll only deal 100)
v[10] < 100 ? 1000 : 100; (If variable 10 is less than 100, it'll deal 1000 damage, else, it'll only deal 100)
v[10] >== 100 ? 1000 : 100; (If variable is 100 or more, it'll deal 1000 damage, else it'll only deal 100)
v[10] <== 100 ? 1000 : 100; (If variable is 100 or less, it'll deal 1000 damage, else it'll only deal 100)
v[10] === 100 ? 1000: 100; (If variable is equal to 100, it'll deal 1000 damage, else it'll only deal 100)
v[10] > 50 && v[11] >== 25 ? 1000 : 100; (If variable 10 is more than 50 and variable 11 is 25 or more, it'll deal 1000 damage, else it'll only deal 100)
v[10] > 50 || v[11] > 50 ? 1000 : 100; (If variable 10 is more than 50 or variable 11 is more than 50 then it'll deal 1000 damage, it'll only deal 100)
v[10] !== 100 ? 1000 : 100; (If variable 10 is not equal to 100, it'll deal 1000 damage else it'll only deal 100)
What about parameters to use for a and b?
Here's a whole list of them:
Current: (All flat numbers, e.g.: 900, 999, 11)
level - current level (Actor only by default)
hp - current hp
mp - current mp
tp - current tp
Params: (All flat numbers, e.g.: 1337, 7331, 156)
mhp - max hp
mmp - max MP
atk - attack
def - defence
mat - magic attack
mdf - magic defence
agi - agility
luk - luck
XParams: (All decimal numbers symbolizing percent, e.g. 1.0, 0.5, 0.75, 2.44 would be 100%, 50%, 75%, 244%)
hit - Hit rate
eva - Evasion rate
cri - Critical rate
cev - Critical evasion rate
mev - Magic evasion rate
mrf - Magic reflection rate
cnt - Counter attack rate
hrg - HP regeneration rate
mrg - MP regeneration rate
trg - TP regeneration rate
SParams:(All decimal numbers symbolizing percent, e.g. 1.0, 0.5, 0.75, 2.44 would be 100%, 50%, 75%, 244%)
tgr - Target Rate
grd - Guard effect rate
rec - Recovery effect rate
pha - Pharmacology
mcr - MP Cost rate
tcr - TP Charge rate
pdr - Physical damage rate
mdr - Magical damage rate
fdr - Floor damage rate
exr - Experience rate
How about changing HP/MP/TP?
gainHp(value) - restores HP by value
gainMp(value) - restores MP by value
gainTp(value) - restores TP by value
setHp(hp) - sets HP to value
setMp(mp) - sets MP to value
setTp(tp) - sets TP to value
E.g. a.setHp(a.mhp)
E.g. a.setHp(a.hp + 100)
clearTp() - sets TP to 0
What about advanced stuff where you can influence formulas with states?
We got all that!
isStateAffected(stateId) - checks if battler has state inflicted to them.
E.g. b.isStateAffected(10) ? 10000 : 1;
isDeathStateAffected() - checks if battler has death state inflicted to them.
E.g. b.isDeathStateAffected() ? 10000 : 1;
resetStateCounts(stateId) - refreshes how long state will last for the battler
if (b.isStateAffected(10)) b.resetStateCounts(10); 100
updateStateTurns() - shortens all states on battler by 1 turn
b.updateStateTurns(); 100
addState(stateId) - adds state to the battler
if (!b.isStateAffected(10)) b.addState(10); 100
isStateAddable(stateId) - checks if state can be added to the battler
c=100; if (b.isStateAddable(10)) b.addState(10); else c=4000; c
removeState(stateId) - removes state from the battler
if (a.isStateAffected(10)) a.removeState(10); 0
What about buffs? Can we buff and debuff battlers?
Yes!
addBuff(paramId, turns) - adds a buff for a parameter
a.addBuff(0, 3); b.def*10
addDebuff(paramId, turns) - adds a debuff for a parameter
b.addDebuff(2, 10); 9999
removeBuff(paramId) - removes a buff or debuff from a battler
removeAllBuffs() - removes all buffs and debuffs from a battler
Parameter IDs
0 - Max HP
1 - Max MP
2 - Attack
3 - Defence
4 - Magic Attack
5 - Magic Defence
6 - Agility
7 - Luck
General Battler Stuff
die() - kills the battler
b.die(); 0
revive() - revives the battler
a.revive(); 1000
paramBase(paramId) - gets base parameter
a.paramBase(3)*10 - b.def*2
paramPlus(paramId) - gets the bonus of parameter
a.paramPlus(3)*2 - b.def*2
paramMax(paramId) - gets max possible value of parameter
b.paramMax(0)
elementRate(elementId) - checks element rate of the battler (rate being decimal numbers representing %)
b.elementRate(10) >== 0.5 ? 10000 : a.mat*4;
isStateResist(stateId) - checks whether the battler resists state
c=0; b.isStateResist(10) ? c+=2000 : b.addState(10); c
isSkillTypeSealed(stypeId) - checks if battler's skill type is sealed
isSkillSealed(skillId) - checks if battler's skill is sealed
isEquipTypeSealed(etypeId) - checks if battler's equip type is sealed
isDualWield() - checks if battler can dual wield
isGuard() - checks if battler is guarding
recoverAll() - removes all states, restores HP and MP to max
hpRate() - checks HP rate of battler
mpRate() - checks MP rate of battler
tpRate() - checks TP rate of battler
b.hpRate() < 0.5 ? b.hp-1 : 100;
isActor() - checks if battler is actor
isEnemy() - checks if battler is enemy
escape() - escapes from battle
b.escape() (makes enemy run away)
consumeItem(item) - eat up an item
a.consumeItem($dataItems[15]); 100
For actor only:
currentExp() - current EXP
currentLevelExp() - EXP needed for current level
nextLevelExp() - EXP needed for next level
nextRequiredExp() - EXP left until next level
maxLevel() - max level of actor
isMaxlevel() - is actor max level (true/false)
hasWeapon() - is actor wielding a weapon (true/false)
hasArmor() - is actor wearing any armor (true/false)
clearEquipments() - unequip everything actor is wearing
isClass(gameClass) - checks if actor is of a class (gameClass - $dataClasses[ID])
hasNoWeapons() - checks if actor doesn't have any weapons
levelUp() - levels actor up
levelDown() - level actor down
gainExp(exp) - gives actor exp
learnSkill(skillId) - makes actor learn a skill
forgetSkill(skillId) - makes actor forget a skill
isLearnedSkill(skillId) - checks if actor has a skill learned
actorId() - returns Actor's ID
For enemy only:
enemyId() - returns Enemy's ID
What about Math? Can we use Math methods inside the formula?
Yup, you totally can.
Math.random() - returns a random number between 0 and 1 (0 <= n < 1)
Math.min(numbers) - returns a minimum number from provided numbers.
E.g. Math.min(10, 50, 40, 200) - would return 10.
Math.max(numbers) - returns a maximum number from provided numbers.
E.g. Math.max(10, 50, 40, 200) - would return 200.
Math.round(number) - rounds a number to nearest integer.
Math.ceil(number) - rounds the number up to nearest integer.
Math.floor(number) - rounds the number down to nearest integer.
Math.rand() returns a number between 0 and 1, but can we get a random number between 1 and 100? Or 5 and 200?
No problem:
Math.floor(Math.random()*100)+1
^ That would return a number between 1 and 100. If we didn't add 1 at the end, it'd only return a number between 0 and 99.
But that's a lot of text? Could we simplify somehow?
Thankfully, there's a method in rpg_core.js that adds Math.randomInt(max);
So we can write the same using:
Math.randomInt(100)+1
I don't understand the formula "paramPlus()", I tested it in rpg maker but it doesn't do nothing, i don't find the bonus of the parameter.Please note:
A discussion has already been started about different things you can do with these formulas so please direct those comments and question to the appropriate thread.
https://forums.rpgmakerweb.com/index.php?threads/rmmv-damage-formula-ideas-and-help.47099/
A link to the list of script equivalents of event commands
https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-script-call-list.46456/
Damage Formulas 101
MV Edition
You probably wondered how to make a skill do more damage against enemies with a state, or heal more if player has a state, or deal exactly half of enemy's HP. And so on.
All of that and more can be done through custom damage formula.

Basics:
Type - sets what does the formula damage or heal.
None - Nothing, no damage will be dealt.
HP Damage - HP will be damaged
MP Damage - MP will be damaged
HP Recover - HP will be restored
MP Recover - MP will be restored
HP Drain - Deals damage to enemy HP and restores that much HP for attacker
MP Drain - Deals damage to enemy MP and restores that much MP for attacker
Element - Sets which element to use. Normal attack - means will use same element as weapon.
Variance - How will damage fluctuate. E.g. If skill formula says it deals 100 damage and variance is 20%, the skill will deal between 80 and 120 damage.
Critical - Can skill critically hit, dealing increased damage by 300%.
And now, the actual fun part - formulas!
It decides how much damage will opponent take or ally will heal.
Let's dissect one of basic formulas that come with RPG Maker MV - Fire
100 + a.mat * 2 - b.mdf * 2
What do things like a and b mean?
a - attacker
b - defender
So if Actor Glasses were to cast Fire on a Slime. a would be Glasses and b would be Slime.
Meaning the takes double of Glasses mat (Magic Attack) parameter and subtracts double of Slime's mdf (Magic Defense) parameter and adds that to the 100 in the beginning ofthe formula.
E.g. Glasses has 100 mat and Slime has 20 mdf. If we were to convert fomula using those numbers, we'd have - 100 + 100*2 - 20*2, after calculation we see with those parameters Fire would deal 260 damage if there were no variance.
But only last number in the formula deals damage. If you had 2 lines of formula. (semicolon ; tells where line ends for the program)
E.g. a.atk; a.atk*2
Only a.atk*2 would be calculated for damage.
Are there more letters other than a and b for the formulas?
Yes. There are variables. Which are used like this: v[ID]. ID - index of the variable.
So you could have a skill that gets stronger the higher variable is.
E.g. v[10] * 2 - b.def * 3
Is there a way to make skill even more complex, e.g. if some variable is over 100, deal extra damage?
Yes, in that case we can use if else statements.
How if else statement looks:
Code:
Code (Text):
if (statement)
{
formula1;
}
else
{
formula2;
}
But how to write it to the damage formula?
It only has 1 line!
Just write everything together~
Code (Text):
if (statement) { formula1; } else { formula2; }
E.g.:
Code (Text):
if (v[10] > 100) { a.atk*4 - b.def*2 } else { a.atk*2 - b.def*2 }
Which can be shortened to this if you're using only 1 line of formula.
Code (Text):
if (statement)
formula1;
else
formula2;
E.g.:
Code (Text):
if (v[10] > 100) a.atk*4 - b.def*2; else a.atk*2 - b.def*2;
And you can shorten it even further using ternary operator (my favorite one):
statement ? formula1 : formula2;
E.g.:
Code (Text):
v[10] > 100 ? a.atk*4 - b.def*2 : a.atk*2 - b.def*2;
Symbols for statements:
> - more than
< - less than
>= more than or equal to
<= less than or equal to
=== equal to
&& and
|| or
!== not equal
! not
Examples:
v[10] > 100 ? 1000 : 100; (If variable 10 is more than 100, it'll deal 1000 damage, else it'll only deal 100)
v[10] < 100 ? 1000 : 100; (If variable 10 is less than 100, it'll deal 1000 damage, else, it'll only deal 100)
v[10] >== 100 ? 1000 : 100; (If variable is 100 or more, it'll deal 1000 damage, else it'll only deal 100)
v[10] <== 100 ? 1000 : 100; (If variable is 100 or less, it'll deal 1000 damage, else it'll only deal 100)
v[10] === 100 ? 1000: 100; (If variable is equal to 100, it'll deal 1000 damage, else it'll only deal 100)
v[10] > 50 && v[11] >== 25 ? 1000 : 100; (If variable 10 is more than 50 and variable 11 is 25 or more, it'll deal 1000 damage, else it'll only deal 100)
v[10] > 50 || v[11] > 50 ? 1000 : 100; (If variable 10 is more than 50 or variable 11 is more than 50 then it'll deal 1000 damage, it'll only deal 100)
v[10] !== 100 ? 1000 : 100; (If variable 10 is not equal to 100, it'll deal 1000 damage else it'll only deal 100)
What about parameters to use for a and b?
Here's a whole list of them:
Current: (All flat numbers, e.g.: 900, 999, 11)
level - current level (Actor only by default)
hp - current hp
mp - current mp
tp - current tp
Params: (All flat numbers, e.g.: 1337, 7331, 156)
mhp - max hp
mmp - max MP
atk - attack
def - defence
mat - magic attack
mdf - magic defence
agi - agility
luk - luck
XParams: (All decimal numbers symbolizing percent, e.g. 1.0, 0.5, 0.75, 2.44 would be 100%, 50%, 75%, 244%)
hit - Hit rate
eva - Evasion rate
cri - Critical rate
cev - Critical evasion rate
mev - Magic evasion rate
mrf - Magic reflection rate
cnt - Counter attack rate
hrg - HP regeneration rate
mrg - MP regeneration rate
trg - TP regeneration rate
SParams:(All decimal numbers symbolizing percent, e.g. 1.0, 0.5, 0.75, 2.44 would be 100%, 50%, 75%, 244%)
tgr - Target Rate
grd - Guard effect rate
rec - Recovery effect rate
pha - Pharmacology
mcr - MP Cost rate
tcr - TP Charge rate
pdr - Physical damage rate
mdr - Magical damage rate
fdr - Floor damage rate
exr - Experience rate
How about changing HP/MP/TP?
gainHp(value) - restores HP by value
gainMp(value) - restores MP by value
gainTp(value) - restores TP by value
setHp(hp) - sets HP to value
setMp(mp) - sets MP to value
setTp(tp) - sets TP to value
E.g. a.setHp(a.mhp)
E.g. a.setHp(a.hp + 100)
clearTp() - sets TP to 0
What about advanced stuff where you can influence formulas with states?
We got all that!
isStateAffected(stateId) - checks if battler has state inflicted to them.
E.g. b.isStateAffected(10) ? 10000 : 1;
isDeathStateAffected() - checks if battler has death state inflicted to them.
E.g. b.isDeathStateAffected() ? 10000 : 1;
resetStateCounts(stateId) - refreshes how long state will last for the battler
if (b.isStateAffected(10)) b.resetStateCounts(10); 100
updateStateTurns() - shortens all states on battler by 1 turn
b.updateStateTurns(); 100
addState(stateId) - adds state to the battler
if (!b.isStateAffected(10)) b.addState(10); 100
isStateAddable(stateId) - checks if state can be added to the battler
c=100; if (b.isStateAddable(10)) b.addState(10); else c=4000; c
removeState(stateId) - removes state from the battler
if (a.isStateAffected(10)) a.removeState(10); 0
What about buffs? Can we buff and debuff battlers?
Yes!
addBuff(paramId, turns) - adds a buff for a parameter
a.addBuff(0, 3); b.def*10
addDebuff(paramId, turns) - adds a debuff for a parameter
b.addDebuff(2, 10); 9999
removeBuff(paramId) - removes a buff or debuff from a battler
removeAllBuffs() - removes all buffs and debuffs from a battler
Parameter IDs
0 - Max HP
1 - Max MP
2 - Attack
3 - Defence
4 - Magic Attack
5 - Magic Defence
6 - Agility
7 - Luck
General Battler Stuff
die() - kills the battler
b.die(); 0
revive() - revives the battler
a.revive(); 1000
paramBase(paramId) - gets base parameter
a.paramBase(3)*10 - b.def*2
paramPlus(paramId) - gets the bonus of parameter
a.paramPlus(3)*2 - b.def*2
paramMax(paramId) - gets max possible value of parameter
b.paramMax(0)
elementRate(elementId) - checks element rate of the battler (rate being decimal numbers representing %)
b.elementRate(10) >== 0.5 ? 10000 : a.mat*4;
isStateResist(stateId) - checks whether the battler resists state
c=0; b.isStateResist(10) ? c+=2000 : b.addState(10); c
isSkillTypeSealed(stypeId) - checks if battler's skill type is sealed
isSkillSealed(skillId) - checks if battler's skill is sealed
isEquipTypeSealed(etypeId) - checks if battler's equip type is sealed
isDualWield() - checks if battler can dual wield
isGuard() - checks if battler is guarding
recoverAll() - removes all states, restores HP and MP to max
hpRate() - checks HP rate of battler
mpRate() - checks MP rate of battler
tpRate() - checks TP rate of battler
b.hpRate() < 0.5 ? b.hp-1 : 100;
isActor() - checks if battler is actor
isEnemy() - checks if battler is enemy
escape() - escapes from battle
b.escape() (makes enemy run away)
consumeItem(item) - eat up an item
a.consumeItem($dataItems[15]); 100
For actor only:
currentExp() - current EXP
currentLevelExp() - EXP needed for current level
nextLevelExp() - EXP needed for next level
nextRequiredExp() - EXP left until next level
maxLevel() - max level of actor
isMaxlevel() - is actor max level (true/false)
hasWeapon() - is actor wielding a weapon (true/false)
hasArmor() - is actor wearing any armor (true/false)
clearEquipments() - unequip everything actor is wearing
isClass(gameClass) - checks if actor is of a class (gameClass - $dataClasses[ID])
hasNoWeapons() - checks if actor doesn't have any weapons
levelUp() - levels actor up
levelDown() - level actor down
gainExp(exp) - gives actor exp
learnSkill(skillId) - makes actor learn a skill
forgetSkill(skillId) - makes actor forget a skill
isLearnedSkill(skillId) - checks if actor has a skill learned
actorId() - returns Actor's ID
For enemy only:
enemyId() - returns Enemy's ID
What about Math? Can we use Math methods inside the formula?
Yup, you totally can.
Math.random() - returns a random number between 0 and 1 (0 <= n < 1)
Math.min(numbers) - returns a minimum number from provided numbers.
E.g. Math.min(10, 50, 40, 200) - would return 10.
Math.max(numbers) - returns a maximum number from provided numbers.
E.g. Math.max(10, 50, 40, 200) - would return 200.
Math.round(number) - rounds a number to nearest integer.
Math.ceil(number) - rounds the number up to nearest integer.
Math.floor(number) - rounds the number down to nearest integer.
Math.rand() returns a number between 0 and 1, but can we get a random number between 1 and 100? Or 5 and 200?
No problem:
Math.floor(Math.random()*100)+1
^ That would return a number between 1 and 100. If we didn't add 1 at the end, it'd only return a number between 0 and 99.
But that's a lot of text? Could we simplify somehow?
Thankfully, there's a method in rpg_core.js that adds Math.randomInt(max);c
So we can write the same using:
Math.randomInt(100)+1
I olso tried add a adventage to the parameter but nothing happend.
Someone who understand the funtion and description of the formula who can help me? -
Wow, I made this post so long ago.. I'm so glad to see people are still benefiting from it :)
(Sorry mods for the off topic post, just have to show some appreciation)
I love you all... especially you @Shaz lol <3 -
Edit: removed because I found a more active thread to ask the same question, as this one appears to have been dead a while
RMMV Damage Formula - ideas and help