Removing a state after all skill uses have been used up

Skill Core: http://www.yanfly.moe/wiki/Skill_Core_(YEP)
Limited Skill Use: http://www.yanfly.moe/wiki/Limited_Skill_Uses_(YEP)

I was wondering if there was a way to remove a state after you use up Skill uses. What I am doing is having a character install a turret for one ally to use and it gives them a state. Once they used up all the uses the state would get removed.
Do you want the skill to be used only with the state? 'Cause if so then it's pretty simple to do with just Yanfly's Buff and States core.

Put the following in your state's notebox.
Spoiler: Notetag Code
Code:
<Custom Apply Effect>
//Set this to the number of uses the skill has.
user._usesLeft = 2;
user.setStateCounter(stateId, user._usesLeft);
</Custom Apply Effect>
<Custom Confirm Effect>
//Change this._item._itemId == 1 to the ID number of your skill.
if(this.isSkill() && this._item._itemId == 1){
//Subtracts a use from this skill, and removes it if its 0
user._usesLeft -= 1;
user.setStateCounter(stateId, user._usesLeft);
if(user._usesLeft == 0)
user.removeState(stateId);
}
</Custom Confirm Effect>
Do you want the skill to be used only with the state? 'Cause if so then it's pretty simple to do with just Yanfly's Buff and States core.

Put the following in your state's notebox.
Spoiler: Notetag Code
Code:
<Custom Apply Effect>
//Set this to the number of uses the skill has.
user._usesLeft = 2;
user.setStateCounter(stateId, user._usesLeft);
</Custom Apply Effect>
<Custom Confirm Effect>
//Change this._item._itemId == 1 to the ID number of your skill.
if(this.isSkill() && this._item._itemId == 1){
//Subtracts a use from this skill, and removes it if its 0
user._usesLeft -= 1;
user.setStateCounter(stateId, user._usesLeft);
if(user._usesLeft == 0)
user.removeState(stateId);
}
</Custom Confirm Effect>

The state still doesn't delete itself after I reach 0 uses. This is how I put it in the state notetag.

Spoiler: Note tag
<Custom Apply Effect>

//Set this to the number of uses the skill has.

user._usesLeft = 3;

user.setStateCounter(12, user._usesLeft);

</Custom Apply Effect>

<Custom Confirm Effect>

//Change this._item._itemId == 13 to the ID number of your skill.

if(this.isSkill() && this._item._itemId == 13){

//Subtracts a use from this skill, and removes it if its 0

user._usesLeft -= 1;

user.setStateCounter(stateId, user._usesLeft);

if(user._usesLeft == 0)

user.removeState(12);

<Custom Apply Effect>

//Set this to the number of uses the skill has.

user._usesLeft = 3;

user.setStateCounter(1, user._usesLeft);

</Custom Apply Effect>

<Custom Confirm Effect>

//Change this._item._itemId == 13 to the ID number of your skill.

if(this.isSkill() && this._item._itemId == 13){

//Subtracts a use from this skill, and removes it if its 0

user._usesLeft -= 1;

user.setStateCounter(stateId, user._usesLeft);

if(user._usesLeft == 0)

user.removeState(12);

user.removeState(13);



}

</Custom Confirm Effect>

the first 12 is skill id. The second id is the id of the state. 13 is a state that is added to the character once the character once they use up all of that skill. This makes it so that character can't use the turret again.
Use this. You shouldn't need to change anything.

Spoiler: Code
Code:
<Custom Apply Effect>
//Set this to the number of uses the skill has.
user._usesLeft = 3;
user.setStateCounter(stateId, user._usesLeft);
</Custom Apply Effect>
<Custom Confirm Effect>
if(this.isSkill() && this._item._itemId == 13){
//Subtracts a use from this skill, and removes it if its 0
user._usesLeft -= 1;
user.setStateCounter(stateId, user._usesLeft);
if(user._usesLeft == 0)
user.removeState(stateId);
}
</Custom Confirm Effect>
<Custom Remove Effect>
user.addState(13);
</Custom Remove Effect>
Sorry for the late reply, fortunately that code worked. Thanks again for helping me.

Original thread: https://forums.rpgmakerweb.com/threads/removing-a-state-after-all-skill-uses-have-been-used-up.119886/