I and copy and pasting this from another forum but I think you may be able to do this with a special damage formula.
Spoiler
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 damagedMP Damage - MP will be damagedHP Recover - HP will be restoredMP Recover - MP will be restoredHP Drain - Deals damage to enemy HP and restores that much HP for attackerMP Drain - Deals damage to enemy MP and restores that much MP for attackerElement
- 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 - Fire100 + a.mat * 2 - b.mdf * 2What do things like
a and
b mean?
a - attackerb - defenderSo 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*2Only 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 * 3Is 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 (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! notExamples:
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 hpmp - current mptp - current tpParams
: (All flat numbers, e.g.: 1337, 7331, 156)mhp - max hpmmp - max MPatk - attackdef - defencemat - magic attackmdf - magic defenceagi - agilityluk - luckXParams
: (All decimal numbers symbolizing percent, e.g. 1.0, 0.5, 0.75, 2.44 would be 100%, 50%, 75%, 244%)hit - Hit rateeva - Evasion ratecri - Critical ratecev - Critical evasion ratemev - Magic evasion ratemrf - Magic reflection ratecnt - Counter attack ratehrg - HP regeneration ratemrg - MP regeneration ratetrg - TP regeneration rateSParams
🙁All decimal numbers symbolizing percent, e.g. 1.0, 0.5, 0.75, 2.44 would be 100%, 50%, 75%, 244%)tgr - Target Rategrd - Guard effect raterec - Recovery effect ratepha - Pharmacologymcr - MP Cost ratetcr - TP Charge ratepdr - Physical damage ratemdr - Magical damage ratefdr - Floor damage rateexr - Experience rateHow about changing HP/MP/TP?
gainHp(value) - restores HP by valuegainMp(value) - restores MP by valuegainTp(value) - restores TP by valuesetHp(hp) - sets HP to valuesetMp(mp) - sets MP to valuesetTp(tp) - sets TP to valueE.g. a.setHp(a.mhp)E.g. a.setHp(a.hp + 100)clearTp() - sets TP to 0What 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 battlerif (b.isStateAffected(10)) b.resetStateCounts(10); 100updateStateTurns() - shortens all states on battler by 1 turnb.updateStateTurns(); 100addState(stateId) - adds state to the battlerif (!b.isStateAffected(10)) b.addState(10); 100isStateAddable(stateId) - checks if state can be added to the battlerc=100; if (b.isStateAddable(10)) b.addState(10); else c=4000; cremoveState(stateId) - removes state from the battlerif (a.isStateAffected(10)) a.removeState(10); 0What about buffs? Can we buff and debuff battlers?
Yes!addBuff(paramId, turns) - adds a buff for a parametera.addBuff(0, 3); b.def*10addDebuff(paramId, turns) - adds a debuff for a parameterb.addDebuff(2, 10); 9999removeBuff(paramId) - removes a buff or debuff from a battlerremoveAllBuffs() - removes all buffs and debuffs from a battlerParameter IDs
0 - Max HP1 - Max MP2 - Attack3 - Defence4 - Magic Attack5 - Magic Defence6 - Agility7 - LuckGeneral Battler Stuff
die() - kills the battlerb.die(); 0revive() - revives the battlera.revive(); 1000paramBase(paramId) - gets base parametera.paramBase(3)*10 - b.def*2paramPlus(paramId) - gets the bonus of parametera.paramPlus(3)*2 - b.def*2paramMax(paramId) - gets max possible value of parameterb.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 statec=0; b.isStateResist(10) ? c+=2000 : b.addState(10); cisSkillTypeSealed(stypeId) - checks if battler's skill type is sealedisSkillSealed(skillId) - checks if battler's skill is sealedisEquipTypeSealed(etypeId) - checks if battler's equip type is sealedisDualWield() - checks if battler can dual wieldisGuard() - checks if battler is guardingrecoverAll() - removes all states, restores HP and MP to maxhpRate() - checks HP rate of battlermpRate() - checks MP rate of battlertpRate() - checks TP rate of battlerb.hpRate() < 0.5 ? b.hp-1 : 100;isActor() - checks if battler is actorisEnemy() - checks if battler is enemyescape() - escapes from battleb.escape() (makes enemy run away)consumeItem(item) - eat up an itema.consumeItem($dataItems[15]); 100For actor only:
currentExp() - current EXPcurrentLevelExp() - EXP needed for current levelnextLevelExp() - EXP needed for next levelnextRequiredExp() - EXP left until next levelmaxLevel() - max level of actorisMaxlevel() - 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 wearingisClass(gameClass) - checks if actor is of a class (gameClass - $dataClasses[ID])hasNoWeapons() - checks if actor doesn't have any weaponslevelUp() - levels actor uplevelDown() - level actor downgainExp(exp) - gives actor explearnSkill(skillId) - makes actor learn a skillforgetSkill(skillId) - makes actor forget a skillisLearnedSkill(skillId) - checks if actor has a skill learnedactorId() - returns Actor's IDFor enemy only:enemyId() - returns Enemy's IDWhat 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