(Solved) (Yanfly Plugins) Can't remember how to check for a certain element on attack.

Trying to add an effect based on if a certain element did damage, but I can't recall how that is done. This is what I have so far for my state:

<Custom Establish Effect>
if target.result().hpDamage > 0 && (Attack element of 13) {
user.addState(872);
}
</Custom Establish Effect>

Basically if I damage a target with the Holy element I will gain state 872. I just can't remember how to check for element type.

*Edit*
Solution by @emelian65

<Custom Respond Effect>
var element = 13;
if (this.item().damage.elementId === element) {
user.addState(872);
}
</Custom Respond Effect>

You can also see Emelian's work a few posts down where more detail is added.
I don't really use Yanfly's plugins/scripts as I write my own, but from what I know of it I think you can do this with:

user.currentAction().item().damage.elementId === 13
So I tried the following:

<Custom Establish Effect>
if target.result().hpDamage > 0 && user.currentAction().item().damage.elementId === 13 {
user.addState(872);
}
</Custom Establish Effect>

But it doesn't seem to have any effect.
Establish effect may be too late for it. Does the console show any errors?
SyntaxError: Unexpected identifier {stack: (...), message: "Unexpected identifier"}
Okay, it may be that the action has already been flushed when establish effect fires.

Do me a favour then: get into a battle, choose the holy ability you're testing with, then write

$gameParty.members()[index of user].currentAction().item().damage.elementId === 13

in the console, and tell me if that returns true.
$gameParty.members()[index of user].currentAction().item().damage.elementId === 13
VM2306:2 Uncaught SyntaxError: Unexpected identifier
Did you replace "index of user" with the actual index of the party member who took the action?
I have a question, do you want the state to react to a certain element?
In that case, something like this should work.
Code:
<Custom Respond Effect>
// Get the ID from the element you want to react
// where X is the element you want to react
var element = X;
// Check if the X element damage is dealt.
if (this.item().damage.elementId === element) {
// effect you want
} else {
// effect you want
}
</Custom Respond Effect>
Had no idea I needed to. I can barely comprehend Java. lol

$gameParty.members()[1].currentAction().item().damage.elementId === 13
VM1808:2 Uncaught TypeError: Cannot read property 'currentAction' of undefined
Are you doing that command in the console right after the party member chooses a target for the skill?

Edit: emelian's idea might work. I didn't realise the "this" scope for the lunatic tags was the current action.
@emelian65 Not quite. The passive state is on me and I want it to give me another state if I damage the enemy with a specific element. Custom Respond is if I'm the one taking the damage. Your code DOES work if I change it to "Establish" from "Respond". Thank you for the help. 🙂

@Trihan And thank you for the help, as well. I may use a similar damage formula for some other skills in the future.
Yeah, I edited out the bit I edited in about being able to do it in the formula box after remembering you'd wanted to make sure it did damage first, but if you don't have that requirement for future skills it's easy to do.

Original thread: https://forums.rpgmakerweb.com/threads/solved-yanfly-plugins-cant-remember-how-to-check-for-a-certain-element-on-attack.75172/