Quet

Villager
Member
Joined
Nov 1, 2015
Messages
21
Reaction score
5
First Language
español
Hello, I've been trying to make some attacks to do Minimal damage, however, it seems the damage formula saves negative damage, so even if I have a formula like this (a.atk - b.def)+10 it wont work. I did several tests
Hero has 50 attack, Enemy has 100 defense.

(a.atk - b.def)+10 = 0 damage
(a.atk - b.def)+55 = 5 damage

So it seems the formula saves negative values

Is there a way to make a formula that does minimal damage after parameter calculations?
I was wondering if there is way to put conditions (if), so if the damage is below zero, turn it into zero and add 10 but I don't have enough knowledge in the engine.

Anyone has any idea? Thank you in advance (sorry for my english)
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,243
Reaction score
4,702
First Language
EN
Primarily Uses
RMMZ
Try this:

Math.max(a.atk - b.def, 10)
I.e. "return a.atk - b.def or 10, whichever is larger".

Note that if the Skill/Item has a Variance, that is applied after the damage formula. Other factors like element rates are also applied after the formula.
 

BK-tdm

Waifumancer
Regular
Joined
Jun 21, 2018
Messages
543
Reaction score
1,667
First Language
English
Primarily Uses
RMMV
Note that max returns the bigger number, if you want "damage formula, or 100 minimum" use math.min, as it will return the lowest of the two in case something like player def mitigates the damage and ends up either negative or lower than your intended minimum damage.

You can also use percentages of health with the max/min function in case you want a set attack or skill do a maximum of 25% of the target's hp as damage for example which would be expressed as (a or b .mhp*0.25)
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,243
Reaction score
4,702
First Language
EN
Primarily Uses
RMMZ
if you want "damage formula, or 100 minimum" use math.min, as it will return the lowest of the two in case something like player def mitigates the damage and ends up either negative or lower than your intended minimum damage.
I'm not sure if this is a typo? As I stated, use Math.max(value, cap) for a lower bound:
  • If value < cap it should return cap (larger value);
  • If value ≥ cap it should return value (larger value).
Similarly for an upper bound: use Math.min(value, cap).

My original suggestion can be written as an if-else instead if you prefer, e.g.

var r = a.atk - b.def; r < 10 ? 10 : r
if (a.atk - b.def < 10) 10; else a.atk - b.def
 

Latest Threads

Latest Profile Posts

In twitter, square phoenix had successfully prompted chatgpt to make the mini game watermelon pangpang.

drew some stuff to see how frontview might look. not entirely sold on or off of it yet. "could" work, but something feels missing.
Shower Thoughts: ". . . Scammers would be OP in the Elder Scrolls. They could just get speech 100 and blatantly ask everyone for all of their money, and everyone would think it's a great investment. And then after being robbed blind, they'd say, with a smile on their face, 'need something?' "
Day #2 for advent is compiled. Please, go to their threads to share love! But, if you wanna talk to me…what’s your favorite Christmas carol or holiday song?

Forum statistics

Threads
136,693
Messages
1,268,822
Members
180,406
Latest member
General_Melt
Top