Checking for weapon in the inventory

I'm using Hime's hidden choice conditions and I would like some choices to only be available once certain weapons are in player's posession. The plugin command looks like this:
1589832958040.png


What's the javascript for checking if the player has a weapon in their inventory? I need it to detect the weapon whether it is equipped or not. But as long as it's there, the choice should be visible.
This is what the script call master list says for checking to see if an actor has specific equipment equipped.

# Check for Name/ID of Player Equipment
# ----------------------------------------------
$game_actors[X].equips[Y].id unless $game_actors[X].equips[Y] == nil
# Returns the ID of the equipment on actor X, equipped in slot Y
$game_actors[X].equips[Y].name unless $game_actors[X].equips[Y] == nil
# Returns the name of the equipment on actor X equipped in slot Y
# NOTE: If using any scripts that give or take equipment slots, the #Y is the number of the character's slot
# not the slot's number in the script. I.E. using Yanfly Equip Menu script - if your character has equipment
# slots 6,7,8,15,15,32,75 available then $game_actors[1].equips[0].id would return the ID of the
# item equipped in the slot defined as slot 6 in Yanfly script because it's the 1st equipment slot for the
# specific character.

Code:
if ($gameActors.actor(actorId).equips()[n]) {
return $gameActors.actor(actorId).equips()[n].id;
};
if ($gameActors.actor(actorId).equips()[n]) {
return $gameActors.actor(actorId).equips()[n].name;
};
Ok, but this checks for what's equipped, not what is in the player's posession. Thanks for linking the list by the way - will come in handy in the future, but I can't find what I'm looking for there :/
Hi there!
I think you can try:
$gameParty._weapons[ID]
$gameParty._armors[ID]
$gameParty._items[ID]

If you do not have it, this will return false.
Doesn't work, unfortunately.
Try this.

JavaScript:
($gameParty._weapons[1] >= 1 || $gameActors.actor(1)._equips[0]._itemId == 1)

$gameParty._weapons[1] >= 1 checks if you have 1 or more of that weapon id in your inventory. returns true/false.

$gameActors.actor(1)._equips[0]._itemId == 1 checks if you have that weapon equipped to your weapon slot. returns true/false.

if one of the conditions is true it will return true, if neither returns true it returns false.

The values you see above are shown below in plain text so you can edit them easier.

$gameParty._weapons[weaponId] >= quantity
OR
$gameActors.actor(actorId)._equips[equipslot]._itemId == weaponId

you can leave equipslot value as 0 most likely unless you use a plugin which changes equip slots around.
It doesn't work, unfortunately.

It works to check if you have this weapon or armor or item in the inventory.
JavaScript:
◆Script:hide_choice(2, $gameParty._weapons[1])

But if you want to check in the inventory AND the equipped weapons, like if the player have the weapon anywhere, equipped by any actor:

JavaScript:
◆Script:hide_choice(2, $gameParty._weapons[1] || $gameParty.isAnyMemberEquipped($dataWeapons[1]))

for weapons:
Inventory > $gameParty._weapons[ID]
Equipped > $gameParty.isAnyMemberEquipped($dataWeapons[ID]))

for armors:
Inventory > $gameParty._armors[ID]
Equipped > $gameParty.isAnyMemberEquipped($dataArmors[ID]))

for items:
Inventory > $gameParty._items[ID]
What ultimately worked:

function hasWeapon(weaponId) {
var bool = ($gameParty._weapons[weaponId] != null && $gameParty._weapons[weaponId] > 0);
if (bool) {return true;}
for (actorId in $gameParty._actors) {
bool = $gameActors.actor($gameParty._actors[actorId])._equips[0]._itemId == weaponId;
if (bool) {return true;}
}
return false;
}

Thank you everything for trying to help 🙂
Thread closed kl

Original thread: https://forums.rpgmakerweb.com/threads/checking-for-weapon-in-the-inventory.121738/