Improved damage formula scripting

This is not something I need at the moment, but an idea that occurred to me because more and more developers use the damage formula field for special skill effects, and that field has some limitations like the lenght and the readability.

1)

A way to define part of the damage formula outside that field and simply call it from there (with as short a command as possible).

This might be a predefined segment of the script implementing these changes, or perhaps by using comments in a designated common event to store those sequences.

This should allow re-use of components for several skills and allow the developer to exceed the length-limit of the damage formula

2)

Possibility to designate a default first segment

Like the scripts that make the troop events of the first troop applied to all troops, this would designate a damage formula sequence that would be added in front of the regular damage formula before evaluating it.

This would be helpfull in automated state-checks and changes on user/target of the skill, especially if they are actor-based (changes apply to all skills used by that actor/class)

I don't know if that is possible because I don't know how the damage formula is handled internally, but I think many would find such a script usefull.
I would answer the first question

1)

A way to define part of the damage formula outside that field and simply call it from there (with as short a command as possible).

This might be a predefined segment of the script implementing these changes, or perhaps by using comments in a designated common event to store those sequences.

This should allow re-use of components for several skills and allow the developer to exceed the length-limit of the damage formula
I've tried this before. And it works

1. Open script editor

2. Insert a new section just like when u insert a new script

3. Write down this following line

Normal = "a.atk * 4 - b.def * 2"4. Open skill database

5. Write down this following line to your damage formula

eval(Normal)You may write your own damage sequences with other name. Make sure that you have to make the first letter is capitalized
^ Oh so it works even without putting it inside Game_Battler? That's nice to know...

btw, do you really need eval there? the damage formula is evaluated using eval already...
^ Oh so it works even without putting it inside Game_Battler? That's nice to know...

btw, do you really need eval there? the damage formula is evaluated using eval already...
Yes, it might save your life.

If you just put "Normal", the evaluated damage formula return as a string, "a.atk * 4 - b.def * 2". Not a numeric value. Which may cause "took no damage".

The actual code is

eval("Normal")If you put eval in your damage formula, the actual code is

eval("eval(Normal)")Do you see the difference?
oh... so eval only returns the direct result of the passed value? that's good to know... XD
You could also do

def dmg(a,b)return (4*a-2*.to_iendand then call dmg(a.atk,b.def), as explained by Fomar here.

You can make it more generic than that; in fact, I recommend you do. But the call would end up being longer.
oh that's it... the one theo posted was using a variable... that explains a lot...
1)


A way to define part of the damage formula outside that field and simply call it from there (with as short a command as possible).


This might be a predefined segment of the script implementing these changes, or perhaps by using comments in a designated common event to store those sequences.


This should allow re-use of components for several skills and allow the developer to exceed the length-limit of the damage formula
I have a tutorial on that: http://forums.rpgmakerweb.com/index.php?/topic/1716-how-to-make-the-most-of-custom-formulae-part-2/
Thanks. I actually have a question about that. Why does it have to be a.basef() or b.basef() instead of simply basef()? Is it because they are defined in Game_Battler?
Good point. basef should work as well. Now I feel daft.
I'd go with theodoric's approach to storing formulas in constants for the first one.

For the second one, I'd also define a method that does all of the checks (as a string) in Object space and then call it from within the formula.

If someone wants the same method to be called for every formula, then maybe a script would be used so they don't have to copy it to every skill/item.

Thanks. I actually have a question about that. Why does it have to be a.basef() or b.basef() instead of simply basef()? Is it because they are defined in Game_Battler?
basef shouldn't work because the formula is evaluated within the context of the corresponding damage object, while the `basef` method is defined in Game_Battler.

If you defined it in Object space, for example

def basef ...endThen you could directly call it because all classes inherit from Object.
oh that's it... the one theo posted was using a variable... that explains a lot...
More specifically, it's a constant defined in Object space.

You can't do the same if you had defined it as

Code:
normal = "a.atk * 4 - b.def * 2"

Original thread: https://forums.rpgmakerweb.com/threads/improved-damage-formula-scripting.17056/