Damage formula help

Darkstrife

Villager
Member
Joined
Oct 22, 2017
Messages
16
Reaction score
8
First Language
English
Primarily Uses
RMMV
Hello

In my project I'm creating sort of dice aspect to my formulas utilizing the Math.randomInt() to create custom dice for each of my skills to give me more control on the damage variance for my game.

I have been successful in making formulas that roll multiple dice but in my play testing I've noticed that an issue pops up where if say a high DEF enemy ends up having more defense than the random dice rolled, then nothing will happen and there will be no effect and no damage whatsoever

I've been trying to use IF statements in my damage formula to make it so that if a number is <= to 0 then do a specific # for damage (Basically the damage would be as if the player rolled a 1 on all their dice and the wouldn't add in their ATK bonus.) but every attempt I've made to make this work seems to basically break the skill and then there is no effect whatsoever

I've been reviewing Skunk's Damage Formulas 101 forum post and trying different things but I'm just not seeing why this isn't working.

This is the original formula that I created that does work, but has the problem of occasionally doing nothing when the value is below enemy defense.
(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+a.atk-b.def

Heres the edit I tried to make
if(((Math.randomInt(3)+1)+(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+a.atk-b.def)<=0)5else;(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+(Math.randomInt(3)+1)+a.atk-b.def

I also tried doing something with a smaller number of Math.randomInt in there but it still causes the issue with it breaking the skill and just playing the animation and doing no damage.
(Math.randomInt(3)+1 >= 1) 10

Any tips or thoughts on how to make this work would be greatly appreciated

-Thanks
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
first suggestion: clean up your formula to prevent typos and similiar problems.

Code:
r={your damage formula}; if (r<=0) 5 else; r
haven't checked for typos myself, but r= creates a temporary variable r and stores the value inside to be used only inside that specific damage formula.
 

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
696
Reaction score
215
First Language
Vietnamese
Primarily Uses
RMMV
Tbh, this kind of formula hurts my eyes so much. I couldn't even follow it. You better create a temporary variable like what Andar said, and make use of it.
 

Darkstrife

Villager
Member
Joined
Oct 22, 2017
Messages
16
Reaction score
8
First Language
English
Primarily Uses
RMMV
Sorry for the terrible formula, I'm usually more involved in the graphic and UI Aesthetic sort of stuff and have been trying to get better at this part of game design

I'm thinking the variable is what I need to figure out in general to solve this problem
r={Math.random.Int(3)+1};
now with that variable could I then create a 2nd variable by using a different letter like c for example?
like this
c={r+r+r}
then with these two internal variable in the damage formula it would look something like this
r={Math.random.Int(3)+1}; c={r+r+r}; if (c=<=0) 1 else; c

I cleaned up the formula with the feedback you gave me and did the following. However I'm still getting the issue of it coming up blank, only now it is not generating any numbers.
r={Math.random.Int(3)+1}; z={r+r+r+r}; q={z+a.atk-b.def}; if (q<=0) 5 else; q
I'm curious if its because I'm trying to use other letters like z= and q= to create 2nd and 3rd variables. Am I able to set multiple variables within the formula box like this or do I need to do something outside of the norm for it? I know we have variables for common events and such but that seems like it wouldn't be the right solution for what I'm trying to do.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
r={Math.random.Int(3)+1};
now with that variable could I then create a 2nd variable by using a different letter like c for example?
like this
c={r+r+r}
bad idea - r will never change after it has been defined, which means that you roll one dice and multiply that number by three.


r={Math.random.Int(3)+1}; z={r+r+r+r}; q={z+a.atk-b.def}; if (q<=0) 5 else; q
again, bad idea - the purpose of the variable is to make ONE variable handle the values, it is NOT a good idea to have a sequence of variable definitions in there, even if it should work with the correct syntax.

and you need to remove the {} because that was part of the placeholder, the correct formula for you should be
r=Math.random.Int(3)+1+Math.random.Int(3)+1+Math.random.Int(3)+1 or
r=Math.random.Int(3)+Math.random.Int(3)+Math.random.Int(3)+3 if you combine the +1's
 

Isabella Ava

Veteran
Veteran
Joined
Sep 13, 2016
Messages
635
Reaction score
756
First Language
English
Code:
r = (Math.randomInt(3)+1); z = (r+r+r+r); q = (z + a.atk - b.def); q <= 0 ? 5 : q
 

Darkstrife

Villager
Member
Joined
Oct 22, 2017
Messages
16
Reaction score
8
First Language
English
Primarily Uses
RMMV
Aha I found the solution.

The trick is just encompassing the formula within a Math.max to make it do make it do know less than 5 damage. It makes the formula cleaner too
I've tested the formula below a couple of times and works perfectly never doing below 5 damage - the minimum possible value of the dice that could be rolled for damage


This a formula for a 5d4 + ATK skill if anyone is interested in implementing a damage system that works a little like D&D dice Its what is in my skill and it has worked without issue.


Math.max(Math.randomInt(3)+Math.randomInt(3)+Math.randomInt(3)+Math.randomInt(3)+Math.randomInt(3)+5+a.atk-b.def,5)

Thank you so much Andar, you definitely helped get me rolling in the right direction.

Found this solution on the Steam forums, figured I would link it here as its a pretty helpful post for anyone interested.
 
Last edited:

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top