Damage Formulas 101

xDRAGOONx

Veteran
Veteran
Joined
Jan 22, 2019
Messages
206
Reaction score
159
First Language
English
Primarily Uses
RMMV
I was wondering if some can help me out here with a formula. I dont want this specific skill to actually deal damage.
What i need is like a Rock, Paper, Scissor format.
So the user will use skill, i want the formula to check for user Hp amount and targets HP amount.
---> If users HP is greater than targets HP ---> add (x) state to target.

The second skill works similar to the first.
--User uses skill, --> check if user HP is greater than targets --> apply (x) state to user & target.

I feel like i need to declare a varible somewhere.
JavaScript:
a.mhp > b.mhp ? addState(stateId) : 0
use 'mhp' for max HP
use 'hp' for current HP

Edited: I hadn't realized this had been answered when I posted this...
 

vulcan2k7

Warper
Member
Joined
Jun 9, 2016
Messages
4
Reaction score
1
First Language
Vietnamese
Primarily Uses
Hello, I'm currently making a damage formula for a class that use bare-hands (Asura) and I would like to make the close combat skills damage based on the defense of the gloves and shoes in the equipment. I've been searching if we can call the equipment stats in the damage formula but haven't found anything yet.
Is it possible to do so?
 

xDRAGOONx

Veteran
Veteran
Joined
Jan 22, 2019
Messages
206
Reaction score
159
First Language
English
Primarily Uses
RMMV
Hello, I'm currently making a damage formula for a class that use bare-hands (Asura) and I would like to make the close combat skills damage based on the defense of the gloves and shoes in the equipment. I've been searching if we can call the equipment stats in the damage formula but haven't found anything yet.
Is it possible to do so?
a.paramPlus(3) will reference the user's defense gained from equipment.
 

vulcan2k7

Warper
Member
Joined
Jun 9, 2016
Messages
4
Reaction score
1
First Language
Vietnamese
Primarily Uses
Thanks for the answer, but is it possible to get the exact value the user got from specific equipment?
My ideal is to create a class that focus on Kick, so damage formula is based on Shoes defense, and a class with close combat that has damage formula based on both Gloves + Shoes defense.
 

Blair Pendragon

Veteran
Veteran
Joined
Jul 15, 2012
Messages
99
Reaction score
44
First Language
English
Primarily Uses
Looking at the options here, I think an old idea I gave up on, is actually possible here... maybe.
DAMAGE MP
I had originally looked up pluggins for this, but none of them were designed "correctly".

The idea:
Put up a buff. While this buff is active, damage you take, has to go through your MP before it goes through your HP.
This does NOT mean your HP is immune to damage intake if you have MP.
This does NOT mean a percentage of the damage goes to MP and HP every time.

example:
You have 9,999hp and 999mp.
The enemy does 5,000 dmg.
you take 999mp dmg, and the remaining 4,001 dmg goes to HP, leaving you with 5,998hp.

Looking at the damage formula, would it be possible to do all of this:
(1) First check to see if the buff is up or not. (Damage MP state)
(2) If so, calculates the dmg it would do based on stats, stores the number. (a.att - b.def is stored)
(3) Checks to see how much MP you currently have, stores the number. (b.mp is stored)
(4) uses mpGain "negatively" so you lose MP, rather than gain it, based on that mp stored number. (mpGain - stored dmg number)
(5) reduces the damage dealt to HP based on the stored MP number. (stored number - the stored mp number (not current number, as MP was reduced))

I dont know if its possible to store all these numbers, and recall them with all these conditional branches, nor how i would even start to attempt such a thing. (Maybe deal HP dmg 1st, before i deal dmg to mp, in the equation?)

EDIT:
here's what i tried c=b.mp; d=a.atk-b.def-c; if (b.isStateAffected(21)) b.gainMp(-d); d; else a.atk - b.def
currently doing 0 dmg, and not lowering targets mp either.
if i remove the b.gainMp part out, it will damage Hp correctly. but once i try to damage the mp, it stops working.
when i do b.gainMp(-(a.atk+b.def)); a.atk-b.def
no "if" statement, just this, it does dmg to hp and mp.
so my currently issue is having an if statement do 2 things, before going to an else formula.
edit: just tried c=b.mp; d=a.atk-b.def-c; if (b.isStateAffected(21)) { if (b.isStateAffected(21)){b.gainMp(-d)} else{d} }else{a.atk - b.def}
figured the result would be to damage mp but not HP (which is what happened), but figured id try.
still cant get all 3 to work. i can get any combination of 2 of 3 to work. (1) check if, (2) dmg mp, (3) dmg HP. (yes, even damage both hp and mp work, just not after an if statement)

Bonus question: how would you allow it to work with yanflys temp HP shields? (takes from MP before it takes from temp HP, and temp HP before normal HP. Unless yanflys by default treats temp hp as just a "current hp" number higher than max hp)

FINAL EDIT: I figured it out. When doing if statements, you can NOT do 2 things. example, you cant apply a buff, a debuff, and do dmg. you can do only ONE thing after an if statement. (idk why) but in the else part, you can do as many multiple things as you want.
so i changed the formula to simply have if(!b.isStateAffected where the "normal" formula happens after the if(! but the actual 2 things i want to happen, due to the buff, happen in the "else"

So it currently looks like
c=b.mp; d=a.atk-b.def-c; if (!b.isStateAffected(21)) a.atk - b.def; else b.gainMp(-a.atk-b.def); d
(I think theres a small error, but this mostly works now, ill fine tune details later)


Thanks for the answer, but is it possible to get the exact value the user got from specific equipment?
My ideal is to create a class that focus on Kick, so damage formula is based on Shoes defense, and a class with close combat that has damage formula based on both Gloves + Shoes defense.
Its not quite the answer you're looking for, but one work around I can come up with, is to have each battle start with an event that checks the party members currently equipped gear.
So it looks to see if anyone has the class/ability you mentioned.
then it checks their boots and gloves, and assigns a variable based on which boots they have, and another based on the gloves.
(This is a LOT of conditional branching, as u have to check for every single piece of gear that can be equipped in that slot)
then in the damage formula, have it add the 2 variables together for the damage.

if you use pluggins that allow you to put states on gear, then you can just check for the states, and make variables that way.
and if you use a pluggin that allows you to make "useless" stats on gear, u can check for those instead.
(some pluggins allow u to add stats to gear which boost certain attacks as well)
 
Last edited:

Andyest

Villager
Member
Joined
Jul 7, 2020
Messages
11
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
Ok, so I have this damage formula, but it have a lot of if and elses, and I pretend to put more.
there is a way to just call a function with all the formula?

My formula right now:

dp = (a.atk*2 - b.def*1.5);dr = (a.agi*2 - b.def*1.5);dm = (a.mat*2 - b.mdf*1.5);((a.isActor() && a.weapons()[0]) ? c = a.weapons()[0].wtypeId : c = 10000);(c<10000 ? ((c===30 || c===31 || c===32 || c===33) ? d = dr : ((c===42 || c===43 || c===44 || c===45 || c===46) ? d = dm : d = dp)) : d = dp);

c is the weapon type and d is the damage. dp is physical weapons, dr is ranged weapons and dm is magical weapons (like wands and staffs).

(If there's an easier way to write this, I apreciate any kind of help :) )
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
869
Reaction score
554
First Language
English
Primarily Uses
RMMV
Ok, so I have this damage formula, but it have a lot of if and elses, and I pretend to put more.
there is a way to just call a function with all the formula?

My formula right now:

dp = (a.atk*2 - b.def*1.5);dr = (a.agi*2 - b.def*1.5);dm = (a.mat*2 - b.mdf*1.5);((a.isActor() && a.weapons()[0]) ? c = a.weapons()[0].wtypeId : c = 10000);(c<10000 ? ((c===30 || c===31 || c===32 || c===33) ? d = dr : ((c===42 || c===43 || c===44 || c===45 || c===46) ? d = dm : d = dp)) : d = dp);

c is the weapon type and d is the damage. dp is physical weapons, dr is ranged weapons and dm is magical weapons (like wands and staffs).

(If there's an easier way to write this, I apreciate any kind of help :) )
Yes, you can just call a function. For example, lets take the first new file I create in almost any project- _formula.js, where I put any sufficiently complex code snippets I want to re-use later. Here's a typical entry:

JavaScript:
// physical atk-def formula, minimum damage 1
var physDmg = function(a, b) {
    var atk = a.atk;
    var def = b.def;
    return Math.min(a.atk - b.def, 1);
};

// magical atk-def formula, minimum damage 1
var magDmg = function(a, b) {
    var atk = a.mat;
    var def = b.mdf;
    return Math.min(a.atk - b.def, 1);
};

// speed-based damage, greatly reduced if you're slower
var swiftStrikeDmg = function(a, b) {
    var atk = a.agi;
    var def = b.agi;
    if (atk > def) return atk;
    else return 0;
}
I add this file to the plugin manager at the very end of the list, and now I can use "swiftStrikeDmg(a, b)" as a damage formula.

This is helpful not just for complex formulas, but also if you use the same formula for a lot of skills and think you might change something about it at some point- if I want to adjust how physical damage works across the board, maybe by setting the minimum damage to atk * 0.1 instead of a flat 1, I can just modify _formula.js, instead of having to touch every individual skill. And if I want to make just one skill work differently, I can either make a new function in the file, or just enter the formula raw, as usual.
 

MetalKing11417

Veteran
Veteran
Joined
Jul 7, 2018
Messages
80
Reaction score
52
First Language
english
Primarily Uses
RMMV
Ok, so I have this damage formula, but it have a lot of if and elses, and I pretend to put more.
there is a way to just call a function with all the formula?

My formula right now:

dp = (a.atk*2 - b.def*1.5);dr = (a.agi*2 - b.def*1.5);dm = (a.mat*2 - b.mdf*1.5);((a.isActor() && a.weapons()[0]) ? c = a.weapons()[0].wtypeId : c = 10000);(c<10000 ? ((c===30 || c===31 || c===32 || c===33) ? d = dr : ((c===42 || c===43 || c===44 || c===45 || c===46) ? d = dm : d = dp)) : d = dp);

c is the weapon type and d is the damage. dp is physical weapons, dr is ranged weapons and dm is magical weapons (like wands and staffs).

(If there's an easier way to write this, I apreciate any kind of help :) )
I'd like to point out that a formula that complicated likely will not function as is, as there seems to be a point where too many operations in the damage formula just causes the engine to throw it away.
 

Andyest

Villager
Member
Joined
Jul 7, 2020
Messages
11
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
Yes, you can just call a function. For example, lets take the first new file I create in almost any project- _formula.js, where I put any sufficiently complex code snippets I want to re-use later. Here's a typical entry:
[...]
So, I put this _formula.js inside the js file and the rpg maker will just know that it's there to be called?
EDIT: Sorry I skipped one line by accident. Thank you.




I'd like to point out that a formula that complicated likely will not function as is, as there seems to be a point where too many operations in the damage formula just causes the engine to throw it away.
Yes, I thought of that too. But this one worked, as I tested, but I need a bigger formula to cover everything.


Thank you very much, guys.
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
531
Reaction score
232
First Language
English
Primarily Uses
RMMV
I'd like to point out that a formula that complicated likely will not function as is, as there seems to be a point where too many operations in the damage formula just causes the engine to throw it away.
That's not based on the size or complexity of the formula. It throws it away if there's an error in the formula. Of course, a large and complex formula is more likely to have errors, especially if you're writing it directly in the damage formula box...
 

DragonDancer

Villager
Member
Joined
Sep 10, 2020
Messages
9
Reaction score
2
First Language
English
Primarily Uses
RMMV
instead of a variable or a state, is it possible to use a switch to change formulas?
 

Andyest

Villager
Member
Joined
Jul 7, 2020
Messages
11
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
I know that you can find the switches by using:

$dataSystem.switches[id]


id being the switch id. But I don't remember how to say if it's on or off.
 

DragonDancer

Villager
Member
Joined
Sep 10, 2020
Messages
9
Reaction score
2
First Language
English
Primarily Uses
RMMV
I know that you can find the switches by using:

$dataSystem.switches[id]


id being the switch id. But I don't remember how to say if it's on or off.
so what I ended up finding was that the proper way to query the value was with
$gameSwitches.value(122) === true

so this worked for me as a damage formula


$gameSwitches.value(122) === true ? 10000 : 25;
 

Andyest

Villager
Member
Joined
Jul 7, 2020
Messages
11
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
so what I ended up finding was that the proper way to query the value was with
$gameSwitches.value(122) === true

so this worked for me as a damage formula


$gameSwitches.value(122) === true ? 10000 : 25;

Oh, right! DataSystem is for the names, only, I believe. thanks.
 

MerlinCross

Veteran
Veteran
Joined
Jun 8, 2015
Messages
208
Reaction score
88
First Language
English
Primarily Uses
I'm trying to work in TP having a value/effect in attacks. But every time I do so I get a big fat white damage 0. even for healing effects. Fast example

a.luck + a.TP

What I think should happen is that you heal based of the user's Luck + Their TP at time of using. But I keep getting a 0.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
531
Reaction score
232
First Language
English
Primarily Uses
RMMV
It should be a.tp instead of a.TP.
 

MerlinCross

Veteran
Veteran
Joined
Jun 8, 2015
Messages
208
Reaction score
88
First Language
English
Primarily Uses
okay thank you Solar_Flare that was me being stupid but other damage related question;

How would you rig up a minimum damage set up in the damage formula?
 

Users Who Are Viewing This Thread (Users: 2, Guests: 3)

Latest Threads

Latest Posts

Latest Profile Posts

Here's the title-screen for the game I'm working on: :LZSgrin:
Oh man I've been struggling with event spawners and Qmovement compatibility for quite a while- went as far as to use a tool just to pick crops :kaocry: but Ritter got their spawner to work with Qmove and I'm screeing! It's still in testing period but just- the feeling of getting over a large gameplay hurdle is a HUGE relief, I'm so thankful to Ritter! It's a cheap paid plugin but totally worth it!
Welp, I just finished my favorite part of RPG making which is creating skills, now onto the tasks I like less so the motivation is lower. At least I'll get to create new ones while designing enemies!
New to MV... Awesome forum, cheers everyone.

Forum statistics

Threads
104,654
Messages
1,007,885
Members
136,143
Latest member
idotine
Top