How to make the most of custom formulae. Part #1

I wanted to ask, how you get a damage formula that deals damage based on weapon types?
You can do it by putting something like this into your scripts

Spoiler
class Game_Battler < Game_BattlerBase def Damage_By_Weapon(a, if (a.weapons.select { |item| item.wtype_id == 3 }).size > 0 p 'weapon 03' return formula_3 elsif (a.weapons.select { |item| item.wtype_id == 2}).size > 0 p 'weapon 02' return formula_2 end #of if statement block end #of 'Damage_By_Weapon' methodend #of class
Then your formula box can just say

Code:
a.Damage_By_Weapon(a,
You can do it by putting something like this into your scripts

Spoiler
class Game_Battler < Game_BattlerBase def Damage_By_Weapon(a, if (a.weapons.select { |item| item.wtype_id == 3 }).size > 0 p 'weapon 03' return formula_3 elsif (a.weapons.select { |item| item.wtype_id == 2}).size > 0 p 'weapon 02' return formula_2 end #of if statement block end #of 'Damage_By_Weapon' methodend #of class
Spoiler
Then your formula box can just say

a.Damage_By_Weapon(a,
Thanks for the help, now all I need now is to figure out how to get this so it's unique only to actors, just because the monsters don't seem to do any damage when this script is posted.
add an else part... that would be the one to work for enemies and for actors not having those weapon types...

Code:
    if (a.weapons.select { |item| item.wtype_id == 3 }).size > 0      p 'weapon 03'      return formula_3    elsif (a.weapons.select { |item| item.wtype_id == 2}).size > 0      p 'weapon 02'      return formula_2    else       p 'no weapon'       return formula_4    end #of if statement block
or if you want it such that actors without weapons and enemies will have different formulas
Code:
    if a.enemy?      p 'enemy'      return formula_5    elsif (a.weapons.select { |item| item.wtype_id == 3 }).size > 0      p 'weapon 03'      return formula_3    elsif (a.weapons.select { |item| item.wtype_id == 2}).size > 0      p 'weapon 02'      return formula_2    else       p 'no weapon'       return formula_4    end #of if statement block
Thanks for the help, now all I need now is to figure out how to get this so it's unique only to actors, just because the monsters don't seem to do any damage when this script is posted.
Never mind, it's because the enemy's attack power was too low.
reading the original formula, it wouldn't deal any damage for anyone not using any of the two weapons...

which is why I posted this:

add an else part... that would be the one to work for enemies and for actors not having those weapon types...

Code:
    if (a.weapons.select { |item| item.wtype_id == 3 }).size > 0      p 'weapon 03'      return formula_3    elsif (a.weapons.select { |item| item.wtype_id == 2}).size > 0      p 'weapon 02'      return formula_2    else       p 'no weapon'       return formula_4    end #of if statement block
or if you want it such that actors without weapons and enemies will have different formulas
Code:
    if a.enemy?      p 'enemy'      return formula_5    elsif (a.weapons.select { |item| item.wtype_id == 3 }).size > 0      p 'weapon 03'      return formula_3    elsif (a.weapons.select { |item| item.wtype_id == 2}).size > 0      p 'weapon 02'      return formula_2    else       p 'no weapon'       return formula_4    end #of if statement block
add an else part... that would be the one to work for enemies and for actors not having those weapon types...

if (a.weapons.select { |item| item.wtype_id == 3 }).size > 0 p 'weapon 03' return formula_3 elsif (a.weapons.select { |item| item.wtype_id == 2}).size > 0 p 'weapon 02' return formula_2 else p 'no weapon' return formula_4 end #of if statement blockor if you want it such that actors without weapons and enemies will have different formulas
Code:
    if a.enemy?      p 'enemy'      return formula_5    elsif (a.weapons.select { |item| item.wtype_id == 3 }).size > 0      p 'weapon 03'      return formula_3    elsif (a.weapons.select { |item| item.wtype_id == 2}).size > 0      p 'weapon 02'      return formula_2    else       p 'no weapon'       return formula_4    end #of if statement block
Okay, i got it working.
My turn!

So, I'm trying to get a mechanic going wherein the player characters essentially receive a bonus to damage and healing abilities that's based on their TP amount and level (so it scales with their level). Here's my formula for regular attack as it stands right now:

(a.atk * 4 - b.def * 2) + (a.tp * (a.level / 4))

Problem is, I go into a fight, and the bonus the characters get rapidly becomes quite excessive. One of the DPS-based characters essentially winds up doing 10x their normal damage once the gauge is full. Is my math off somewhere?

I tried scaling it down to a.level / 10, and that seems to get it to numbers more in line with what I wanted, but I just wanted to double-check.

Also, I'm trying to create a skill that does both HP and MP damage at the same time, but I'm not sure how to do that. Any advice? Thanks!
1) let's see... at level 4 and 100 TP, you will deal 100 bonus damage... at level 8 and 100 TP, you will deal 200 bonus damage... and so on...


2) You can damage the MP via the formula bar via something like: b.mp -= amount ; damagerformulaforhp


though I think doing that won't show a message for the MP loss...
That just winds up getting me a NULL attack, even if I put the original damage formula first.

Apparently I can set the effects to include recover MP, and just set that for a negative amount, so I guess that works.
How would I make a formula add a number from 0 to another number. In my game hammers are supposed do nearly random damage, the formula I came up with is: rand(a.atk*6)-b.def*2 my character with an atk of 33 attacking a monster with 6 def only deals from 115 to 155 a hit. Do I have to specify from 0 to a.atk*6 or is my formula just wrong?

Edit: Variance is also set to 0

Edit: Solved it myself, I forgot to specify in the script that the weapon used that skill number. It works fine.
Apologies if this has been answered already, but:

I want most of the healing spells to cure a percentage of damage based on their defense stats - Defense for warriors, Magic Defense for mages and clerics.

What formula should I use?  ((a.def%) * 1.5) or something?
if you need to distinguish which stat, you can check first the class id


so like, assuming classes 1,2,3 uses def, others use mdf


[1,2,3].include?(a.class.id) ? a.def*1.5 : a.mdf*1.5


this is caster based, just change the a's into b's if you want target based


I'm not sure if the id call is right though
if you need to distinguish which stat, you can check first the class id

[1,2,3].include?(a.class.id) ? a.def*1.5 : a.mdf*1.5

this is caster based, just change the a's into b's if you want target based

I'm not sure if the id call is right though
I'll handle it with different skills for each class (First Aid and Cure) rather than by checking class.  Thank you.
My turn!

I need a formula that, on default, uses the user's ATK versus the enemy's DEF. However, if the user's MAT is bigger then ATK, it uses the user's MAT versus the enemy's MDF, and the attack element is set to one particular element.
(a.atk > a.mat) ? a.atk * 4 - b.def * 2 : a.mat * 4 - a.mdf * 2
(a.atk > a.mat) ? a.atk * 4 - b.def * 2 : a.mat * 4 - a.mdf * 2
And the element part? Is that possible?
Change the element box on attack?
Change the element box on attack?
Well no, I want it to use the weapon's element on default for say, swordsmen and archers, so the elemental damage would be slash/pierce. But when a mage attacks he uses his MAT kind of like a 'Mind blast' and element changes to Spirit.
Then can't you make the mage's weapon's element Spirit?

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-the-most-of-custom-formulae-part-1.1143/