Is it possible to use dmg formula which stored in variables??

MatTokki

Regular
Regular
Joined
Oct 6, 2015
Messages
54
Reaction score
14
First Language
Korean
I know I can use variable by v[x] code but what I want to do here is storing the whole formula(ex: 'a.atk * 2 - b.def' to variables[1]) in variables, and using it in skill's dmg formula box, so I can just use 'v[1]' as a formula, instead of typing a.atk *2 - b.def everytime.

I tried to do this but it seems game only accept variables as numbers and not actually take in it's string and use it as formula but what do I know I'm noob anyway

So is this possible in vanila MZ or do I need a plugin?
thanks you for reading btw
 

ShadowDragon

Realist
Regular
Joined
Oct 8, 2018
Messages
8,216
Reaction score
3,481
First Language
Dutch
Primarily Uses
RMMV
I do know you could use scriptcalls functions in MV,
create a function with your formula and use that.

I'm not sure about variable with the formula though.
 

Andar

Regular
Regular
Joined
Mar 5, 2013
Messages
39,924
Reaction score
11,873
First Language
German
Primarily Uses
RMMV
theoretically it might be possible by using a double eval on the variable, but that has problems in itself.

can you give a more detailed description of the effect you want to achieve ingame?
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,635
Reaction score
11,131
First Language
English
Primarily Uses
RMMV
What ShadowDragon said is the best way to do this. I agree with Andar, trying to eval the code string in a variable could get wonky.

So, for example, I have this:
Code:
function TurDam(atk, def) 
{ 
    return atk * Math.log10(atk) * Math.log(1 + Math.pow((atk / def), 2)) / Math.log(2);
};
in a file called Turan.js in my plugins folder. I included that plugin in my plugin manager.

Then in the damage formula for my skills I can just do TurDam(a.atk, b.def)
 

MatTokki

Regular
Regular
Joined
Oct 6, 2015
Messages
54
Reaction score
14
First Language
Korean
theoretically it might be possible by using a double eval on the variable, but that has problems in itself.

can you give a more detailed description of the effect you want to achieve ingame?

Things mentioned in main post is really all that I want to do with this.

More specifically, I want to setup some kind of preset of damage formula that easy to edit in future.
For example, let's say I want to have two large category of skill dmg: weak / strong

weak: a.atk * 2 - b.def * 1 + (various modifiers for each individual skill)
strong: a.atk * 3 - b.def * 1 + (various modifiers for each individual skill)

obviously there will be hundred of skill in the end point of development, and suddenly I realise that I have to add something, or subtract something from that "preset" area of formula, so I have to track each skill that belongs to that category and edit every one of them one by one, which is not good.

So this is what I wanna do. Just storing a.atk * 2 - b.def * 1 into variables, and use that variables in skill damage formula box, so making formula into,
weak: v[1] + (various modifiers for each individual skill)
strong: v[2] + (various modifiers for each individual skill)

By this I can just modify one variables to edit entire category of skill.

Again thanks all of you for your attempt to helping me
 

Andar

Regular
Regular
Joined
Mar 5, 2013
Messages
39,924
Reaction score
11,873
First Language
German
Primarily Uses
RMMV
in that case you're better off using @ATT_Turan suggestion of a mini-plugin.
editing that plugin is a lot easier than editing the content of the variable in a way that that can be used.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,635
Reaction score
11,131
First Language
English
Primarily Uses
RMMV
So this is what I wanna do. Just storing a.atk * 2 - b.def * 1 into variables, and use that variables in skill damage formula box, so making formula into,
weak: v[1] + (various modifiers for each individual skill)
strong: v[2] + (various modifiers for each individual skill)

By this I can just modify one variables to edit entire category of skill.
That's basically what I showed you how to do. If what you're trying to do is make the damage formulae change during gameplay depending on things you do to the variables, then you can have conditionals in the code inside the plugin function. Or you can put conditionals inside your damage formula and change what you're passing into the plugin function.
 

ScorchedGround

Blizzards most disappointed fan (They keep going)
Regular
Joined
Apr 12, 2020
Messages
826
Reaction score
1,300
First Language
German
Primarily Uses
RMMV
Yeah, I'd go with @ATT_Turan aswell.

Making a small plugin only containing your personal damage formulas will be way easier, orderly and risk-free than any short and wonky solution.

The advantage of putting your formulas into a plugin is that you can use all javascript functions without restrictions, as long as you return a number at the end.

Not to mention being able to use multiple lines of code instead of cramming everything inside the single line damage formula.

And you have the advantage of being able to edit the formulas at any time, affecting all skills and other objects that may use the formula all at once. So you don't have to around editing every single skill when you change something.
 

Aesica

undefined
Regular
Joined
May 12, 2018
Messages
1,927
Reaction score
1,896
First Language
English
Primarily Uses
RMMZ
Custom formula in a function is definitely the way to go, I've been doing it for years now. Rather than typing out the same formula every time, it's just a matter of putting this in the formula box once it's all set up:

Code:
damage(a.atk, 4, b.def)
With 4 being the skill's power modifier.
 

Latest Threads

Latest Posts

Latest Profile Posts

Someone leaked the GTA VI trailer, so Rockstar just put it out today. Let the hype period truly begin!!!
Not surprising, but I've basically forgotten everything about Cubase. Guess I'm looking up beginner's tutorials again... :kaodes:
Bought myself a single booster of Revised edition MtG and it was not a winner. RIP.
Surprising to come back and my last profile post still resonates years later... Air is still dry. Hello again forum!
If you haven’t had the opportunity to check it out yet, here’s day #4 for advent compiled! Today’s question! Real tree or fake tree?

Forum statistics

Threads
136,749
Messages
1,269,502
Members
180,485
Latest member
CodexNexus
Top