YEP <Custom Passive Conditions> not working on equipment?

Im having a very difficult time making a piece of armor that provides a bonus to DEF once each battle, once the actor takes any sort of damage the state is turned off and reset the next battle.

I tried this on the state given by armor. No luck, I also tried creating a dummy state that adds my DEF state and used the custom react to remove the state and it did not work either.
Code:
<Custom Passive Condition>
if ($gameParty.inBattle() && user._guardCheck !== 1){
var atkcount = 1; //This is the attack counter. Change it to fit your purpose. 1 means it will be removed after 1 attack and so on
user._attackCount = user._attackCount || atkcount; //Set this flag to count your attacks received
user.setStateCounter(99, target._attackCount); //Set a visual counter to your state. Change X to your state ID
condition = true; //Enablethe passive state
}
else{
user._guardCheck = undefined;
user._attackCount = undefined;
condition = false; //Disable the passive state
}
</Custom Passive Condition>

<Custom React Effect>
//Check if actor takes dmg
if (value > 0 && !this.isHpRecover()){
//Decrease the attack counter by 1
target._attackCount -= 1;
//Set a counter to your state. Change X to your state ID
target.setStateCounter(99, target._attackCount);
//Check if attack counter reaches 0
if (target._attackCount <=0){
target._guardCheck = 1;}}
</Custom React Effect>
I got this one that adds attack stack. but you can convert it to def and adjust the way you need it.

JavaScript:
<Custom Passive Condition>
//Check if your party is in battle to activate the state
if ($gameParty.inBattle()){
condition = true;}
else{
condition = false;
user._comboState = undefined;}
</Custom Passive Condition>

<Custom Battle Effect>
user._comboState = 0;
user.setStateCounter(x, user._comboState); //With X is your state ID. This will display the number of current stacks on your state
</Custom Battle Effect>

<Custom Confirm Effect>
//Check if the action is a normal attack
if (this.isAttack()){
//setup bonus dmg
var bonus = 50 * user._comboState;
//add bonus dmg to the current dmg
value += bonus;
//increase stack by 1
user._comboState += 1;}
else{
//if not an attack, reset the stack to 0
user._comboState = 0;}
user.setStateCounter(x, user._comboState); //With X is your state ID. This will display the number of current stacks on your state
</Custom Confirm Effect>

but the passive condition is more, if the battle is true or false,
than add the custom battle effect.

I think this works if you replace attack to def.
I got this one that adds attack stack. but you can convert it to def and adjust the way you need it.

JavaScript:
<Custom Passive Condition>
//Check if your party is in battle to activate the state
if ($gameParty.inBattle()){
condition = true;}
else{
condition = false;
user._comboState = undefined;}
</Custom Passive Condition>

<Custom Battle Effect>
user._comboState = 0;
user.setStateCounter(x, user._comboState); //With X is your state ID. This will display the number of current stacks on your state
</Custom Battle Effect>

<Custom Confirm Effect>
//Check if the action is a normal attack
if (this.isAttack()){
//setup bonus dmg
var bonus = 50 * user._comboState;
//add bonus dmg to the current dmg
value += bonus;
//increase stack by 1
user._comboState += 1;}
else{
//if not an attack, reset the stack to 0
user._comboState = 0;}
user.setStateCounter(x, user._comboState); //With X is your state ID. This will display the number of current stacks on your state
</Custom Confirm Effect>

but the passive condition is more, if the battle is true or false,
than add the custom battle effect.

I think this works if you replace attack to def.

EDIT: I found a way using your code to create the desired effect.. however I need 2 states. The item equipped gives passive state;

Code:
<Custom Battle Effect>
user._comboState = 1;
user.setStateCounter(99, user._comboState); //With X is your state ID. This will display the number of current stacks on your state
user.addState(99);
</Custom Battle Effect>

The actual state is;
Code:
<Custom React Effect>
//Check if actor takes dmg
if (value > 0 && !this.isHpRecover()){
var halfdmg = Math.ceil(value * 0.5);
value = halfdmg;
target._comboState -= 1;
target.setStateCounter(99, target._comboState); //With X is your state ID. This will display the number of current stacks on your state
if (target._comboState <=0){
target.removeState(99);}
}
</Custom React Effect>

Super annoying that you need to make 2 states to make this work. I tried other ways and nothing seems to work for me. Thanks
I got this state from a discord server to boost attack, and you can create def the other way around,
so far I see, it's 1 state, but if its 2, than it can be annoying.

I dont know much about lunatic code, but I save usefull onces in case I ever need it or someone else.
so most can be saved as a basis 🙂

if you need to extend it, I hope someone can help you out on it.

Original thread: https://forums.rpgmakerweb.com/threads/yep-custom-passive-conditions-not-working-on-equipment.122393/