Yanflys Skills Cost Item not checking equipped items.

Hey there gang. I have been trying to fix this for a while but I am not a coder so I am a little lost. I feel like I am on the right track but I haven't been able to correct the issue.

I have a bow and arrow system where you put the arrows in your offhand slot as a weapon. When you use the bows attack it fires an arrow and removes 1 from your inventory. The problem comes when there is only 1 arrow left, the one equipped to the offhand.

What I have been able to determine is the Yanflys Skills cost Items plugin is not checking the equipped slots and removing the item from there, if there is one. When your turn comes up, if you only have the equipped arrow left, the skill will be greyed out.

What I was hoping is if someone could adjust the script to allow it to check for and remove items that are equipped. I found this in a post here from Shaz:

JavaScript:
    case 9:  // Weapon

        result = $gameParty.hasItem($dataWeapons[this._params[1]], this._params[2]);

        break;
parameter 1 is the weapon, parameter 2 is whether you want to also look for equipped stuff.

I searched Yanflys plugin for $dataWeapons and found a few locations to which I tried to add, this._params[2] This has allowed me to see that there is an equipped arrow but it does not remove the arrow, and I believe it is throwing an error but I can't seem to get my console to display it.

I would love if anyone could help with this, I'll post a link to the script below, but it's a paid plugin now so if you need me to post any sections please let me know.

Plugin
AFAIK Victor's Skill Ammunition is compatible with Yanfly's plugins and has an option that requires the ammunition to be equipped for a skill to be used. It also has an eval, so you can use just one attack skill for all your weapons and only require ammunition if, say, a bow or gun is equipped. It could be easier, but if you don't want to swap for whatever reason I'll take a look at Yanfly's plugin and see what I can do
Hmm, I have kind of stayed away from vs's plugins so far just because I use other peoples and was trying not to branch out too much. I'll take a look though as right now the ammo system just looks bad if it leaves the one ammo.

Thanks for letting me know about that and also thanks for taking a look at Yanfly's plugin, I would definitly prefer to stay with the yanfly set up I have if possible. 🙂
Edit:

I just took a look and VS's plugin has pretty much the same issue, if an item is equipped and it's the last one it doesn't take the items damage into account. It apparently unequippes the arrow before the attack happens.
I just took a look and VS's plugin has pretty much the same issue, if an item is equipped and it's the last one it doesn't take the items damage into account. It apparently unequippes the arrow before the attack happens.
Could you clarify what you mean by doesn't take the item's damage into account? Do you mean the stat bonuses the arrows give? Or something else?
Yeah the arrow is a weapon so it will take the attack value from its damage parameter on the arrow into account, it's really just a fancy dual wield attack but the different arrows are where the real damage comes from .

Victors plugin is apparently removing the arrow before the damage calculation, which isn't what is happening with yanfly's plugin but has the same result. It seems like if yanfly's plugin gets fixed the problem victor had may show up then in yanflys.
Yeah if you edited Yanfly's to check equipped items it'd still take away the arrow before damage calculation because skill costs are payed before damage calculation. It seems like a lot of work to rewrite those plugins to work how you want, and unfortunately it's a bit out of my skill range. I'll look around and see if there's any other plugin/janky fix I can think of though
Yeah no worries it is much more involved than I thought it would be. Thanks for taking the time to get us to that conclusion. I can just stick with one of the methods I have been using.

Until now I had just said oh think of the last arrow as a recipe template you can't spend. But taking all the other stuff you can craft that makes even less sense. But I have a way to remove the last arrow if you fire the second to last arrow. I was going to move to that and somehow boost the damage, but then if someone tries to equip just one arrow they wouldn't be able to fire it so that kind of sucks too hehe.

Anyways I'll see what I can come up with. A huge thanks for taking the time to look into this. 🙂
Alright, I have some code that should work, but you'll have to change your arrows to a type of armor, preferably the same equip type as shields. Put this in your skill's notebox
Spoiler: Code
Code:
<Custom Requirement>
  //Initializes the value as false
  value = false;
  //Initializes the arrow Id
  user._arrowId = user._arrowId || 0;
  //Replace these with your arrows armor Ids
  var arrowIds = [1,2,3];
  //Checks if the user has an arrow equipped, and if so allows use of the skill
  for(var i = 0; i < arrowIds.length; i++){
    if(user.isEquipped($dataArmors[arrowIds[i]])){
      user._arrowId = arrowIds[i];
      value = true;
    }
  }
</Custom Requirement>
<Post-Damage Eval>
//If the user has an arrow equipped
if(user._arrowId != 0){
//Destroys the equip, then adds one from the inventory
user.discardEquip($dataArmors[user._arrowId]);
user.changeEquip(1,$dataArmors[user._arrowId]);
}
</Post-Damage Eval>
This should work, let me know if there's any issues or if you want something different
Hey there, wow this is a surprise. 🙂 A big thanks but I'm not sure if it's working. Was all I am suppose to change:

var arrowIds = [1,2,3];
I set it to = [419]

I only made one armor arrow so far so not sure if that has anything to do with it but it isn't consuming the final arrow. When the final arrow comes up the skill is greyed out and the arrow is still equipped.

Sorry to be a pain.🙂
Hmm. Everything is working fine on mine. Do you still have Yanfly's skill cost items on the skill you're using?
Okay that was it I overlooked changing the skill cost to armor. And wow this is amazing! 🙂
Thank you sooo very much for this. The system works perfectly now and doesn't have some stupid explainer why I couldn't make it work like one would expect hehe.

This has been an issue I have fought with for a very long time now so I am super excited. I'm going to toss you in the special thanks section of my games credits if ya don't mind. I really appreciate this.
This has been an issue I have fought with for a very long time now so I am super excited. I'm going to toss you in the special thanks section of my games credits if ya don't mind. I really appreciate this.
Awww, thank you so much! And just so you know, with my little lunatic code snippet you don't strictly need Yanfly's skill cost plugin unless you want players to be able to attack with arrows they don't have equipped. Everything is handled by the Skill Core plugin on its own.
That is great news as well. I am running into an issue though it seems. The arrows seem to be being used by 2 at a time for some reason and if you equip an arrow while only having one of that type it doesn't recognize the single equipped arrow.

Also is Rainyday okay for the credits or would you prefer a different name.
Could you take a screenshot of your skill and post it? Put the notebox in a spoiler too. That'll be easier for me to see what's going wrong on your end. And yeah, you can credit me by Rainyday
Np here ya go.
Spoiler: Skill
<Steal: -50%>

<Attack Text: Wood Arrow>

<Select Conditions>

Any Row

</Select Conditions>

<Cannot Counter>

<Armor 419 Cost: 1>

<Custom Requirement>

//Initializes the value as false

value = false;

//Initializes the arrow Id

user._arrowId = user._arrowId || 0;

//Replace these with your arrows armor Ids

var arrowIds = [419];

//Checks if the user has an arrow equipped, and if so allows use of the skill

for(var i = 0; i < arrowIds.length; i++){

if(user.isEquipped($dataArmors[arrowIds])){

user._arrowId = arrowIds;

value = true;

}

}

</Custom Requirement>

<Post-Damage Eval>

//If the user has an arrow equipped

if(user._arrowId != 0){

//Destroys the equip, then adds one from the inventory

user.discardEquip($dataArmors[user._arrowId]);

user.changeEquip(1,$dataArmors[user._arrowId]);

}

</Post-Damage Eval>

Spoiler: Pics
s.jpg

ss.jpg
Take out <Armor 419 Cost: 1> from the skill
There we go it's working perfectly now sorry about that. 🙂 Thanks for helping me get it figured out. I was trying everything but I never thought to remove that command hehe. You're the best @rainyday

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/yanflys-skills-cost-item-not-checking-equipped-items.118058/