juan

Villager
Member
Joined
Nov 1, 2015
Messages
15
Reaction score
4
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
4,338
Reaction score
3,375
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

Manga Maker
Veteran
Joined
Jun 21, 2018
Messages
478
Reaction score
1,414
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
4,338
Reaction score
3,375
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 Posts

Latest Profile Posts

Now that I have linklists on large trees and cars, is there any theme that would interest you?
Debugging multiplayer issues... I'm having fun, right?
yay_streaming.jpg

For just starting streaming on the 10th... Definitely not the worst. :LZScheeze:

Granted I need 333.34 hours a month on average to achieve money. So I don't really expect that, but it sure has helped my game dev go much faster.
Proud on how this map turned out.

FnmhDLIXgAAOvIC
I just finally fixed a huge problem that wouldn’t let my game load and would crash it.. I thought that I was gonna have to trash the project and start over lol

Forum statistics

Threads
128,327
Messages
1,193,646
Members
168,813
Latest member
jasper1hu
Top