Damage Formulas 101

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
399
Reaction score
221
First Language
English
Primarily Uses
RMMV
The damage formula will pretty much let you affect anything you want and as many of them as you want. It's just evaluating the code you're putting in, so I doubt that's the issue.

What happens if you paste my example into your damage formula? If that works but your code doesn't it may be useful if you could copy and paste your damage formula with the extra functions included so we can see what's causing the eval to fail.
 

Nofx670

Villager
Member
Joined
Oct 13, 2019
Messages
6
Reaction score
3
First Language
English
Primarily Uses
RMMV
The damage formula will pretty much let you affect anything you want and as many of them as you want. It's just evaluating the code you're putting in, so I doubt that's the issue.

What happens if you paste my example into your damage formula? If that works but your code doesn't it may be useful if you could copy and paste your damage formula with the extra functions included so we can see what's causing the eval to fail.
The damage formula will pretty much let you affect anything you want and as many of them as you want. It's just evaluating the code you're putting in, so I doubt that's the issue.

What happens if you paste my example into your damage formula? If that works but your code doesn't it may be useful if you could copy and paste your damage formula with the extra functions included so we can see what's causing the eval to fail.
ok I copy and pasted your code which works for adding the state but didn't change the variable Here is the code I wrote for the variable change which seems like it should work.

$gameVariables.setValue(2, 50); a.atk - b.def

would it be that I have named variable 2 should I be using the name instead of the number?
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
399
Reaction score
221
First Language
English
Primarily Uses
RMMV
The code you've shown should work. This still doesn't deal damage?

My immediate suspicions are that you may have a plugin installed that is controlling variable 2, which is either preventing it from being changed or resetting the value immediately after it is changed. I would try turning off your plugins and seeing if the formula works after doing this. If it does it's a plugin causing the issue. If doesn't, it's worth checking that you don't have any other events / formulas changing the value of the variable. These could be common events that are being called by other skills/items, events set up on the troop, parallel / autorun events on the map after the battle, or a similar function being run in a different damage formula.

EDIT: the engine doesn't look for variables by name, it's only by number. As far as I know, it's only the editor that keeps information regarding the variable names. When you're actually in game that information is inaccessible (and this is when your code is running).
 
Last edited:

Nofx670

Villager
Member
Joined
Oct 13, 2019
Messages
6
Reaction score
3
First Language
English
Primarily Uses
RMMV
The code you've shown should work. This still doesn't deal damage?

My immediate suspicions are that you may have a plugin installed that is controlling variable 2, which is either preventing it from being changed or resetting the value immediately after it is changed. I would try turning off your plugins and seeing if the formula works after doing this. If it does it's a plugin causing the issue. If doesn't, it's worth checking that you don't have any other events / formulas changing the value of the variable. These could be common events that are being called by other skills/items, events set up on the troop, parallel / autorun events on the map after the battle, or a similar function being run in a different damage formula.

EDIT: the engine doesn't look for variables by name, it's only by number. As far as I know, it's only the editor that keeps information regarding the variable names. When you're actually in game that information is inaccessible (and this is when your code is running).
Wahoo it works I had an event that was using variable 2 when it shouldn't have been

Thanks again for your help
 

Gia Dreams

Villager
Member
Joined
May 7, 2014
Messages
14
Reaction score
4
First Language
English
Primarily Uses
RMMV
Hi, I know its been awhile. Just figured i'd try here first after banging my head around for hours.

So I have a healer skill going on.

**Skill when State(84) is active boost potency by +50 so = a.isStateAffected(84) ? a.luk + 35 + 50 : a.luk + 35;

I also have on the same skill that when State(82) is active it will give the target 10Mp, so.

a.isStateAffected(82) ? b.gainMp(10) : a.luk + 35.



What my issue is, im trying to have it so that these two lines can exist on the same skill and fire off when called.

I now put it so that the two states will Remove each other ex:

If player applies state 84 to self it will remove state 82 - and so on.



But I cant seem to get the codes to function correctly, it seems that its always one or the other that ones properly or not at all

here is a little break down.



Skill - Bless

base heal = a.luk + 35

When Prayer(State 84) is active + 50 to heal.

When Bless Signet(State 82) is active target gains 10 mp.
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
399
Reaction score
221
First Language
English
Primarily Uses
RMMV
What you've coded re state 82 looks like you don't want any healing to occur when this state is active. I'm not sure if this is intentional so I'll attempt a solution both ways.

Code:
if (a.isStateAffected(82)) {b.gainMp(10); 0;} else {a.luk + 35 + (a.isStateAffected(84) ? 50 : 0);}
Having state 82 applied will mean no healing.

Code:
if (a.isStateAffected(82)) b.gainMp(10); a.luk + 35 + (a.isStateAffected(84) ? 50 : 0);
Having state 82 applied will still heal like normal.
 

Gia Dreams

Villager
Member
Joined
May 7, 2014
Messages
14
Reaction score
4
First Language
English
Primarily Uses
RMMV
What you've coded re state 82 looks like you don't want any healing to occur when this state is active. I'm not sure if this is intentional so I'll attempt a solution both ways.

Code:
if (a.isStateAffected(82)) {b.gainMp(10); 0;} else {a.luk + 35 + (a.isStateAffected(84) ? 50 : 0);}
Having state 82 applied will mean no healing.

Code:
if (a.isStateAffected(82)) b.gainMp(10); a.luk + 35 + (a.isStateAffected(84) ? 50 : 0);
Having state 82 applied will still heal like normal.
Thank you soo much, little sad that I was that close to getting it the many times I kept writing out the code.
life saver!
 

Popnfizzle

Veteran
Veteran
Joined
Dec 28, 2015
Messages
69
Reaction score
174
First Language
English
Primarily Uses
N/A
Is there a way to make an attack do minimum 1 damage. Im wanting even low level creatures to be able to at least do 1 damage to a higher level character.

I tried something like 1+ a.atk - b.def or a.atk - b.def +1

Not sure what Id need to do for this.
 

Gia Dreams

Villager
Member
Joined
May 7, 2014
Messages
14
Reaction score
4
First Language
English
Primarily Uses
RMMV
;_;;_;;_;
I seem to have run into another one.
So I have a skill, it cost no TP to use it. Yet it's damage varies based on the users current TP amount.
Also when users TP is at 100, this skill add a status effect (Blind State 26). I still want it to do damage also while its at 100.

Then I seem to also hit a wall.
Upon using the skill the TP will remain 100, I was trying to find a way that
"When TP is 100 apply state 26, and reset users tp to 1"
I assumed I could just give this skill like a 4 turn cool down, that didn't seem good enough.

I tried the following:

a.tp === 100 ? b.addState(26) : a.atk + a.tp - b.def;
if (a.tp === 100)) b.addState(26) : setTp(0); a.atk + a.tp - b.def;
if (a.tp === 100)) b.addState(26); a.atk + a.tp - b.def - (a.tp === 100 ? setTp(1) : 0);
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
399
Reaction score
221
First Language
English
Primarily Uses
RMMV
I'll run through what each of your formulas is doing so you can see where they're not working.

Code:
a.tp === 100 ? b.addState(26) : a.atk + a.tp - b.def
This is saying if the user's tp is 100 apply the state, if the user's tp is not 100 deal damage.

Code:
if (a.tp === 100)) b.addState(26) : setTp(0); a.atk + a.tp - b.def;
The issue here is that you've used a colon instead of a semi-colon, you're also calling "setTp" on nothing.

Code:
if (a.tp === 100)) b.addState(26); a.atk + a.tp - b.def - (a.tp === 100 ? setTp(1) : 0);
Again, "setTp" is being called on nothing so will fail. Additionaly, setTp returns "undefined", a number - undefined = NaN.

There is one other problem you're likely running into as well. Because the damage formula only evaluates the value of the last line of the code you need to reset the user's tp before the last line, this means a.tp is always going to be 0. The way around this is to store the value of the user's tp in a variable before resetting it. So taking your second attempt we can tweak it to become something like this:

Code:
if (a.tp === 100) b.addState(26); var tp = a.tp; a.setTp(0); a.atk + tp - b.def;
 
Last edited:

Gia Dreams

Villager
Member
Joined
May 7, 2014
Messages
14
Reaction score
4
First Language
English
Primarily Uses
RMMV
I'll run through what each of your formulas is doing so you can see where they're not working.

Code:
a.tp === 100 ? b.addState(26) : a.atk + a.tp - b.def
This is saying if the user's tp is 100 apply the state, if the user's tp is not 100 deal damage.

Code:
if (a.tp === 100)) b.addState(26) : setTp(0); a.atk + a.tp - b.def;
The issue here is that you've used a colon instead of a semi-colon, you're also calling "setTp" on nothing.

Code:
if (a.tp === 100)) b.addState(26); a.atk + a.tp - b.def - (a.tp === 100 ? setTp(1) : 0);
Again, "setTp" is being called on nothing so will fail. Additionaly, setTp returns "undefined", a number - undefined = NaN.

There is one other problem you're likely running into as well. Because the damage formula only evaluates the value of the last line of the code you need to reset the user's tp before the last line, this means a.tp is always going to be 0. The way around this is to store the value of the user's tp in a variable before resetting it. So taking your second attempt we can tweak it to become something like this:

Code:
if (a.tp === 100) b.addState(26); var tp = a.tp; a.setTp(0); a.atk + tp - b.def;
Thank you, i'm still new with working around some of the other formulas.
This one works out just fine :D.

I was wondering, how would I go about writing the formula if I wanted two different things to happen base on the same condition.
EX: TP = 100 or more, add state(26) & set TP to 0.


if (a.tp >= 100) b.addState(26); var tp = a.tp; if (a.tp >= 100) a.clearTp(0); a.atk + 25 + tp - b.def;

^^ That would be the correct way to write it? Sorry not home at the moment to playtest it.
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
399
Reaction score
221
First Language
English
Primarily Uses
RMMV
The easiest way is to just include the 2 things within a set of curly braces after the if (condition). Something like this would work:

Code:
var tp = a.tp; if (tp === 100) {b.addState(26); a.setTp(0);} a.atk + tp - b.def;
You'll notice I've moved the "var tp = a.tp" to the start just to keep the two items occurring within the if statement together.

You could also use two if statements like in your own example, whatever makes it more readable for yourself. :)
 

Gia Dreams

Villager
Member
Joined
May 7, 2014
Messages
14
Reaction score
4
First Language
English
Primarily Uses
RMMV
The easiest way is to just include the 2 things within a set of curly braces after the if (condition). Something like this would work:

Code:
var tp = a.tp; if (tp === 100) {b.addState(26); a.setTp(0);} a.atk + tp - b.def;
You'll notice I've moved the "var tp = a.tp" to the start just to keep the two items occurring within the if statement together.

You could also use two if statements like in your own example, whatever makes it more readable for yourself. :)
Your version looks cleaner, and thanks for the help! Greatly appreciate it.
 

Motteley

Villager
Member
Joined
Nov 19, 2019
Messages
12
Reaction score
0
First Language
English
Primarily Uses
RMMV
I was wondering how I could get a weapon that completely ignores the user's physical/magical attack stat when dealing damage (like a gun for instance), as well as a skill that lets the user deal damage while ignoring the enemy's physical/magical defense (think Luna Λ from Fire Emblem: Three Houses).
 

MetalKing11417

Veteran
Veteran
Joined
Jul 7, 2018
Messages
81
Reaction score
54
First Language
english
Primarily Uses
RMMV
The ignore enemy defense is easy- simply remove the b.Def/b.mdf from the formula or multiply it by whatever fraction you want to get your desired result i.e. a.atk - .5 * b.def or a.atk * 4 - b.def if you are sticking to default formulas.

The ignore the user's attack stat in favor of an innate weapon attribute is a bit more complicated- I think you are going to need to search for plug-ins to get what I think you are wanting done.
 

Motteley

Villager
Member
Joined
Nov 19, 2019
Messages
12
Reaction score
0
First Language
English
Primarily Uses
RMMV
The ignore enemy defense is easy- simply remove the b.Def/b.mdf from the formula or multiply it by whatever fraction you want to get your desired result i.e. a.atk - .5 * b.def or a.atk * 4 - b.def if you are sticking to default formulas.

The ignore the user's attack stat in favor of an innate weapon attribute is a bit more complicated- I think you are going to need to search for plug-ins to get what I think you are wanting done.
Does Yanfly have such a plugin?
 

MetalKing11417

Veteran
Veteran
Joined
Jul 7, 2018
Messages
81
Reaction score
54
First Language
english
Primarily Uses
RMMV
Does Yanfly have such a plugin?
I don't think so. I mean Weapon Unleash will at least get you a similar result by allowing you to replace the standard attack, but that would likely be inefficient as you would likely need to have a new skill for every weapon you want to use it on, and that still doesn't go into other skills.
 

Gia Dreams

Villager
Member
Joined
May 7, 2014
Messages
14
Reaction score
4
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 5)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,845
Messages
1,016,961
Members
137,561
Latest member
JaCrispy85
Top