Shortening Terms in Damage Formula

● ARCHIVED · READ-ONLY
Started by Potluckgames 12 posts View original ↗
  1. I'm currently using a lot of references to element rates in my damage formulas.  If I multiply an attackers element rate by a defenders element rate, it takes up a lot of room in the formula bar.  It is common for a skill to have several multipliers. 

    a.element_rate(11) * b.element_rate(12) + a.element_rate(13) * b.element_rate(14), etc...

    Is there a way to shorten these references to take up less room?

    I imagine I can do a few lines of script to define shorter vocabulary.  Can someone point me in the right direction?  Let's say, I just want to type "a.er(1)" and the formula bar knows I'm referring to the attacker's element rate number 1.
  2. Make an alias for element_rate in Game_Battler. You need to insert a new script

    class Game_Battler alias er element_rateendNow you can do this to get element_rate

    Code:
    a.er(11) * b.er(12) + a.er(13) * b.er(14)
  3. That sounds really simple.  Thank you.

    Out of curiosity, can I redefine "b.element_rate" as "er" (incorporating the "b.")?
  4. yes and no.


    yes, theoretically it is possible - but if you do that, you have to be a lot more carefull with class assignments and where to use what structure.


    If you can script yourself that is no problem - if you can't, you better don't try to use that because b is a placeholder that can't be accessed from anywhere in the scripts.
  5. It's possible but would be tricky. I can't think the best way to implement that idea without breaking things.
  6. Okay.  I'm mostly just curious how versatile the alias command is.  Maybe a better question would be whether I can set "er" equal to an equation rather than just a term. Say, "er" equals (a*b*c*d*e)/f.  That way a couple letters could multiply strength by fatigue rate, by weather conditions, by weapons proficiency, and a dozen other possible multipliers.
  7. I haven't tested this yet, but it might work

    class RPG::UsableItem::Damage alias modified_eval eval def eval(a,b,v) normal = (a.atk * 4 - b.def * 2) modified_eval(a,b,v) endendAnd then if you just put "normal" in formula box, it should be same as "a.atk * 4 - b.def * 2"
  8. TheoAllen said:
    I haven't tested this yet, but it might work

    class RPG::UsableItem::Damage alias modified_eval eval def eval(a,b,v) normal = (a.atk * 4 - b.def * 2) modified_eval(a,b,v) endendAnd then if you just put "normal" in formula box, it should be same as "a.atk * 4 - b.def * 2"
    I haven't tested it, but it shouldn't work.
  9. Tested, and this works

    Code:
    class RPG::UsableItem::Damage  def eval(a,b,v)    normal = (a.atk * 4 - b.def * 2)    [Kernel.eval(@formula), 0].max * sign rescue 0  endend
  10. Potluckgames said:
    Okay.  I'm mostly just curious how versatile the alias command is.  Maybe a better question would be whether I can set "er" equal to an equation rather than just a term. Say, "er" equals (a*b*c*d*e)/f.  That way a couple letters could multiply strength by fatigue rate, by weather conditions, by weapons proficiency, and a dozen other possible multipliers.
     Simple, make a new method and do the formula there instead of aliasing an existing one

    class Game_BattlerBase def er(args) return YOUR_FORMULA_HERE endendlike if I want to shorten the normal attack then I could

    Code:
    class Game_BattlerBase  def normal(    return self.atk*4 - b.def*2  endend
    and you'll simply put a.normal( b ) on your damage formulanow let's say I have another formula that deals more atk damage

    Code:
    class Game_BattlerBase  def super_atk(    return self.atk*8 - b.def*2  endend
    then I'd just use a.super_atk( b ) on my damage formula
  11. I won't get a chance to try this out until later this week, due to the holiday, but thanks for the help, everyone.
  12. I tested TheoAllen's approach last suggestion first and it seems to work perfectly.  Thank you everyone for helping.