Double damage if an actor has a state, help.

So I'm trying to figure out how to make this work. I have most Yanfly plugins and it seems like it should be easy to figure out compared to some of the other things I've asked but I am struggling on it.

Basically all I'm trying to do is create an enemy skill that does double damage to an actor if they have a given state. In this case the damage multiplier can't be done on the state side because normally the state doesn't cause extra damage dealt. Rather it's a specific enemy skill that does x damage normally and (x * 2) if the character happened to have the state. Bonus points if you can figure out a way to use Yanfly ai core to target characters with the state first before characters without but that's a secondary problem and not as big of a deal.

Things I've tried:

1) doing this directly via the damage formula for the skill. I saw a few things online about this but whenever I tried this, it somehow made it so the enemy didn't do any damage at all when they used the skill.

2) I've tried using damage core tags and then tried <custom respond effect >tags but I'm not sure how to do the coding side of it, or if I need to include the actual damage formula I'm wanting for the code. Some kind of example to point me in the right direction would be great.

I have so far:

//Check if target took hp damage
<Custom Respond Effect>
if (target.isStateAffected(92){
(something in these brackets about damage formula but not sure how to do syntax
}
</Custom Respond Effect>

Not sure if this works this way anyway since it's an enemy skill? Any help would be appreciated.
When a damage formula has an error in it, it will return 0.

I haven't tested these, but:
  1. For a specific skill, you could try a damage formula like:

    (a.atk * 4 - b.def * 2) * (b.isStateAffected(123) ? 2 : 1)
    I.e. "a.atk * 4 - b.def * 2 times 2 if the target has state ID 123, or times 1 otherwise".

  2. Or, for a state that doubles all incoming damage, you could try a YEP Buffs & States Core notetag:

    <Custom React Effect> if (target.result().hpAffected && value > 0) { // if hp damage value *= 2; // double the result } </Custom React Effect>
    It's "React Effect" because that happens before damage is dealt; "Respond" happens after.
[Edit: replaced this.isHpEffect() with target.result().hpAffected to catch more cases.]
[Edit: replaced this.isHpEffect() with target.result().hpAffected to catch more cases.]
I'm curious, which cases get caught by that change? I would've just done this.isDamage() && this.isHpEffect() - is there something that would've slipped past that?

@PersistentDreamerGames You may find this useful.

It gives the basic syntax for the stuff caethyril showed you above - how to check for a state, how to use a ternary formula for adding in multipliers.
I'm curious, which cases get caught by that change? I would've just done this.isDamage() && this.isHpEffect() - is there something that would've slipped past that?
isHpEffect and isDamage only check the action's Damage Type. So if there's anything else contributing to the result (e.g. other <Custom React Effect> tags, custom YEP Damage Core steps, action sequences, etc) then result().hpAffected should catch those that affect HP.

(It's also a free micro-optimisation. By default those damage type checks generate small amounts of garbage per call: the arrays [1,2] & [1,3,5]. They also potentially check up to that many values each time. Checking a number vs 0, or the truthiness of a boolean flag on the target's result, are cheaper.)
Speaking of, is Yanfly's article http://www.yanfly.moe/wiki/Stop_Putting_Mechanics_in_Damage_Formulas relevant to the whole putting variables in the damage formula thing?

(Edit: not variables but things like other code conditionals etc.)

[*]Or, for a state that doubles all incoming damage, you could try a YEP Buffs & States Core notetag:

<Custom React Effect> if (target.result().hpAffected && value > 0) { // if hp damage value *= 2; // double the result } </Custom React Effect>
It's "React Effect" because that happens before damage is dealt; "Respond" happens after.[/list]
[Edit: replaced this.isHpEffect() with target.result().hpAffected to catch more cases.]

So I'm trying to use the Yanfly way because I'm worried about the random side effects I posted but for this case I'm not looking for a state that doubles all incoming damage. I'm looking for it to only double damage if the owner of the state is targeted by a specific skill.

Edit 2:

Maybe something like this? Would this work in skill notetag?

<Custom React Effect>
if (target.result().hpAffected && value > 0 && target.isStateAffected(92) {
value *= 2;
}
</Custom React Effect>
Speaking of, is Yanfly's article http://www.yanfly.moe/wiki/Stop_Putting_Mechanics_in_Damage_Formulas relevant to the whole putting variables in the damage formula thing?
No. That article points out the dangers in including code that changes things in the damage formula.

So you would want to avoid setting a variable's value if it matters whether or not the skill gets used; you should not include addState() in a damage formula.

But, as it says right at the beginning of the article, that only matters
1712541759009.png


So if a skill isn't used by enemies, and if your game doesn't use the Auto Battle trait, it doesn't matter. It's bad practice generally, but you should understand what the article is saying.

Maybe something like this? Would this work in skill notetag?
...no. According to the documentation, Custom React Effect is not a skill notetag.

But all you're doing is math. You're not running any code that would change anything, so there's no reason not to do it in the formula the way caethyril demonstrated.

if there's anything else contributing to the result...then result().hpAffected should catch those that affect HP.
Good point, thanks.
No. That article points out the dangers in including code that changes things in the damage formula.

So you would want to avoid setting a variable's value if it matters whether or not the skill gets used; you should not include addState() in a damage formula.

But, as it says right at the beginning of the article, that only matters
View attachment 301267

So if a skill isn't used by enemies, and if your game doesn't use the Auto Battle trait, it doesn't matter. It's bad practice generally, but you should understand what the article is saying.


...no. According to the documentation, Custom React Effect is not a skill notetag.

But all you're doing is math. You're not running any code that would change anything, so there's no reason not to do it in the formula the way caethyril demonstrated.


Good point, thanks.

Oh I had forgotten his original reply was if I was doing it on a state.

So this will be used by enemies though. But it still shouldn't matter because it's only checking for a state, not adding one? Guess I got nothing to lose testing it out.
So this will be used by enemies though. But it still shouldn't matter because it's only checking for a state, not adding one
That's correct.
Solved: I just set the attack value too low. 😔

Okay, so I tried testing it with the formula, and it's not working right. It's still doing zero damage.

Here's the screenshot of the skill in case I missed anything. Below that I've included a screenshot of state 92 and made sure the state was on the actor at time of testing. Though it does 0 whether or not the actor has state 92. The final screenshot is the enemy I'm using the skill on, in case I've overlooked anything. Finally, I'm copying and pasting the formula code I put in the event to make sure I put it in exactly.

(a.atk * 4 - b.def * 2) * (b.isStateAffected(92) ? 2 : 1)

Is there anything else I've missed here? Maybe a plugin is messing things up?


1712594991829.png

1712595081512.png

1712595503539.png

*Edit* Didn't get the enemy screenshot last time.
Solved: I just set the attack value too low. 😔
No worries! Good to hear you got it working~ 👋

Original thread: https://forums.rpgmakerweb.com/threads/double-damage-if-an-actor-has-a-state-help.167560/