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

agapad

Warper
Member
Joined
Jan 31, 2021
Messages
4
Reaction score
1
First Language
English
Primarily Uses
RMMZ
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!
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
613
Reaction score
589
First Language
german
Primarily Uses
RMMZ
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
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,976
Reaction score
2,299
First Language
EN
Primarily Uses
RMMZ
@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]);
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,785
Reaction score
1,632
First Language
English
Primarily Uses
RMMV
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.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,310
Reaction score
8,752
First Language
German
Primarily Uses
RMMV
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...
 

agapad

Warper
Member
Joined
Jan 31, 2021
Messages
4
Reaction score
1
First Language
English
Primarily Uses
RMMZ
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).
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,310
Reaction score
8,752
First Language
German
Primarily Uses
RMMV
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...
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,976
Reaction score
2,299
First Language
EN
Primarily Uses
RMMZ
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. :kaohi:
 

ShadowDragon

Realist
Veteran
Joined
Oct 8, 2018
Messages
4,685
Reaction score
1,800
First Language
Dutch
Primarily Uses
RMMV
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).
 

Latest Threads

Latest Profile Posts

Mod name: "[Game name] Gameplay Overhaul"
What they actually mean: "Here is a mod that makes the game harder."
I decided to reinstall one of my most favourite game of all times, Gothic 2. Time to get back to Khorinis!
So much game make... I needs to rest. The foods call.
-Casino with bunnysuit green check.png
1638563168795.png
Monday December 6th 2021 at 7PM Hawkzombie will stream A Thief's Voyage on his Twitch.

Hawkzombie Twitch

Check it out.​

Forum statistics

Threads
117,163
Messages
1,105,063
Members
153,249
Latest member
Jon_Doe
Top