Core damage formula for all skills to use

darthmarth

Grail-Seeker
Member
Joined
Dec 27, 2014
Messages
9
Reaction score
2
First Language
English
Primarily Uses
RMMZ
Hey everyone, 


I have a question about managing skill formulae.  For my game, I'd like to tie many skills to the same basic formula, and have each skill modify that base damage with a skill power variable, kind of like Pokemon does (ex. Fire Blast has a power of around 120, making it stronger than Flamethrower at about power 90).  This would let me avoid copying and pasting the damage formula into each individual skill, and would also let me experiment with damage formulas a little bit by altering the root formula instead of each individual skill if I needed to tweak or balance the damage.  Has anyone heard of a good plugin or workaround that could solve this problem?


As a last thing, not every skill would use this formula, just the ones that inflict HP damage.


Thanks a ton!
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
First Language
French
Primarily Uses
You could use an eval. The eval function allows you to put strings to be executed as javascript code at a later point. It's perfect for this.


So your basic formula box for your damaging spells would be:


eval(v[1])


You'd just have to set variable 1 to your formula at the beginning of the game, using Control variables: script.


Ex:


"a.atk * 4 - b.def * 2"


For the default MV attack formula.


This would even allow you to change your base damage formula dynamically in game, by changing variable 1. Useful if you have a part of your game where you want physical attacks to deal less damage without changing parameters for instance.


To complete the pokemon analogy, using another variable you could have two basic damage formulas for special attack and attack based spells.
 
Last edited by a moderator:

darthmarth

Grail-Seeker
Member
Joined
Dec 27, 2014
Messages
9
Reaction score
2
First Language
English
Primarily Uses
RMMZ
You could use an eval. The eval function allows you to put strings to be executed as javascript code at a later point. It's perfect for this.


So your basic formula box for your damaging spells would be:



eval(v[1])


You'd just have to set variable 1 to your formula at the beginning of the game, using Control variables: script.


Ex:



"a.atk * 4 - b.def * 2"


For the default MV attack formula.


This would even allow you to change your base damage formula dynamically in game, by changing variable 1. Useful if you have a part of your game where you want physical attacks to deal less damage without changing parameters for instance.


To complete the pokemon analogy, using another variable you could have two basic damage formulas for special attack and attack based spells.


Thanks, I just did a bit of testing, and I think that'll work great!  Just for learning purposes, when else might you use an eval?  I'm pretty new to the whole scripts and coding thing.
 

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
Or you could just make a new js file and make a damage function inside that takes the multiplier as a parameter then call it on the damage formula...


something like


var Damage = {}

Damage.formula = function(a,b,multiplier) {return multiplier*(a.atk*4 - b.def*2)};


then on your damage formula you just need to put


Damage.formula(a,b,multiplier) where multiplier will be your damage multiplier, so like 1.20 for 120%


or change Damage and formula to shorter names if you want to have shorter things to copy into your damage formula


Not sure in MV but in Ace, avoiding eval is a good thing since its slower and can have some consequences...
 
Last edited by a moderator:

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
First Language
French
Primarily Uses
I'm no experienced programmer, so I can't really say anything on the eval function. Just that the security risk is non existent as long as you don't let the player run it's own code. It might be slower, but this is code that won't be run more than once a second at most, is it really important to optimize it?


The advantages of this solution are that it works in editor, and that you can change the formula in game for flexibility.


It can all be acheived with a small plugin, of course, but in my opinion it's not really worth it. I guess that if you have 10 different base damage formulas it can be worth it, to have them all in the same place. It's also less error prone, because you can overwrite the variables by accident mid game, and that can't happen with your definitions.


Eval is used throughout the engine, for instance the event command script, and for the damage formula.


You shouldn't really have a need for it as the developper. This is the only case I had to in order to make things work in editor.
 

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
I just presented an alternative to the eval one so that he will know all possible ways to do what he wants. It is up to him to use whatever method he prefers.

It's also less error prone, because you can overwrite the variables by accident mid game, and that can't happen with your definitions.
yeah, that's definitely a possible problem if the creator gets confused after using so many variables. I've seen quite a lot of threads over the years where people get problems and end up realizing it's because they ended up modifying the wrong variables or modifying a certain variable (when they shouldn't) at some point.
 
Last edited by a moderator:

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
First Language
French
Primarily Uses
And I responded in kind, with pros and cons to both alternatives to allow him to make a more informed decision :)


I hadn't thought of creating a small plugin like that myself so your suggestion is quite helpful.


Cheers!
 

darthmarth

Grail-Seeker
Member
Joined
Dec 27, 2014
Messages
9
Reaction score
2
First Language
English
Primarily Uses
RMMZ
Thanks for the ideas.  That gives me a couple of good options to consider.
 

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
Take note though that it's untested so I'm not sure if it is actually working. but the idea should be correct. :)
 

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,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top