damage mechanic

Mihe

Veteran
Veteran
Joined
Apr 16, 2014
Messages
192
Reaction score
71
First Language
English
Primarily Uses
RMMV
How do you write a damage formula that makes it so you can never deal 0 dmg. You will always deal at the very least 1 dmg even if the target's defense is higher than your attack.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
12,718
Reaction score
13,123
First Language
English
Primarily Uses
RMVXA
Most do it with a plug-in, and the plug-in is set up so that it sets all damage to 1 if it computes it should be 0. Otherwise you can use a javascript command to do this in the damage formula, or just by a cute damage formula where getting very low numbers is near impossible.

Moved to MV Support

 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,072
First Language
English
Primarily Uses
RMMV
You can easily do it inside the damage formula:

Code:
formula === 0 ? 1 : formula
In English,
Does the formula equal zero?
If so, put 1 instead. Otherwise, put the formula.

Replace formula with whatever your formula is
 

Mihe

Veteran
Veteran
Joined
Apr 16, 2014
Messages
192
Reaction score
71
First Language
English
Primarily Uses
RMMV


So for example, if a.atk < b.def, the value will return to 0. I can't edit what the value returns to by default. How would I rewrite this?
 

Sauteed_Onion

Mmm Tasty
Veteran
Joined
Dec 13, 2017
Messages
555
Reaction score
3,666
First Language
English
Primarily Uses
RMMV
I believe so. It's what I use, I never messed with it to know.
 

AdamSakuru

[Null_Value]
Veteran
Joined
Mar 14, 2014
Messages
314
Reaction score
170
First Language
English
Primarily Uses
N/A
Yup you are correct!
So I just tested this out:
Code:
Math.max(1, a.atk * 4 - b.def * 2)
And it returned 0 damage on an enemy with maximum defense. What'd I do wrong?
 

Fernyfer775

Veteran
Veteran
Joined
Oct 6, 2013
Messages
1,312
Reaction score
814
First Language
English
I am assuming that if you have variance on the damage formula, that it could be changing the result?
 

Sauteed_Onion

Mmm Tasty
Veteran
Joined
Dec 13, 2017
Messages
555
Reaction score
3,666
First Language
English
Primarily Uses
RMMV
Hmm.. maybe put a ; at the end?
 

Wavelength

Pre-Merge Boot
Global Mod
Joined
Jul 22, 2014
Messages
4,705
Reaction score
3,965
First Language
English
Primarily Uses
RMVXA
The problem with trying to do this kind of stuff with formulas is that it's affected afterwards by variance, elemental weakpoints/resistances, damage rates, critical hits (which could give you a slightly strange 3 damage instead of 1), etc.

That's why plugins like Yanfly's Damage Core are usually the better way to go, although obviously lightweight plugins are better than ones which affect a bunch of stuff you don't want to change. Or, if you know JS, you can change a few lines of code yourself to set the minimum damage to 1 right before it's applied and displayed.
 

WickedWolfy

Touch Fluffy Tail!
Veteran
Joined
Nov 27, 2017
Messages
108
Reaction score
45
First Language
En, De, Ru
Primarily Uses
RMMV
There is always "1 + [formula]", where 1 is a solid number of damage the weapon would do regardless of user.
For example... even in the weakest hands, a sharp blade would still to 1d4 damage, where 1 would be minimum amount possible.
After that, practiced and tried used would do "1 + a.atk - b.def".
A strong character might do "1 + a.atk * a.STRENGTH - b.def"
A not very strong but a nimble character might strike more times, but lighter. "1 + ( a.atk / 2 ) * a.AGILITY - b.def"
You can also write something that would look at the strongest stat out of the two and decide more precisely how the character uses the said weapon. =)

One of the best tool to deduct these I've used was "NPC sheets".
Mei is a made, so she is great with spells, but can still hit sometimes with a knife for 1/2 of its damage, or min = 1
George is a strong fighter - he picks up an ax and applies his strength for x3 damage
And so on.

In my works I prefer to step outside of the simple math formula and work "by character" instead. It does get complex more often than simple, but it looks kinda cool. And if you add "equip comments" ("Oh, a new axe! I can definitely cleave some ork skulls with this!" [George's strength will deal x3 the normal damage of "Battle Axe"])
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
12,718
Reaction score
13,123
First Language
English
Primarily Uses
RMVXA
@WickedWolfy : Actually, 1 + a.atk - b.def can still return 0, as it is all evaulated at once. For example, if your ATK is 5 and the DEF is 50, the math is:

1 + 5 - 50 = -46, which returns 0 in the engine.
 

WickedWolfy

Touch Fluffy Tail!
Veteran
Joined
Nov 27, 2017
Messages
108
Reaction score
45
First Language
En, De, Ru
Primarily Uses
RMMV
Actually, 1 + a.atk - b.def can still return 0
My example was slightly shorthanded. Thus my mention of 1 being "solid number". Thanks for poking holes in my terrible math. =D
Yes, in perfect world a max-0-value (or ceil, or floor... depending on what is the perfect goal) should be taken of the calculation and a solid number added. There are a number of ways math can be done, based on the situation.
I wanted to focus less on the math that was already mentioned and more on assigning class/character damage instead, as per my later examples.

My example with multiplication by strength and/or agility is flawed too, if you want to pick at my terrible short-hand maths. ;)
 

WickedWolfy

Touch Fluffy Tail!
Veteran
Joined
Nov 27, 2017
Messages
108
Reaction score
45
First Language
En, De, Ru
Primarily Uses
RMMV
Fine... You got me into math thinking now. This is along the lines of the formula I would use for my projects, where applicable
Code:
Math.max( Math.floor((Math.random() * 10) + 1), a.atk * Math.max( a.STRENGTH * 2/3, a.AGIL * 1/3 ) - b.def );
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
12,718
Reaction score
13,123
First Language
English
Primarily Uses
RMVXA
I get what you meant. The math.max (for MV) fixes the issue heavily. Or you can do what I do:

(a.atk + STR + 20) * (a.atk) / (b.def + 20) + a.level

The first part will always be >= 0, then the a.level makes sure something positive is added on.
 

WickedWolfy

Touch Fluffy Tail!
Veteran
Joined
Nov 27, 2017
Messages
108
Reaction score
45
First Language
En, De, Ru
Primarily Uses
RMMV
(a.atk + STR + 20) * (a.atk) / (b.def + 20) + a.level
Interesting. How would you write this in English? I am a bit shy using a.atk squared, because this is what you would end up if you open up the parenthesis.

( ( a.atk^2 + STR*a.atk + 20 * a.atk ) / ( b.def + 20 ) ) + a.level
Technically, because level is never lower than zero, and there is no subtraction and only devision, the result will never be less than 1.
Although funny things might happen if the enemy defense is negative 20 =D

Gee... This got me rallied up on damage maths and I even got a plugin idea in mind =\
 
Last edited:

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

Latest Threads

Latest Posts

Latest Profile Posts

I started really hammering down on my game a year ago... annnnd I still haven't actually started yet. I think trying to do all these assets was a bad idea.
Dear RegantCorp.
Your game Bubble Burst $tory sucks! I won't spend 10$ on a skin that looks exactly the same! And now I have Up on the Housetop stuck in my head, and it's not even close to Christmas! Curse you, RegantCorp!
Signed,
Tantan.
HaneHaeterun wrote on PathosFear's profile.
Do you have a link for the time-travelling VN (I assume it's a VN)...? The banner is "disgustingly adorable" and I want in!
I have to rewrite the Kitty Pride presentation. Too much has changed.

Forum statistics

Threads
95,678
Messages
930,983
Members
126,020
Latest member
LolloBlue96
Top