Shortening Terms in Damage Formula

Potluckgames

Villager
Member
Joined
Oct 21, 2014
Messages
17
Reaction score
0
First Language
English
Primarily Uses
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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
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)
 

Potluckgames

Villager
Member
Joined
Oct 21, 2014
Messages
17
Reaction score
0
First Language
English
Primarily Uses
That sounds really simple.  Thank you.

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

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,667
First Language
German
Primarily Uses
RMMV
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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
It's possible but would be tricky. I can't think the best way to implement that idea without breaking things.
 

Potluckgames

Villager
Member
Joined
Oct 21, 2014
Messages
17
Reaction score
0
First Language
English
Primarily Uses
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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
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"
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
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
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
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
 
Last edited by a moderator:

Potluckgames

Villager
Member
Joined
Oct 21, 2014
Messages
17
Reaction score
0
First Language
English
Primarily Uses
I won't get a chance to try this out until later this week, due to the holiday, but thanks for the help, everyone.
 

Potluckgames

Villager
Member
Joined
Oct 21, 2014
Messages
17
Reaction score
0
First Language
English
Primarily Uses
I tested TheoAllen's approach last suggestion first and it seems to work perfectly.  Thank you everyone for helping.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,847
Messages
1,016,972
Members
137,561
Latest member
JaCrispy85
Top