MV [Solved] Looking to require a shield to use a skill/skills.

Hello, fellow game makers!
I'm looking to have a skill only usable upon using a shield. Currently, my "Small Shield" is armor #101. I'm using Yanfly Skill Core and the script in the picture. Something tells me there's just a small bit off.
Thank you in advance for all your awesome help!


Spoiler
1637874434676.png
your else branch isn't corect, so remove the ( and ) and the
dataArmors [ ] is also invalid, because it doesn't contain
a number in it.

after that, it should work if you correct those.
I'm not sure what ShadowDragon means about the else branch, except that the braces are unnecessary when you only have a single statement (of course, you don't need the if/else in the first place). There are also more things wrong, so...it wouldn't work just by getting rid of that 🙄

So...gosh...where did you pick up any of that syntax? $dataArmors is not a member of Game_Item, and referencing an entire array can never equal a single value. So lets fix this up.

I'm presuming you know the order of your equipment slots and equips[1] is the slot your shield goes in. If you want to check for the item in that slot to have ID 101, you first need to check for the actor to be equipped in that slot: user.equips()[1] and then for the item ID user.equips()[1].itemId()==101

A few bits of advice as you continue to work on coding:
1 - It is a good habit to use accessor methods when provided. So call user.equips() instead of directly accessing user._equips

2 - Any time you find yourself using an if statement just to set a boolean (true/false), you can always skip that, since the result of the if statement is already boolean. So your whole notetag could be written thusly:
Code:
<Custom Requirement>
value=user.equips()[1] && user.equips()[1].itemId()==101;
</Custom Requirement>
I'm not sure what ShadowDragon means about the else branch, except that the braces are unnecessary when you only have a single statement (of course, you don't need the if/else in the first place). There are also more things wrong, so...it wouldn't work just by getting rid of that 🙄

So...gosh...where did you pick up any of that syntax? $dataArmors is not a member of Game_Item, and referencing an entire array can never equal a single value. So lets fix this up.

I'm presuming you know the order of your equipment slots and equips[1] is the slot your shield goes in. If you want to check for the item in that slot to have ID 101, you first need to check for the actor to be equipped in that slot: user.equips()[1] and then for the item ID user.equips()[1].itemId()==101

A few bits of advice as you continue to work on coding:
1 - It is a good habit to use accessor methods when provided. So call user.equips() instead of directly accessing user._equips

2 - Any time you find yourself using an if statement just to set a boolean (true/false), you can always skip that, since the result of the if statement is already boolean. So your whole notetag could be written thusly:
Code:
<Custom Requirement>
value=user.equips()[1] && user.equips()[1].itemId()==101;
</Custom Requirement>
I really appreciate you taking the time and energy to explain this, so thank you so much. I see what I was doing wrong now.
.... Or, at least, I did. I got this when I used what you gave me.
Spoiler
1637894562355.png
That's weird, for a few reasons.

1 - It works perfectly in my test game. I can use a skill when I have the right shield on, it's greyed out if I take the shield off, no errors. I even installed Selection Control and its prerequisites, still works fine.

2 - The error you're getting is from a completely unrelated plugin, you have no tags in the skill that should be making it go through Selection Control.

I suggest you make sure that your Yanfly plugins are in the correct order as listed on the YEP Web site. Then double check that they're all the latest version, and that your MV and project files are at version 1.6.2.
That's weird, for a few reasons.

1 - It works perfectly in my test game. I can use a skill when I have the right shield on, it's greyed out if I take the shield off, no errors. I even installed Selection Control and its prerequisites, still works fine.

2 - The error you're getting is from a completely unrelated plugin, you have no tags in the skill that should be making it go through Selection Control.

I suggest you make sure that your Yanfly plugins are in the correct order as listed on the YEP Web site. Then double check that they're all the latest version, and that your MV and project files are at version 1.6.2.
Lol! The Selection plug-in was in the wrong place and it was interfering. It works now, thank you!

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/solved-looking-to-require-a-shield-to-use-a-skill-skills.142456/