MV YEP Item Requirements - Custom Requirement Help

My game uses a system where guns can be buffed by using ammo items to give it extra damage or specialized element. It also includes energy weapons and melee, which naturally would not work with ammo items, so YEP Item Requirements works great for this feature. In battle it works fine since the item only buffs the user, I just use the "Weapon Type" requirement to check whether or not the actor trying to use the ammo item is a weapon that's compatible with ammo items (I'm just going to call it a "gun" as a shorthand).

The problem is that when I try to use the ammo items out of battle, which I'd like to keep to let the player prep for upcoming battles. It seems that if the party leader is using an energy or melee weapon, no one in the party can use the item even if they are using a gun. And if the party leader is using a gun, the ammo item can then be used on any party member, even those wielding energy or melee weapons. So far I've solved the latter problem by making energy and melee weapons resist the ammo buff state, but it still consumes the item which is not ideal.

As far as I can tell, nothing in the built in requirements would help here. I suspect that there's some script that can be used to make this work, maybe something like "condition = target.equipweapontype != 1, 2"? Unfortunately I'm not familiar with javascript so I don't know what the proper code would be. If anyone could help with the code or provide some work around, that be greatly appreciated. Thanks in advance!
When using an item from the menu, one actor is the actor who is considered using the item always. That is the actor who has the highest PHA% stat, which is to say, the one who gets the greatest benefit for using restorative items is always the one who uses the actual item.

If all members have the same PHA% stat, it'd just pick the first actor in the party who had that value, which'd be the leader.

As for the requirements, you could use something like condition = target.weapons()[0] && target.weapons()[0].wtypeId == 1 to enable it if weapon type 1 is equipped, and disable it otherwise. You could also use an array to check for multiple weapontypes as well:
JavaScript:
var guns = [3, 4, 6]
var weapon = (target.weapons()[0]) ? target.weapons()[0].wtypeId : 0
condition = guns.includes(weapon)
Thanks for the response! I tried condition = target.weapons()[0] && target.weapons()[0].wtypeId == 1, but that just made it so that the item couldn't be used by anyone regardless of their equipped weapon. To clarify, I can't even reach the target selection part when trying to use the item from the menu, and it behaves as if I'm trying to use an item that can't be used at all (like a key item). According to the plugin documentation:
Item Notetags:

<Custom Enable Requirement>
condition = battler.level >= item.price;
</Custom Enable Requirement>

The 'condition' variable will determine whether or not the item will be enabled/disabled. If the 'condition' variable returns true, then the item is enabled provided all other conditions (if any) are also met. Otherwise, the item is disabled and cannot be used. The 'battler' variable will refer to the battler using the item. The 'item' variable will refer to the item being checked.
I think the plugin checks the condition prior to letting the player use the item, so it doesn't even have a chance to check the target. Is there any way to get around this?
Thanks for the response! I tried condition = target.weapons()[0] && target.weapons()[0].wtypeId == 1, but that just made it so that the item couldn't be used by anyone regardless of their equipped weapon. To clarify, I can't even reach the target selection part when trying to use the item from the menu, and it behaves as if I'm trying to use an item that can't be used at all (like a key item). According to the plugin documentation:

I think the plugin checks the condition prior to letting the player use the item, so it doesn't even have a chance to check the target. Is there any way to get around this?
Ah. Okay, so item requirements isn't the plugin we want to use then. You want YEP_TargetCore. You can use the custom target eval to make it so the item can only be used on a specific target, in this case, one who's using the correct kind of weapon.

Custom Target Eval​

For users that are proficient with JavaScript, these notetags can be used to
make custom target selections. For the targeting aspect, this will refer to
the skill/item's current scope and the targets made here will be made
independent of the scope with the exception of the target, where if a target
is selected, it will become the 'target' value.

<Custom Target Eval>
for (var i = 0; i < foes.aliveMembers().length; ++i) {
var member = foes.aliveMembers();
if (member.level % 3 === 0) targets.push(member);
}
</Custom Target Eval>
The 'targets' variable is an array that determines which are the targets
to be used during the selection process. Push the desired targets into
the 'targets' array.

Basically you'd use something like:

JavaScript:
<Custom Target Eval>
  for (var i = 0; i < allies.aliveMembers().length; ++i) {
    var member = allies.aliveMembers()[i];
    var guns = [3, 4, 6]
    var weapon = (member.weapons()[0]) ? target.weapons()[0].wtypeId : 0
    if (guns.includes(weapon)) targets.push(member);
  }
</Custom Target Eval>
Thanks for the continued help!

Unfortunately the problem persists. When using the item from the menu, it still allows the item to be used on anyone regardless of their equipped weapon. And when using the item in battle, it applies the effect to every living party member regardless of equipped weapon. To clarify, I'd like it so that during battle, the item only buffs whoever uses it, so the "User" scope is enough for that purpose. Looking at YEP Target Core, it seems like it's meant to target multiple enemies/allies based on the conditions, hence the for loop in the sample code. Maybe there's a way to change the scope so it only checks the user? Though using the item out of battle from the menu would still be an issue I think.

Alternatively, maybe there's some workaround using common events? Like, using some script for the conditional branch, or maybe a script to record the target's actor id and use that to check their equipment/and to add states? It won't be the ideal solution since it'd still waste a turn in battle, but at least it won't consume the item since the item could be refunded in the common event if used on an incompatible weapon. Or maybe there's some way to make it so that when using an item from the menu, it has the target use it instead of the party leader or the one with the highest PHA% stat so I can keep using YEP Item Requirements. That plugin still seems like the best bet so far to me.

Original thread: https://forums.rpgmakerweb.com/threads/yep-item-requirements-custom-requirement-help.146325/