Goblin Punch and establishing an absolute value in formula

miyanke

Veteran
Veteran
Joined
Dec 2, 2015
Messages
73
Reaction score
12
First Language
Spanish
Primarily Uses
RMMZ
Hi!
Before anything sorry for my english, this is a difficult dubt and I will try my best to be understood. Please excuse my english and ask me anything (and correct me) if it's not clear enough.

I'm trying to create "Goblin Punch" similar to FF9 Version in MZ:
The damage dealt increases the closer the caster's level is to the target's. It is also affected by the caster's strength and the target's Defense, as well as any status effects.

I have VS Enemy levels, so I can use a.level and b.level in the formulae.

I created a formula, but I need to make a value absolute to make it work (I don't know if this is how it is said in english |x|).

My formula is the next one, but I still didn't know the exact value of the base damage (20 in the original), so let's call it just "base damage" until then:
Code:
c = base damage ;
g = a.atm+a.level ;
e = (g/8) + 1 ;
d = Math.randomInt(e) + g ;
h = |a.level-b.level| ;
f = 100-(h*10) ;
a.level==b.level ? c*d : c*(f/100)+1
or
Code:
a.level==b.level ? 20*Math.randomInt((a.atm+a.level/8) + 1) + a.atm+a.level : 20*(100-(|a.level-b.level|*10)/100)+1

I'll try to explain, as I said I'm trying to use the original formula. I know I can substitute so many variables in just one long formula, but I wanted to cut it to explain, and ask for help.

First is to determine "g", that is the base in the original formula, what is the min number of times "c" will repeat if levels are equals (so It's different each time you hit, but always is c*g)

I needed a random between "g" and "g"+"g"/8, so I made a Math random of "g"/8 and then add "g".

The hard part is the second: suppose "c" is the 100% I needed to transform the differences between the levels into a percentage, the problem is that I need to make this value "h" (a.level-b.level) as an absolute, because I can't know what is bigger to be first, and I don't know how to set it in the formulae [I used the bars because it's how mathematically is written, but I don't know if this is right].

Once I have the difference, aka "h" as an absolute value I can transform it into a percentage 100-[h*10].

Here I have my second question: if the difference is 1, the effectiveness of the atack is 90% "c", if the difference is 10, the effectiveness of the atack is 0% "c". What if the difference is 11? will it heal? Is there anyway to set negative numbers as 0?

Then I added +1, because I don't like the "no-damage" pop up, so 1 damage is always good.

In resume:
  • How can I set an absolute value in formula?
  • How can I transform a negative value into 0?
Thank you A LOT!
 
Last edited:

Maliki79

Veteran
Veteran
Joined
Mar 13, 2012
Messages
811
Reaction score
353
First Language
English
Primarily Uses
N/A
Hi there. I tried converting a few of the lines to hopefully match up and explain what you needed.

Check below:

Code:
var c = 20; //base damage
var g = a.mat + a.level; //Caster Magic Attack plus caster level
var e = (g/8) + 1;
var d = Math.randomInt(e) + g;
var h = Math.abs(a.level - b.level); // Absolute value of level diff between target and caster
var f = 100 - (h * 10);
var dam = a.level == b.level ? c * d : c * (f/100) + 1; // store damage in a variable to check value later
return Math.max(dam, 1); // Will make damage 1 if the calculations equal 0 or less

Reply back if you need more help or I don't answer you correctly here.
 

miyanke

Veteran
Veteran
Joined
Dec 2, 2015
Messages
73
Reaction score
12
First Language
Spanish
Primarily Uses
RMMZ
In my place we say ¡Olé! (in fact the stress is in the O)
Yes! Math.abs was what I was looking for.

One more question, Can I write more than one line in the formula or should I transform it to a line?
 

Maliki79

Veteran
Veteran
Joined
Mar 13, 2012
Messages
811
Reaction score
353
First Language
English
Primarily Uses
N/A
You can if you know how to make your own plugin.
You can put that formula in the file then load it up and call it in the damage formula.
(If you don't understand what I said, you probably will need help making the file.)

Other wise, you would need to pack all that in the one line of your damage formula.
 

miyanke

Veteran
Veteran
Joined
Dec 2, 2015
Messages
73
Reaction score
12
First Language
Spanish
Primarily Uses
RMMZ
In one line, it's late to check it, but this might work…

Code:
Math.max(a.level == b.level ? 20*(Math.randomInt((a.mat + a.level/8) + 1) + a.mat + a.level) : 20*((100 - (Math.abs(a.level - b.level) * 10))/100),1)
 

Maliki79

Veteran
Veteran
Joined
Mar 13, 2012
Messages
811
Reaction score
353
First Language
English
Primarily Uses
N/A
Whoa! That's quite the code you got there!

Looks ok at first glance.
Yeah. Test it when you can.
I'd love to hear the results!
 

miyanke

Veteran
Veteran
Joined
Dec 2, 2015
Messages
73
Reaction score
12
First Language
Spanish
Primarily Uses
RMMZ
I tested it in with LV50 characters and enemiess +5 -10 levels.
The results with a 20 as base damage is damage of 18 if they are the same level, and 16 if its 48.
With 100 as base damage, it dealt 98 damage if the same level and 2 if 46.

Does it work? Yes. As I have planned? Not exactly, I think the maths should be adapted and reviewed.

If there are any ideas about it, share it please.
 

Maliki79

Veteran
Veteran
Joined
Mar 13, 2012
Messages
811
Reaction score
353
First Language
English
Primarily Uses
N/A
Well, firstly, why not put the code exactly as I did it?

JavaScript:
var c=20; var g = a.mat+a.level; var e = (g/8)+1; var d = Math.randomInt(e)+g; var h = Math.abs(a.level-b.level); var f = 100-(h*10); var dam = a.level == b.level ? c * d : c * (f/100) + 1; Math.max(dam, 1);

(I tried it in MZ and I can at least say it all fit in the formula box.)
I don't have enemy levels, so I can't try it out.

If the numbers are still off, remember the main areas where you can make changes:

The Magic Attack stat of the caster,
The levels of caster and target,
or the base damage.

Any of those three will make a noticeable change in the damage.
Also, just what kind of numbers were you expecting?
Equal level does?
Level +-10 does?

Basically, just make some conscious tweaks and you should get the code the way you want.
Eventually...

(I hate overly complicated damage formulas myself...)
 

Latest Threads

Latest Posts

Latest Profile Posts

Aaaaannd published my game's tech demo. :D

Feel free to download and play it. And give feedback!
Hey everyone, we know that the edit bar is missing. We're working on it. You can talk about it in the announcement here: https://forums.rpgmakerweb.com/index.php?threads/forum-errors-missing-edit-bar-etc.132715/
So, explain why we can no longer use BBC code or smilies in our posts? This sparks much sadness...
Are we now stuck with WYSIWYG ? I cannot revert back my posts to good old raw text ?
I'm wondering if I may be putting too many things into one map. A story, within a story, within a story . . . it's fun, but I can't shake the feeling that it may be better to scrap some of it, and use it for another map. I'm not sure what to do.

Forum statistics

Threads
107,793
Messages
1,032,237
Members
139,939
Latest member
nachteulen
Top