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,322
Reaction score
3,358
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,322
Reaction score
3,358
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

Hi sweethearts! :kaoluv: Check out my review of @EntangledPear's totally oldskool The Stuff Fairy Tales Are Made Of!
When you spend all day at work distracted by things you want to work on or try in your project and then by the time you get home, you are too mentally tired to concentrate so you just browse the forum instead and think of more things you won’t get to work on for a while.
Time to write some enemy behaviors, here's the stream link for those interested.

Call of duty 1&2 had an interesting cheat prevention method. Between levels the game unloads and reloads the engine dll. If you ever employ this method, make sure to include at least an md5 hash check. Otherwise I can just edit that dll and implant cheats into it.
Hi-Fi Rush is one of the coolest games I've seen in a while. I don't have a way to play it so I watched a friend and wow... I really wish I had a powerful enough computer for it.

Forum statistics

Threads
128,277
Messages
1,193,261
Members
168,733
Latest member
Bradenpalm
Top