Help fixing weird bug/issue with Visustella's SkillStatesCore

Im pretty new to RPGMaker so bear with me. Im trying to make a character that uses items to use their skills. Im trying to use the notetags.

Code:
<Item Cost: 1 Item>

Like So

Code:
<Item Cost: 1 Mandrake>

<Item Cost: 1 Sage>

The items exist as follows

1690647017222.png



When I try to use the notetag, they work fine, but once they use the ability, this happens.

1690647109373.png


Here is the stacktrace

Code:
at Game_Actor.eval (eval at VisuMZ.<computed> (VisuMZ_1_SkillsStatesCore.js:1), <anonymous>:12:20)
    at Game_Actor.Game_BattlerBase.<computed>.<computed> (VisuMZ_1_SkillsStatesCore.js:3081)
    at Game_Actor.Game_BattlerBase.<computed>.<computed> [as paySkillCost] (VisuMZ_3_LimitedSkillUses.js:552)
    at Game_Actor.Game_Battler.useItem (rmmz_objects.js:3820)
    at Function.BattleManager.startAction (rmmz_managers.js:2746)
    at Function.BattleManager.<computed> [as startAction] (VisuMZ_1_BattleCore.js:19990)
    at Function.BattleManager.<computed> [as processTurnCTB] (VisuMZ_2_BattleSystemCTB.js:1690)
    at Function.BattleManager.<computed> [as processTurn] (VisuMZ_2_BattleSystemCTB.js:1690)
    at Function.BattleManager.updateTurn (rmmz_managers.js:2616)
    at Function.BattleManager.<computed> [as updateTurnCTB] (VisuMZ_2_BattleSystemCTB.js:1690)

Ive tried figuring out what the issue is, but im not great with javascript.
I found this for the paying skill cost, where item does not seem to be defined, but im unsure how to fix it. Any help would be greatly appreciated.
Code:
// Declare Variables
const user = this;
const skill = arguments[0];
const cost = arguments[1];


// Process Payment
{ // Check Item Costs
    for (let id in cost.items) {
        const obj = $dataItems[id];
        if (obj && item.consumable) {
            if (item.itypeId !== 2) {
                const costAmount = cost.items[id];
                $gameParty.loseItem(obj, costAmount);
            }
        }
    }
}
{ // Check Weapon Costs
    for (let id in cost.weapons) {
        const obj = $dataWeapons[id];
        if (obj) {
            const costAmount = cost.weapons[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}
{ // Check Armor Costs
    for (let id in cost.armors) {
        const obj = $dataArmors[id];
        if (obj) {
            const costAmount = cost.armors[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}
I have moved this thread to JavaScript/Plug-in Support.
as far as I can tell,
Code:
item
doesn't exist -- which is why it says not defined.

Head over to VisuMZ_1_SkillsStatesCore > Skill Cost Types > Item Cost > JS: Paying Cost >

Spoiler: Original Code
Code:
// Declare Variables
const user = this;
const skill = arguments[0];
const cost = arguments[1];

// Process Payment
{ // Check Item Costs
    for (let id in cost.items) {
        const obj = $dataItems[id];
        if (obj && item.consumable) {
            if (item.itypeId !== 2) {
                const costAmount = cost.items[id];
                $gameParty.loseItem(obj, costAmount);
            }
        }
    }
}
{ // Check Weapon Costs
    for (let id in cost.weapons) {
        const obj = $dataWeapons[id];
        if (obj) {
            const costAmount = cost.weapons[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}
{ // Check Armor Costs
    for (let id in cost.armors) {
        const obj = $dataArmors[id];
        if (obj) {
            const costAmount = cost.armors[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}

Replace with:
Spoiler: New Code
Code:
// Declare Variables
const user = this;
const skill = arguments[0];
const cost = arguments[1];

// Process Payment
{ // Check Item Costs
    for (let id in cost.items) {
        const obj = $dataItems[id];
            if (obj.consumable && obj.itypeId !== 2) {
                const costAmount = cost.items[id];
                $gameParty.loseItem(obj, costAmount);
        }
    }
}
{ // Check Weapon Costs
    for (let id in cost.weapons) {
        const obj = $dataWeapons[id];
        if (obj) {
            const costAmount = cost.weapons[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}
{ // Check Armor Costs
    for (let id in cost.armors) {
        const obj = $dataArmors[id];
        if (obj) {
            const costAmount = cost.armors[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}
as far as I can tell,
Code:
item
doesn't exist -- which is why it says not defined.

Head over to VisuMZ_1_SkillsStatesCore > Skill Cost Types > Item Cost > JS: Paying Cost >

Spoiler: Original Code
Code:
// Declare Variables
const user = this;
const skill = arguments[0];
const cost = arguments[1];

// Process Payment
{ // Check Item Costs
    for (let id in cost.items) {
        const obj = $dataItems[id];
        if (obj && item.consumable) {
            if (item.itypeId !== 2) {
                const costAmount = cost.items[id];
                $gameParty.loseItem(obj, costAmount);
            }
        }
    }
}
{ // Check Weapon Costs
    for (let id in cost.weapons) {
        const obj = $dataWeapons[id];
        if (obj) {
            const costAmount = cost.weapons[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}
{ // Check Armor Costs
    for (let id in cost.armors) {
        const obj = $dataArmors[id];
        if (obj) {
            const costAmount = cost.armors[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}

Replace with:
Spoiler: New Code
Code:
// Declare Variables
const user = this;
const skill = arguments[0];
const cost = arguments[1];

// Process Payment
{ // Check Item Costs
    for (let id in cost.items) {
        const obj = $dataItems[id];
            if (obj.consumable && obj.itypeId !== 2) {
                const costAmount = cost.items[id];
                $gameParty.loseItem(obj, costAmount);
        }
    }
}
{ // Check Weapon Costs
    for (let id in cost.weapons) {
        const obj = $dataWeapons[id];
        if (obj) {
            const costAmount = cost.weapons[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}
{ // Check Armor Costs
    for (let id in cost.armors) {
        const obj = $dataArmors[id];
        if (obj) {
            const costAmount = cost.armors[id];
            $gameParty.loseItem(obj, costAmount);
        }
    }
}
Thank you, oddly enough it randomly stopped doing it, I dont think I changed anything. If it does it again I will certainly use this. Thanks for your help.
Not sure if I'm allowed to keep this thread alive but here goes...

I was having the exact same problem as OP. I copy/pasted the new code you wrote and it worked!

But there's one problem - the items aren't deducted from the inventory. Says they cost items but they don't in practice. Any idea? Thanks!
According to this thread, it was a bug in the plugin corrected in the latest version.
Not sure if I'm allowed to keep this thread alive but here goes...

I was having the exact same problem as OP. I copy/pasted the new code you wrote and it worked!

But there's one problem - the items aren't deducted from the inventory. Says they cost items but they don't in practice. Any idea? Thanks!
Have you checked to see if your item is Consumable?
1692419227012.png


According to this thread, it was a bug in the plugin corrected in the latest version.
The latest version seems to have the same issues, unless Sample Project Update 128 doesnt have the update applied(Did a brief test)
That was it. Case closed. Thanks!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/help-fixing-weird-bug-issue-with-visustellas-skillstatescore.159835/