Damage Formulas 101

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
531
Reaction score
232
First Language
English
Primarily Uses
RMMV
Code:
Math.min(5, your formula here)
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
531
Reaction score
232
First Language
English
Primarily Uses
RMMV
Math.min will work in MZ, at least. It's part of core JavaScript.
 

MerlinCross

Veteran
Veteran
Joined
Jun 8, 2015
Messages
208
Reaction score
88
First Language
English
Primarily Uses
How would I avoid getting a Decimal in my numbers?

Example; I have a skill that cuts TP in half. But it will leave me with say .5 at times. So

a.setTp(a.tp / 2)

Used at 5 TP will make the user's TP, 2.5. I'd like to avoid that but how?
 

MetalKing11417

Veteran
Veteran
Joined
Jul 7, 2018
Messages
80
Reaction score
52
First Language
english
Primarily Uses
RMMV
How would I avoid getting a Decimal in my numbers?

Example; I have a skill that cuts TP in half. But it will leave me with say .5 at times. So

a.setTp(a.tp / 2)

Used at 5 TP will make the user's TP, 2.5. I'd like to avoid that but how?
Are you talking about within the formula or once the formula has ended? Because after the formula is finished, the system automatically rounds the result, because items like HP and TP only accept integers.
 

MerlinCross

Veteran
Veteran
Joined
Jun 8, 2015
Messages
208
Reaction score
88
First Language
English
Primarily Uses
Are you talking about within the formula or once the formula has ended? Because after the formula is finished, the system automatically rounds the result, because items like HP and TP only accept integers.
I'm talking about this.

Guard Skill
Formula: a.setTp(a.tp / 2)

This should cut TP in half. What happens when it's left over as a Decimal? Well I don't know what the fix is but would like to as I get this. Not sure what would happen if I tried it for HP as well.
2020_10_16_22_49_58_684_4775.png
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
805
Reaction score
438
First Language
Poland
Primarily Uses
RMMV
@MerlinCross
Math.floor( a.setTp(a.tp / 2) ) but preferable way is

Math.floor( a.setTp(a.tp * 0.5) )
 

MerlinCross

Veteran
Veteran
Joined
Jun 8, 2015
Messages
208
Reaction score
88
First Language
English
Primarily Uses
@MerlinCross
Math.floor( a.setTp(a.tp / 2) ) but preferable way is

Math.floor( a.setTp(a.tp * 0.5) )
No that still doesn't seem to work. And it's not a plugin problem before people suggest that, I'm trying this with an empty new project.
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
805
Reaction score
438
First Language
Poland
Primarily Uses
RMMV
Aaahhh now I see where is error:

a.gainTp(Math.floor( a.maxTp()*0.5) )
 

MerlinCross

Veteran
Veteran
Joined
Jun 8, 2015
Messages
208
Reaction score
88
First Language
English
Primarily Uses
Aaahhh now I see where is error:

a.gainTp(Math.floor( a.maxTp()*0.5) )
And now I just gain a flat 50.

I'm just gonna deal with Decimal being there for this little demo idea thing. Hopefully shouldn't break the game.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
531
Reaction score
232
First Language
English
Primarily Uses
RMMV
Try a.setTp(Math.floor(a.tp / 2)), or maybe a.gainTp(-Math.floor(a.tp / 2)).
 

Sir_Titas

Villager
Member
Joined
Jul 22, 2013
Messages
15
Reaction score
0
First Language
english
Primarily Uses
N/A
ok so I have done something wrong with my formula and I have no idea what,
my formula is (a.atk * 4 * (Math.floor (Math.random() * v[20] ) + 1)) - (b.def * 2),
but I know for a fact it is not working because on the test enemy it is giving a solid 50 to 60 each time with actor attack being 18 and enemy defense 25 with the dice variable (v[20]) being at 48, now it should be randomized with the maths between 22 and 3406 but it is not, does anyone know what is going on here.

ps. the dice variable is controlled by a custom armor slot with different types of dice and in this example, I am using a pair of 24 sided dice and I know that function works.

edit. ok, I am an idiot, I did not realize there was an error in my code the several times I looked at it. :hswt2:
 
Last edited:

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

Latest Threads

Latest Posts

Latest Profile Posts

"I want custom, more lively looking grass for my forest map."

"Just set overworld grass as outside grass."

--RM Wisdom--
Any thoughts on my hexagon map system?
Idk where this post would go, so how do you change the font of the choice selection window? I have a different font for the game so it looks a little odd could someone tell me where this would go on the forum?
RPG Maker MZ demo -project with some new features:
I don't really have a use for this guy, I just wanted to build a plague doctor.

Forum statistics

Threads
104,619
Messages
1,007,618
Members
136,095
Latest member
loomer_
Top