Multi-Variable Formulas

So I recently grew bored of my (a.atk + a.atk + a.agi) formula for my physical attacks/skills. For my project, ATK(Strength) is the primary physical dmg stat, but AGI(Dexterity) serves as a secondary bonus to physical damage. This is because AGI also increases Hit, Crit, & Counter chances. Therefore the dmg bonus portion of the stat serves to increase the AGI stat's weight/value to match that of ATK (which also increases Crit Mult. btw) and ideally all other stats. Anyways, here's what I've come up w/...

Before:
(a.atk + a.atk + a.agi)<-I would normally add a coefficient <1 for normal attacks (e.g. *0.5)
After:
(a.atk * a.agi) / (a.atk + a.level) + a.atk

Of course, I'll be adding coefficients to scale the damage for various skills, but this would be the base from which all physical attacks/skills are derived.

So I'm curious, have you guys come up w/ any interesting formulas that utilize 2 stats in an unequal manner? Btw, you'll notice my formula didn't reference DEF or MDF, and that's simply because I'm using Armor Scaling (Yanfly)...just an FYI. I'm mostly interested in the relationship between variables, not the specific values themselves. Though feel free to discuss whatever you want. 👋
Just as a note:

Its incredibly easy to create a custom plugin to have much more advanced formulas. All you have to do is create a custom function for the Game_BattlerBase.prototype. Like this:
Code:
Game_BattlerBase.prototype.quirky_skill_formula = function(target) {
    // Check if attacker has state id 83, 84 or 85
    const has_state = this.states().some(id => [83, 84, 85].contains(id));
    // variables to store temp damage values
    let damage = 0, extra = 0;
    // check if has any of above states and use mdf if they do, and def otherwise
    if (has_state) {
        damage = Math.max(.6*(this.mat-target.mdf),0);  
        extra = ((this.level||1)*1/10 +1);
    } else {
        damage = Math.max(.6*(this.atk-target.def),0);  
        extra = ((this.level||1)*4/10 +1);
    }
    const switch_id = 1;
    // check if switch 1 is on, if so, do somme more 
    if ($gameSwitches.value(switch_id)) {
        const variable_id = 1;
        // add the value stored in variable 1 onto the extra modifier
        extra += $gameVariables.value(variable_id);
    }
    // check if target is enemy and multiply for lolz
    if (target.enemy()) {
        extra *= 2;
    }
    // check if target is actor and divide for lolz
    if (target.actor()) {
        extra /= 2;
    }
    // make more damage the more times you escaped!!
    extra += $gameSystem.escapeCount();
    // now return this formula
    return damage + extra;
};

You then 'attach' the formula onto a skill or item in the formula box using this:
Code:
a.quirky_skill_formula(b);

Using this approach you are able to create incredibly advanced formulas, or have one formula that all skills use with some base value or something (similar to pokemon)

Have fun with that :*
@?????? Cool, thank you for that. That definitely falls under implementation more than mechanics, but I welcome and appreciate it nonetheless! Btw, what do you use for your "Normal Attack" formula?
As @?????? showed, you can use some very interesting ways to make damage formula work... I actually use the same thing he pointed out and I have an overly complicated melee attack setup. This formula scales very well with both early and late game content for the numbers I like.

Some of the bits in it seem a bit odd, but I have repurposed some of the default uses for things like "Physical Damage Rate" in my game for other parts, so I simply call them as part of the formula if needed instead of letting the default engine do all that fun after-the-fact from the calculation going off.

Code:
Game_Battler.prototype.attack = function(a, b) {
    if (a.isActor()) {
        damage  = (((a.atk+Math.pow((a.atk/10), 2)))*(100/(100.00+b.def))+((a.atk-b.def)/2))
        fi = $gameVariables.value( 8)
        wi = $gameVariables.value( 9)
        wa = $gameVariables.value(10)
        ea = $gameVariables.value(11)
        damage *= ((fi+wi+wa+ea)*0.0025)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.pdr)
        // console.log(a._name+": Melee ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
    else {
        a._mp += a.mmp/10
        damage  = (((a.atk+Math.pow((a.atk/10), 2)))*(100/(100.00+b.def))+((a.atk-b.def)/2))*1.50
        damage *= (b.level*0.05)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.pdr)
        // console.log(a.originalName()+": Melee ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
}

In this example it checks to see if the attacker is a player or enemy, which allows them to both use the same skill, but have a different formula for each. The commented out console.log lines will send the data to the console so I can see the non-critical damage range for the skill for balancing purposes.

and in the formula box for the basic attack skill I just have "a.attack(a,b)" using my version of the setup.
I wouldnt say that I do anything special for any individual skills formula. I just have a ton of scripts that change skill damage for all skills based on certain values, then skills have a base value that is used in the formulas instead of the skill having a unique formula. 😛
Very neat guys, though I noticed only a.atk is used (ignoring defensive portion rn). I'm trying to find inspiration for a formula that utilises 2 stats lol. (mitigation doesnt count, hence ignoring DEF/MDF)

Although that Math.pow() looks interesting...whats the difference between that and using "**"?
Math.pow() allows you to get float values returned (decimal values) instead of always normal integers (0, 1, 2, always a full non-decimal value), so you can more finely tune your calculations. At least in my experience that's how it was going, esp if you are going for decently high damage values by the end game.

I might have explained it kinda bad, lol. so here is a quote from stack overflow

The big difference of math. pow to both the built-in pow and the power operator ** is that it always uses float semantics. So if you, for some reason, want to make sure you get a float as a result back, then math. pow will ensure this property.
How's this look?...
(a.atk * a.agi) / (a.atk + a.level) + Math.pow(a.atk, a.agi / a.level)

Does this formula look like there would be any glaring balance issues? The "a.agi / a.level" exponent component will almost always fall between 1 - 2. (Maybe up to 3 if they min-maxed AGI, but then they'd have crappy ATK lol)

Edit: I'm considering tacking on a "- a.level" to slightly offset that exponent portion.
Edit2: Nvm, that exponent part needs tweaking...it's too OP as it is.
Edit3: Maybe the following perhaps?...
(a.atk * a.agi) / (a.atk + a.level) + Math.pow(a.atk / a.level, a.agi / a.level)
The only way to know for sure how good it would work, make a damage using the formula, but set it to 0 variance and test it with multiple setups:

early player stats vs early enemy stats
early player stats vs mid-game enemy stats
early player stats vs end-game enemy stats

and repeat them with mid-game and end-game stats for the player as well. If you like how the damage seems to be across the board then it would be balanced for your game.

My games damage will be absurd if a player grinds stat+ items at the end, but that is their decision... I was going for something that felt like a Final Fantasy 10's formula where even a few points of attack can greatly increase the final damage based on how much higher attack is than defense (or Intellect vs Spirit for magic).

My formula makes it so that a player can attack an enemy with ~100 defensive stat more and still be able to barely kill them. If the stats are about equal to each other expect to kill enemies in about 3-4 attacks, and if your stat is ~100 over the enemies defense then you will absolutely wreck them without trying most of the time.

Balance is finding the numbers you think feels right for your game 😀 I always try to balance my enemies with same-level attributes for the area to the player taking about 3-4 hits to kill... if a player comes to an area too soon/weak it might be 5-6 hits, while if they have over levelled a bit it might only take 1-2 hits to kill them.



and lets use that formula you made for an example to see how it does with varying stats:

example 1: 10 attack, 10 agility, level 1
(10*10)/(10+1 )+Math.pow(10, 10/1)
(100)/(11)+Math.pow(10, 10)
100/11+10000000000
damage = 10000000010 roughly
(I think there might be an issue with a number this big)---caused by the Pow formula in this example

example 2: 100 attack, 100 agility, level 50
(100*100)/(100+50 )+Math.pow(100, 100/50)
(10000)/(150)+Math.pow(100, 2)
10000/150+10000
damage = 10067 roughly, might be good for a mid-game damage value?

example 3: 1000 attack, 1000 agility, level 100
(1000*1000)/(1000+100)+Math.pow(1000, 1000/100)
(1000000)/(1100)+Math.pow(1000, 100)
(ummm, I can't even make my calculator show this value without being something weird... so not happening)

I am not saying that your formula will not work for your game at all, if you keep very small numbers it MIGHT, but this is more or less just to show that even the slightest mistake when using Math.pow() can cause some seriously large numbers to happen.
I am not saying that your formula will not work for your game at all, if you keep very small numbers it MIGHT, but this is more or less just to show that even the slightest mistake when using Math.pow() can cause some seriously large numbers to happen.
Yea that formula definitely won't work lol. Math.pow is too strong, at least in the form I presented. But yea, I've made spreadsheets w/ various formulas I'm testing and different combinations of stats. I know testing is a key step in balancing, but I'm not sure if I'm even that far yet... I'm still "window shopping" for various formula ideas hehe. All I know is that I need "a.atk*a.agi" somewhere in there and also that ATK should contribute more dmg than AGI.

Would you say exponents are even worth using? I could definitely marginalize its effect, like in your block of code's example.

Oh, for reference, the main stats in my game range from 1 (@lv1 w/o bonuses) to 200 (@lv50 & min-maxed). So the numbers you used in example 2 are spot on, that's why the result was more reasonable lol. It is incredibly difficult to reach 200 in a stat in my game, you pretty much have to sacrifice all other stats to get a single stat to 200.

Edit: I'm considering using ArcTan or a Logistical function of some sort, thoughts?
Ill work on some ideas while I eat dinner and Ill post some back if I can find a good idea 😀

you want a formula using attack, agility, and level mainly? Also, what are you planning for your games max attributes/levels? That way I can test a few setups before making ideas here.
Ill work on some ideas while I eat dinner and Ill post some back if I can find a good idea 😀

you want a formula using attack, agility, and level mainly?
Attack & Agility definitely, the Level was simply used earlier as a way to reduce a quadratic back down to a linear function. Thank you for taking the time to look into this, I greatly appreciate it!🙏

Edit: Hmm, I noticed that "(a.atk*a.agi)/(a.level*a.level)" yields the coefficient I'm looking for that accounts for synergy between ATK & AGI. Now I just gotta come up w/ the rest of it lol...

Edit2: Or maybe simpler is better after all?...a.atk * 2 + a.agi
How about...

Math.pow(a.atk, (1.00+(a.atk*0.001))) + (((a.agi/10)*((a.level/2)+1)) + ((a.atk/10)*(4+a.level)))

EX1: 10 atk, 10 agi, level 1
Math.pow(10, 1.01) + 2 + 5
10 + 2 + 5
damage = 17

EX2: 100 atk, 100 agi, level 50
Math.pow(100, 1.1) + 260 + 540
158 + 260 + 540
damage = 958

EX3: 1000 atk, 1000 agi, level 100
Math.pow(1000, 2) + 5100 + 10400
1000000 + 5100 + 10400
damage = 1015500

This would make it so that early on a single point in attack will be worth a decent amount, but agi will also feel like it adds a fair amount as well. Later in the game attack will start slowly adding more and more per point the larger the value gets.

(PS I really like these damage values, esp if you cap your games damage at 999,999 that formula would almost be perfect, lol)

Edit: Its all up to you, its your game so you make the numbers the way you want them to be. 😀 until you make the attacks/skills you can toss out all the numbers you want. Once they are made is when you can finally decide if you like the outcome. Sometimes simple math is easier, but those easier formula's are also going to be very linear scaling. Some people like linear, some like exponential growth, lol
How about...

Math.pow(a.atk, (1.00+(a.atk*0.001))) + (((a.agi/10)*((a.level/2)+1)) + ((a.atk/10)*(4+a.level)))
Ah, cool...I think the key takeaway here is the "1.00+..." in order to keep the exponent small. Thank you, this gave me some neat ideas. Btw, does it matter if "1.00" is used vs "1" or "1.0"?
I use decimals when I'm expecting decimals in return, its a "bad" habit I guess, but as long as you have a value is all that matters 😀
I use decimals when I'm expecting decimals in return, its a "bad" habit I guess, but as long as you have a value is all that matters 😀
Do you know if there's any effect on precision when using one form over another?
Usually the more decimal places you use in a formula (most of mine use 0.000) the much harder the damage control will be on the final value.

Think of it this way:
1000 * 1 would be 1000
1000 * 0.1 would be 100
1000 * 0.01 would be 10
1000 * 0.001 would be 1

If you set your attack/skill/spell's damage variance using a whole number and the final value was 1000, in this instance the ability would do 0-2000 damage. Set the same skills variance to 0.01 and then it would be 990-1010 damage.

Stuff kinda like that is why I prefer to use decimals in my formula's... it just feels like you have much better control when fine tuning the values to be where they need to be. 😀

I may have picked a bad way of showing the example but I literally just woke up, lol
I just wanted to share this: a.atk ** (1 + a.agi / 1000) aka Math.pow(a.atk, (1 + a.agi / 1000))
I love that I didn't need to use a.level, which makes it much cleaner/simpler. And now the final question: Which formula should I use?...
  1. a.atk * 2 + a.agi
  2. a.atk ** (1 + a.agi / 1000)
Base formula for spells shall be: a.mat ** 2 / (a.mat + a.level) aka Math.pow(a.mat, 2) / (a.mat + a.level))

Edit: Or maybe I should go w/ a.mat ** (1 + a.level / 1000) so it's similar to the melee formula? I've decided to go w/ formula #2 btw.
I like trying to keep all my formula setups as close to the same as I can, it makes changing everything much easier if you need to change the same thing for the most part.

And as long as the numbers suit your game, number 2 seems fair/simple enough 😀

Original thread: https://forums.rpgmakerweb.com/threads/multi-variable-formulas.129769/