How to check if the player has a certain weapon equipped?

Hello,

I am new to the scripting in RPG Maker.
I want the script to check if the Player has equipped himself with a weapon.

That's what I tried but it doesn't work:

0002 - Actor's ID
0007 - Weapon ID

1633530317128.png



Please let me know whether I missed something?

Thank you!
This code will check if the 2nd Actor from your Party (that is NOT the same as the 2nd Actor from your Database) has any weapon equipped.

Code:
$gameParty.members()[1].weapons().length > 0

If you want to check, if the Actor has the Weapon with Id 7 selected, do this:

Code:
$gameParty.members()[1].weapons().some(weapon => !!weapon && weapon.itemId() == 7)

Tell me if it works for you.

EDIT: corrected, thanks to @caethyril
@agapad - that's a VX Ace script call, you'll need something different for MV:
@Aerosys - members() returns an array and does not expect any arguments.

If you know which actor to reference then you can use Conditional Branch -> Actor -> Weapon, no scripting necessary. Otherwise...
  • Does actor ID 2 have weapon ID 7 equipped?
    JavaScript:
    $gameActors.actor(2).hasWeapon($dataWeapons[7]);
  • Does the party leader (i.e. position 0) have weapon ID 7 equipped?
    JavaScript:
    $gameParty.members()[0].hasWeapon($dataWeapons[7]);
Just a quick addition - you saw the example from Aerosys and caethyril, but it should be stated explicitly. Do not include leading zeros as you did in your initial event, or the engine will try to interpret it as an octal value.
I want the script to check if the Player has equipped himself with a weapon
why use a script call at all?
weaponcheck.png



and by the way:
NEVER use leading zeros in programming.
the ID is 7, it is NEVER 0007
because the leading zeroes are a programming override to octal numbers...
Thank you very much for all your help. I was not aware of the fact that the conditional branch as screenshoted above will actually check if the Player has a weapon equipped (not only in possession).
I was not aware of the fact
the event commands are designed to handle the usual checks and effects needed for a regular RPG, so whenever you have a task of something RPG-tyypical, it usually pays to check if the events can do it without problems.
Some cases are a bit hidden (like the game data section of control variable) and others require a bit of indirect solutions (load number into variable before using conditional branch on that variable), but scripts plugins should actually be the final approach, not the first idea...
Many elements of the editor (including those Conditional Branch options) should show a help tip if you hover over them with the cursor.

Have you got things working now? If so then I'll close the thread. 👋
or if you want to check the equip list and item, you can use something
like this:

JavaScript:
$gameActors.actor(1).equips()[3].id === 42

this check equipID 3 (depending how you set it up in your system)
with dataEquip ID = 42.

all equips are in the ID, so equipID 3 and iem ID 42 cannot be checkt
if equipID = 2 with itemID 42 (sword, armor, boots, etc etc).

this is specific check on equipted item.

you can use "||" (for or) and "&&" (for and) if you want to check multiple
armors (to change armor set for example).

Original thread: https://forums.rpgmakerweb.com/threads/how-to-check-if-the-player-has-a-certain-weapon-equipped.141056/