RMMV Damage Formula - ideas and help

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,505
Reaction score
1,400
First Language
English
Primarily Uses
RMMV
I had a feeling it might be failing at the enemy level check, hence the console log test. While enemies don't have levels by default, but you can still use that tag to make the comparison as though they did:

Code:
a.level > (+b.enemy().meta.Level || 1) ? b.hp : 0
Try that. No plugin even required for it to work, either. However, <Level: x> is case sensitive, so <level: x> or <LEVEL: x> won't work.

Also, if enemies try to use this skill against actors, it will fail. Here's a version that is completely usable by both actors and enemies alike:

Code:
(a.isActor() ? a.level : (+a.enemy().meta.Level || 1)) > (b.isActor() ? b.level : (+b.enemy().meta.Level || 1)) ? b.hp : 0
 

Kagemaru

Veteran
Veteran
Joined
Dec 11, 2017
Messages
35
Reaction score
3
First Language
French
Primarily Uses
RMMV
For the <Level: x> notetag, no worries, I know its case sensitive.

Only one actor uses that spell right now but I might give it to special bosses later in the game, so Im gonna use the second formula.

I tried using the spell on a group of 2 enemies and the first test went well. Both enemies have 100HP and the spell dealt 100 points of damage to both of them.
The second test didnt go well though. When I used the spell, enemy A received 100 damage and died but enemy B received only 50 damage. I used the spell a second time, and the spell only dealt 25 damage. On the third turn, it also dealt 25 damage, which finally killed enemy B.
I battled the same enemies several times after that but the spell dealt 100 points of damage to both enemies every time. I wonder what happened during the second test?

Finally, Im not good with formulas, so could you please tell me what that last formula does?
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
126
Reaction score
68
First Language
French
Primarily Uses
RMMV
Here's a breakdown of the line:

If X is greater than Y, deals the target's current HP as damage. Otherwise, it's 0. Now to determine X and Y.

If the user is an actor, X is their level. Otherwise, take the level of the enemy, if it doesn't have a specific level (which wouldn't return a number) we'll say it's 1 (that's what the || 1 is for).
Same process to determine Y, but this time we're getting the target's level.

So here's what the line means: if the user's level is greater than the target's, deals the target's current HP as damage. Otherwise, it's 0.
It's a formula that does what you wanted, but properly handles how enemy levels are processed.

Now for the reason why Enemy B survived this skill despite taking damage, it could be that it has a resistance greater than 0 to the element / type (physical, magic) of the skill. To solve this, try making your skill a certain hit and making it non-elemental. Just remove any reason why it would be able to reduce damage taken. Are you still having this issue?
 

Kagemaru

Veteran
Veteran
Joined
Dec 11, 2017
Messages
35
Reaction score
3
First Language
French
Primarily Uses
RMMV
Oooh! That was really easy to understand! Thanks! :D

For the problem that I mentioned last time, is it possible that it happened because the enemy guarded? When I was testing that time, I left my room for a few seconds. Im using the... active time battle system, I think its called? The enemy must have guarded without me noticing. Ill test it later tonight to be sure, but if thats really what caused the problem, I wont be able to use the formula that Aesica provided... T.T
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,505
Reaction score
1,400
First Language
English
Primarily Uses
RMMV
Oh yeah, if this skill can be resisted/reduced in any way, it's not going to kill the target. If you want to ensure the enemy dies every time, there's a bit more to add OR you could just replace b.hp with some huge number like 9999.

If you use yanfly's action sequences, it's possible to make it look a lot cleaner--no "0" popup on failure and a clean dispatch with no damage popups when it works, no guard/reductions to worry about, etc.
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
126
Reaction score
68
First Language
French
Primarily Uses
RMMV
Or you could do b.addState(1) or whatever is the add state script in MZ, it would only care about one resistance and that'd be the resistance to the death / KO state.

Or b.die() but apparently that skips certain steps? I didn't really understand which ones, though. That's what I've done on an Execution skill in my game, and it worked as planned even with a condition.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,505
Reaction score
1,400
First Language
English
Primarily Uses
RMMV
Basically, die() is a cleanup function invoked as a result of adding state 1 to the target, not as a way to add state 1 to the target. When invoked directly from the console:


As you can see, the enemy is still there. You can't collapse it away via x.performCollapse() and checking its states reveals it doesn't have the death state or anything. The fact that it works when done via the formula box is something of a fluke, because the fact that the damage formula attempts to inflict damage is what probably fills in the missing pieces, allowing the enemy to die off properly.

I guess what I'm saying is that you probably can use die() in the formula, but it's bad practice and will behave horribly if used anywhere else. Better to stick with addState(1);
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
126
Reaction score
68
First Language
French
Primarily Uses
RMMV
I'll make sure to remember that for any other instakill I put in my game. Thanks for the clarification.
 

Kagemaru

Veteran
Veteran
Joined
Dec 11, 2017
Messages
35
Reaction score
3
First Language
French
Primarily Uses
RMMV
@Aesica Thanks a lot for telling me about that! Ive never used the action sequence functions, but Ill give it a try.

@CHKNRAVE I did try adding b.addState(1) to the formula before asking for help here but I havent tried it since then. Ill go give that a try too.
 

Black Pagan

Veteran
Veteran
Joined
Feb 21, 2017
Messages
350
Reaction score
271
First Language
English
Primarily Uses
RMMV
Guys, Can someone help me with this Damage Formula ? I'm trying to use Default Normal Attack to have such a Condition :

"If Player has Weapon Y equipped, Then Normal attacks Life-steal X% Life from Enemy, Else Default Damage Formula calculations happen".
 
Last edited:

Trogdor101

Villager
Member
Joined
Sep 18, 2020
Messages
7
Reaction score
0
First Language
English
Primarily Uses
RMMZ
if you ask me, a simple damage system with the least amount of variance in damage amount is the best for strategic game play. When your players press the button they should be able to reasonably be able to predict how much damage it will do to the opponent. For this reason I propose the following:
1. a.attack - b.defense + x for bladed weapons where x is their base damage
2. a.attack + x for blunt weapons, note x should be less than bladed weapons, this is to represent their armor piercing nature while making sure they are not always a better option against any enemy
3. a.attack - b.defense or a.attack for unarmed combat

you may also want to try
3. 2*a.attack - b.attack if you want to make defense scale slower than attack, but I suggest keeping them in tandum with one another

this all of course goes for magic as well
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,505
Reaction score
1,400
First Language
English
Primarily Uses
RMMV
Guys, Can someone help me with this Damage Formula ? I'm trying to use Default Normal Attack to have such a Condition :

"If Player has Weapon Y equipped, Then Normal attacks Life-steal X% Life from Enemy, Else Default Damage Formula calculations happen".
The easiest way to do this is just use one of the many plugins capable of replacing the basic attack command. You can put a note tag on the desired weapon that will replace basic attack with a skill that does exactly what you're trying to do easily enough.
 

TheDrifter

Veteran
Veteran
Joined
Apr 18, 2012
Messages
121
Reaction score
7
First Language
English
Primarily Uses
Hi,
I'd like to create a skill that restores TP based on how hurt the user is.

For example,
If the user has 1/100 HP, the skill restores 50 TP.
If the user has 50/100 HP, the skill restores 25 TP.
If the user has 100/100 HP, the skill restores 0 TP.

Here is the formula I have so far:
Code:
b.gainTp(Math.ceil(50 - (a.hp / a.mhp * 50)))
So far, the skill seems to work in a brand new project with no plugins, except it shows the user being dealt 0 HP damage (while also restoring the correct amount of TP).

If I use Yanfly's Damage Core 1.08 plugin, this skill makes the game crash.

Any tips / pointers on what I'm doing wrong and how to fix it?
Thanks!

EDIT:
I sort of figured it out.
Make it an HP Restore skill with the following formula instead:
Code:
b.gainTp(Math.ceil(50 - (a.hp / a.mhp * 50))); 0
Only problem is, it still shows the user being dealt 0 HP damage. Not sure how to hide that and only show the amount of TP gained.

Does anyone know how?
 
Last edited:

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
126
Reaction score
68
First Language
French
Primarily Uses
RMMV
Hi,
I'd like to create a skill that restores TP based on how hurt the user is.

For example,
If the user has 1/100 HP, the skill restores 50 TP.
If the user has 50/100 HP, the skill restores 25 TP.
If the user has 100/100 HP, the skill restores 0 TP.

Here is the formula I have so far:
Code:
b.gainTp(Math.ceil(50 - (a.hp / a.mhp * 50)))
So far, the skill seems to work in a brand new project with no plugins, except it shows the user being dealt 0 HP damage (while also restoring the correct amount of TP).

If I use Yanfly's Damage Core 1.08 plugin, this skill makes the game crash.

Any tips / pointers on what I'm doing wrong and how to fix it?
Thanks!

EDIT:
I sort of figured it out.
Make it an HP Restore skill with the following formula instead:
Code:
b.gainTp(Math.ceil(50 - (a.hp / a.mhp * 50))); 0
Only problem is, it still shows the user being dealt 0 HP damage. Not sure how to hide that and only show the amount of TP gained.

Does anyone know how?
The damage / recovery formula is always expecting a final value, which is why you get 0 damage / recovery at the end.

Instead, using the Buffs and States Core, you could create a state whose custom apply effect does the TP manipulation. The skill would then have no damage / recovery formula so you won't get a 0, and it just applies the state which does the job.
 

SciWriter

Villager
Member
Joined
Oct 19, 2020
Messages
20
Reaction score
0
First Language
English
Primarily Uses
RMMV
Hopefully this tread can help. In my game I am making a skill that will do more damage if the enemy is in a certain state.

I know this can be done with the damage formula, but it doesn't seem to be working. Here's how I have the formula. (I'm using MV)

b.IsStateAffected(0027) ? 200 + a.atk*10 - b.def *2 : a.atk*2 - b.def*2

State 0027 is called Blinded. The ability is called shadow strike. When the enemy is blind it is supposed to do a lot more damage. However when I use the Formula. I deal the same damage whether the state is applied or not. What am I doing wrong?

Thank You;
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
126
Reaction score
68
First Language
French
Primarily Uses
RMMV
Hopefully this tread can help. In my game I am making a skill that will do more damage if the enemy is in a certain state.

I know this can be done with the damage formula, but it doesn't seem to be working. Here's how I have the formula. (I'm using MV)

b.IsStateAffected(0027) ? 200 + a.atk*10 - b.def *2 : a.atk*2 - b.def*2

State 0027 is called Blinded. The ability is called shadow strike. When the enemy is blind it is supposed to do a lot more damage. However when I use the Formula. I deal the same damage whether the state is applied or not. What am I doing wrong?

Thank You;
Code is often case-sensitive. The mistake you've made is that the condition should be written b.isStateAffected(27) with a lowercase i.
 

mmiller9280

Warper
Member
Joined
Sep 21, 2020
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMZ
I'm very new to coding, so any help is appreciated.

Basically, I'm looking for a skill to apply a random set of states if the enemy is affected by one particular state, and do damage regardless.

if (b.isStateAffected(47)) (b.addState(Math.floor(Math.random() * 9) + 60)); (a.atk * 12/b.def * 5) * 0.2

This works perfectly in game. But I would also like it to add one tp to the actor using the skill and do extra damage to the monster. (ONLY if the if statement is true, if you used it on an enemy affected by state 47). I'm having trouble adding another effect after the math random component. Ideally, if you use this skill on an enemy with state 47, I'd like it to do (a.atk * 12/b.def * 5) * 2.0 damage and add 1 TP to the actor who used it.

Still learning about this stuff, any help is appreciated. Thanks :)
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,507
Reaction score
1,106
First Language
English
Primarily Uses
RMMV
I'm very new to coding, so any help is appreciated.

Basically, I'm looking for a skill to apply a random set of states if the enemy is affected by one particular state, and do damage regardless.

if (b.isStateAffected(47)) (b.addState(Math.floor(Math.random() * 9) + 60)); (a.atk * 12/b.def * 5) * 0.2

This works perfectly in game. But I would also like it to add one tp to the actor using the skill and do extra damage to the monster. (ONLY if the if statement is true, if you used it on an enemy affected by state 47). I'm having trouble adding another effect after the math random component. Ideally, if you use this skill on an enemy with state 47, I'd like it to do (a.atk * 12/b.def * 5) * 2.0 damage and add 1 TP to the actor who used it.

Still learning about this stuff, any help is appreciated. Thanks :)
You forgot the question mark if you're gonna use ternary notation. I believe it should look like this...someone please correct me if I'm wrong btw.
b.isStateAffected(47) ? b.addState(Math.floor(Math.random() * 9) + 60) : (a.atk * 12) / (b.def * 5) * 0.2;
 
Last edited:

mmiller9280

Warper
Member
Joined
Sep 21, 2020
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMZ
You forgot the question mark if you're gonna use ternary notation. I believe it should look like this...someone please correct me if I'm wrong btw.
if (b.isStateAffected(47)) ? (b.addState(Math.floor(Math.random() * 9) + 60)) : (a.atk * 12) / (b.def * 5) * 0.2
The code I posted works perfectly...though maybe it’s a fluke . In addition to the math floor statement, I’m looking to do extra damage to the monster and add one tp to the actor who used the skill if the IF statement is true. (Enemy has state 47)

Hopefully that’s not too confusing. Thanks for replying!
 

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

Latest Threads

Latest Profile Posts

YES! officially released my games soundtrack on Itunes, Spotify, and Amazon..... kinda cool!

Another old age version of Reid. Trying out different style.
Hey everyone! Not sure how many people know about Cafofo Music on Itch.io, but I highly recommend their Sound Effects! It is amazing quality AND quantity and best of all, they are having a 50% sale! I can't express how much I love sales.
Wow.... My last map GIF got 47 likes, 16 retweet and 2,105 views on Twitter in 24 hours. My game thread here's only got 3k views in 6-7 months. I guess building my Twitter was insanely worth it. :LZSexcite:

Forum statistics

Threads
105,594
Messages
1,014,883
Members
137,264
Latest member
ZeoValinferno
Top