Alright, so I hope the title isn't too confusing. Anyways, I really enjoy the formula function that allowes me to create my own damage formulas, and it works most of the time just fine, but sometimes, I feel like either I did something wrong, or the maker interprets my formula the wrong way, anyway, to the problem.
I'm using a resistance-based system in my game, similar to the MMORPG Dofus. Just to explain it real quick, it reduces the amount of damage taken by a percentage, equal to the defense stat of said attack type.
So I did a little thinking, and came up with the following: a.atk - b.def / 100 * a.atk
In theory, this does exactly what it should do, I tried it with some example values, like: "67 - 50 / 100 * 67 = 33,5"
My first thought was, that it might have done it in the wrong order, so I put some brackets here and there: a.atk - ((b.def / 100) * a.atk) , however, this still doesn't work. The result is always, that it does the exact same amount of damage, without reducing any of it, except it hits 100 Resistance, where it does no damage as intended.
Example of what I mean:
Actor attacks with an attack stat of 20, enemy has a physical resistance of 50%. The output should be, without variance, 10, however, it comes out as 20.
Actor attacks with an attack stat of 20, enemy has a physical resistance of 100%. No damage is done, as intended.
I checked some threads for formula suggestions and problems, but I didn't find one that tackled a problem similar to this one, excuse me if one already exists!
Default Attack Formula - No damage reduction
● ARCHIVED · READ-ONLY
-
-
all values in the system are integers by default - that means that everything after the decimal point is dropped by default.
You either need to force float, or sort the formulas to have divisions done last.
Example:
Mathematically. (b.def/100)*a.atk is the same as a.atk * (b.def/100) or even a.atk * b.def / 100
However, the integer reduction forces two different results in the case of a.atk=67 and b.def=50
1) b.def/100 is 50/100 is 0.5 - is zero after integer reduction. Zero multiplied by a.atk remains zero
2) a.atk * b.def is 67 * 50 is 3350. 3350 / 100 is 33.5 - is 33 after integer reduction, much more like the 50%-reduction of 67 that you expected. -
Works like a charm! Thank you very much!
-
Re-opened at Op's request.
-
Thanks for reopening!
Alright, so we still have the "solution" formula. "a.atk - (a.atk * b.def / 100)"
And it seems to work just fine on lower levels, but after I tried a testbattle against an enemy with 0 defense (=> No damage reduction, flat out the a.atk), with the attacker being a level 80 actor with about 200 attack, the damage output was 70.
200 - (200 * 0 / 100)
200 - 0 = ...70?
I'm sorry for consistently asking questions, but I want to give this project my all, and mistakes like that ruin quite the point in leveling up after a while, eh? :) -
Did you remember to zero the variance?
-
Please give a screenshot of the skill with that damage formula.Alright, so we still have the "solution" formula. "a.atk - (a.atk * b.def / 100)"
There are several other points that can affect damage (like the variance mentioned above), and in the formula itself - sometimes even a space more or missing can change the way ruby interprets a formula... -
Alright, I realised what the problem is. Nothing of the things mentioned above though, it was not the variance (it works as intended, and 15% from 200 should still not be at 70), and also no error with the formula.
It seems like, I can't playtest with a higher level, than I set the limit to in the first place.
Say, my actor 1 is only able to level up to 35 in the regular game for example, where the atk stat is at ~70.
In the playtest, I try to use him with a level of 99, where his atk stat would be at ~200.
The damage I'm getting out is the same from 35 onward, so I suppose that's the explanation. Thanks for the quick help tho! :)
