Improved damage formula scripting

Andar

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

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 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
 
Last edited by a moderator:

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
^ 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...
 
Last edited by a moderator:

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
^ 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?
 
Last edited by a moderator:

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
oh... so eval only returns the direct result of the passed value? that's good to know... XD
 

Fafnir

And yet, these hands will never finish anything.
Veteran
Joined
Apr 26, 2012
Messages
317
Reaction score
26
Primarily Uses
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.
 

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
oh that's it... the one theo posted was using a variable... that explains a lot...
 

Fomar0153

Arkz
Restaff
Joined
Mar 13, 2012
Messages
1,327
Reaction score
473
First Language
English
Primarily Uses
RMMZ
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/
 

Fomar0153

Arkz
Restaff
Joined
Mar 13, 2012
Messages
1,327
Reaction score
473
First Language
English
Primarily Uses
RMMZ
Good point. basef should work as well. Now I feel daft.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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"
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,045
Members
137,569
Latest member
Shtelsky
Top