ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,223
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
I want Weapons and Armor to then apply separately and be much more impactful.
Okay, then you can just reference the weapon's ATK by itself.
Code:
a.weapons()[0].params[2]
is the primary weapon's ATK value.

If there's a possibility of your actors being unarmed, put a check in there for it:
Code:
(a.weapons()[0] ? a.weapons()[0].params[2] : 0)
 

ShatteredRift

Warper
Member
Joined
Apr 22, 2023
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
This would probably be perfect! Since it's a percentage, I can just multiply by 100 to have a range up to 999. And since I hope to handle both Weapons and Armor this way, it should work out perfectly. Thank you!
For anyone following along, RPGM MV assumes the percentage will be 100% by default, so I had to do (100 * a.elementRate(2) - 100) to make it work. Relevant because I'm also including a disarming mechanic by sealing a character's weapon for the battle... although the fact that enemies can't equip weapons probably means I'll be modifying this later anyway. But at least it works on the player characters.\

Okay, then you can just reference the weapon's ATK by itself.
Code:
a.weapons()[0].params[2]
is the primary weapon's ATK value.

If there's a possibility of your actors being unarmed, put a check in there for it:
Code:
(a.weapons()[0] ? a.weapons()[0].params[2] : 0)
Thank you! The one issue with this is that I don't want weapons also adding to ATK. Which is easily solved in formula by subtracting the weapon's ATK from the character's ATK. But would still display the combined ATK on the menu. (Haven't even looked at those while I'm learning.)
 

PhantomRaptorDS

Villager
Member
Joined
May 21, 2022
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
Hello, I'm trying to set up a damage formula for my project and having trouble (0 experience with this sort of thing).

What I'm trying to do is have attack - defense and magic attack - magic defence calculated seperately within the same attack, for example, if the target has 1000 defense and 700 m.defense, and I attack with a weapon that has 500 atk, and 1000 m.atk, I'd want it to deal 300 damage.

The closest I've got trying to come up with it myself was :
(a.atk - b.def) + (a.mat - b.mdf) * 1
but this ended up, as far as I can tell, getting -500 from the first set of brackets, which... doesn't really work well.

I'm sure there's probably a stupidly easy answer here that I'm missing. :kaosigh:
 

udime123

[C]reator of Axial
Regular
Joined
Mar 29, 2018
Messages
113
Reaction score
26
First Language
English
Primarily Uses
RMMV
Hello, I'm trying to set up a damage formula for my project and having trouble (0 experience with this sort of thing).

What I'm trying to do is have attack - defense and magic attack - magic defence calculated seperately within the same attack, for example, if the target has 1000 defense and 700 m.defense, and I attack with a weapon that has 500 atk, and 1000 m.atk, I'd want it to deal 300 damage.

The closest I've got trying to come up with it myself was :
(a.atk - b.def) + (a.mat - b.mdf) * 1
but this ended up, as far as I can tell, getting -500 from the first set of brackets, which... doesn't really work well.

I'm sure there's probably a stupidly easy answer here that I'm missing. :kaosigh:
So, if you want Atk, Mat, Def, and MDf to all contribute to the same formula, the results of the individual brackets aren't actually going to matter if the numbers don't change. You could easily do (Atk+Mat) - (Def+Mdf) and still get the same result, assuming that the numbers being added and subtracted are always the same.

From what I understand based on the example you gave though, it sounds like you want to pull the highest number out from the two possible damage calculations, considering the Mat-Mdf example only used the result of 1000 Mat vs. 700 Mdf divorced from the physical stats. This is fortunately very easy!

If that's what you're going for, you'll want to use Math.max. Specifically for your example:

Math.max(a.atk - b.def, a.mat - b.mdf);

What this formula will do is select which item in the array (separated by commas) will yield the highest result, and select that number. So, if your Atk is lower than the target's Def and would deal no damage, but your Mat is higher than the target's Mdf, only the magic stats will apply in this calculation.

If for whatever reason that's not what you're going for, I think you might need to be a bit more specific, since I can't think of any way to add 500+1000 minus 1000+700 and pull any positive number.
 

Boonty

Regular
Regular
Joined
Oct 10, 2018
Messages
168
Reaction score
65
First Language
French
Primarily Uses
RMMV
Maybe something like this will be do the trick

Math.max(0, a.atk-b.def)+Math.max(0,a.mat-b.mdf)

In this case, if the def is greater than the atk like in your example, this part will be equal to zero and will not impact the magic part.
 

PhantomRaptorDS

Villager
Member
Joined
May 21, 2022
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
Thank you both for your replies! Sorry about wording all of that pretty terribly, what I should have focused on was that I didn't want the result to be able to go into negative numbers. Boonty's suggestion seems to work perfectly for what I was looking to do! Tysm :kaojoy:
 

JohnDoeNews

AFK TTYL
Regular
Joined
Apr 25, 2017
Messages
2,083
Reaction score
1,533
First Language
Dutch
Primarily Uses
RMMV
Thank you both for your replies! Sorry about wording all of that pretty terribly, what I should have focused on was that I didn't want the result to be able to go into negative numbers. Boonty's suggestion seems to work perfectly for what I was looking to do! Tysm :kaojoy:
Normally, when the result is a negative, it should not do any damage. However, if you want to make sure the minimum is 0, or any other number, you can use:
Code:
Math.max(0, X)

Replace X with your own formula. Now, the outcome is either 0 or the outcome of your formula. Whichever is the highest value.

Replace 0 with whatever you want the minimum to be.

Edit:
Oh never mind. I see that was already said. Oops.
 

Zakarijazh

I love making maps!
Regular
Joined
Aug 18, 2019
Messages
246
Reaction score
50
First Language
English
Primarily Uses
RMMV
Trying to make a skill that Drains a percentage of the target's current TP and grants it to the user. Idk whereto even start as the one thing I found didn't have any explanations

I intend to have it be able to be used on any target, including allies if possible, if that matters.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,223
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
Trying to make a skill that Drains a percentage of the target's current TP and grants it to the user. Idk whereto even start as the one thing I found didn't have any explanations
Everything you need is explained in this thread:

Note that it is best practice to not do this in a damage formula, but to use a plugin like Yanfly's Skill Core.
 

Zakarijazh

I love making maps!
Regular
Joined
Aug 18, 2019
Messages
246
Reaction score
50
First Language
English
Primarily Uses
RMMV
Everything you need is explained in this thread:

Note that it is best practice to not do this in a damage formula, but to use a plugin like Yanfly's Skill Core.
There has to be a simpler way to do this without a plugin. It's a single skill for one of my characters and no one else, including enemies.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,223
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
There has to be a simpler way to do this without a plugin. It's a single skill for one of my characters and no one else, including enemies.
...then you use the information in the thread I already linked to you?

I was telling you, because that thread doesn't say it, that if you put skills on enemies or use the Auto Battle trait, JavaScript functions in the damage formula will produce unexpected results. I'm not sure what your question or confusion is. Please clarify.
 

Maldra

Regular
Regular
Joined
May 31, 2017
Messages
102
Reaction score
11
First Language
English
Primarily Uses
RMMV
I'm not sure how to do a %, but you can do something like this:

a.gainTp(45); b.gainTp(-45);
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,223
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
I'm not sure how to do a %
To get a portion of a number you can either divide it by another number (fractions) or multiply by a decimal.

100/2
100*.5
will both give you 50% of 100.

For what it's worth, the above poster got their question figured out in another thread using some plugin notetags.
 

Maldra

Regular
Regular
Joined
May 31, 2017
Messages
102
Reaction score
11
First Language
English
Primarily Uses
RMMV
Well, what I meant is I wasn't sure how to do a % of their current TP. The code I provided him simply subtracts tp and adds tp to the user without checking the target's actual TP.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,223
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
Well, what I meant is I wasn't sure how to do a % of their current TP.
The same math applies.
b.tp/2
b.tp*.5
both give you 50% of the target's TP.

The b.tp part of it is in the tooltip for the damage formula box.

When dividing, you do want to use a JavaScript function to make sure you don't accidentally work with decimals. So, for example, Math.round(b.tp*.5)
 

TailsFiraga

Villager
Member
Joined
Aug 5, 2023
Messages
7
Reaction score
0
First Language
English
Primarily Uses
RMMV
Hello! So I'm using Yanfly's Selection Control plugin and while it has a disperse damage/healing option, said option splits it evenly among all targets. However, I'd like for it to instead work like it typically does in Final Fantasy games where selecting multiple targets just causes the damage to be cut in half or so. So like a spell does ~1,000 damage on one target, but it's ~500 to each target if it's two or more.

While I'm familiar with being able to spread damage evenly across targets or apply a state to the user in the formula, how would I go about doing this act of wizardry? Sorry if this is necroposting, and thank you in advance!
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,223
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
Hello! So I'm using Yanfly's Selection Control plugin and while it has a disperse damage/healing option, said option splits it evenly among all targets. However, I'd like for it to instead work like it typically does in Final Fantasy games where selecting multiple targets just causes the damage to be cut in half or so.
So you would not use the Disperse Damage tag on the skill. Instead, give it the Yanfly Skill Core notetag:
Code:
<Pre-Damage Eval>
if (BattleManager._targets.length>1)
    value/=2;
</Pre-Damage Eval>

I think that should work with each target getting passed the original damage value. If instead you see each target taking half successively, we can do something more complex.
 

TailsFiraga

Villager
Member
Joined
Aug 5, 2023
Messages
7
Reaction score
0
First Language
English
Primarily Uses
RMMV
So you would not use the Disperse Damage tag on the skill. Instead, give it the Yanfly Skill Core notetag:
Code:
<Pre-Damage Eval>
if (BattleManager._targets.length>1)
    value/=2;
</Pre-Damage Eval>

I think that should work with each target getting passed the original damage value. If instead you see each target taking half successively, we can do something more complex.

Thank you for the speedy reply! Upon applying this to a few spells to test it out, it works with one spell but for some reason doesn't seem to work with two other spells that are otherwise the same, which I assume is just RPG Maker being lovely and quirky but I am frantically checking to make sure I copied things correctly just in case. It also doesn't seem to work with the healing spells, probably because they don't do "damage."

As a side thing, and it's probably just RPG Maker MV itself being a little silly, but sometimes it just adds the number "5" to the end of the damage numbers. It doesn't affect the damage at all, the game just really likes to display the number 5.

Placeholdery placeholder stuff for sure
1696209131244.png
 

Robro33

Weeb Cringe Incarnate
Regular
Joined
Oct 15, 2022
Messages
99
Reaction score
42
First Language
English
Primarily Uses
RMMV
As a side thing, and it's probably just RPG Maker MV itself being a little silly, but sometimes it just adds the number "5" to the end of the damage numbers. It doesn't affect the damage at all, the game just really likes to display the number 5.
the 5 is the engine not rounding. youll have to use Math.ceil() or some other rounding function to get rid of decimal results
try replacing that value/=2 line with
Code:
value = Math.ceil(value/2);

also pre-damage tags should work on healing skills. try sharing a pic of the skills that arent working as they are in the database?

EDIT: just thought of it. do your healing skills use the formula box, or did you use a recover hp effect?
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,223
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
@TailsFiraga As @Robro33 said, you need to round the damage: you can use Math.ceil(), Math.floor(), or Math.round()

And yes, healing is also processed as damage.

I'd suggest you start a new thread if they still don't work correctly, as this doesn't have anything to do with the damage formula.

Post screenshots of the skills there, but first double check the order of all Yanfly plugins against the list on the Yanfly Engine Web site. Anything out of order can cause random bugs.
 

Latest Threads

Latest Posts

Latest Profile Posts

I’m so lucky! Simone got referred to a feline cardiologist and had I not called this morning the moment there was a cancellation the next opening would have been SEVEN months from now! The other heart hospital would have been on the other side of Michigan. Who knew that animal specialty appointments were also terrible to get!?
Scalemail project is one step closer to completion. Ordered scales from a local metalworking company, ordered some split rings... now all I need is to wait. :>
And pray that the split rings will be flexible enough to handle that.
A spooky banner and a spooky pfp for a spooky season.
Spooky-Season.png
Broke: Actually making the stuff you need to make before the game can progress.
Woke: Wasting time instead by making a sidequest where you can recruit an imaginary friend to the party.
1696264391516.png
Day 1 I don't know where to start... I enjoy designing icons and brainstorming the abilities my video game will have

Forum statistics

Threads
134,991
Messages
1,252,679
Members
177,896
Latest member
Wulf_SDP_58343
Top