Check for weapon

Hey guys!
I thought about adding a guard that doesn't let the player through as long as they don't have a weapon and some armor. How can I do this, given the fact that I would need a script for this?
I was bored, so I googled it for you 😀


$gameActors.actor(1).weapons().length

$gameActors.actor(1).armors().length

Those are true if 'actor ID 1' has a weapon / armor, otherwise false. You can put them in a conditional script.
You can make a conditional branch with this script line
JavaScript:
$gameParty._actors.some((element) =>$gameActors._data[element]._equips[0]._itemId == 0 )

The statement is checking True or False - someone in the party has a empty weapon slot
I don't know if you plan to have a duel weapon class and need to check the other weapon slots. But you'd just change _equips[0] to a different slot index.
I was bored, so I googled it for you 😀


$gameActors.actor(1).weapons().length

$gameActors.actor(1).armors().length

Those are true if 'actor ID 1' has a weapon / armor, otherwise false. You can put them in a conditional script.
I did that, but I replaced Actors.actor with Party and it worked. Problem is, I can't use those together. Is there a way to do that anyway?
You can write && between them on the script-line or you can just put another conditional branch inside the first one.
You can write && between them on the script-line or you can just put another conditional branch inside the first one.
That doesn't work. Even if I have everything, the game will still think it isn't the case.
Did you try both
Code:
if($gameParty.weapons().length>1 && $gameParty.armors().length>1)
    //do stuff
and
Code:
if($gameParty.weapons().length>1)
    if($gameParty.armors().length>1)
        //do stuff
?
(Replacing the 1 with the number of weapons or armor pieces you want)
Maybe try different conditional cases?

Regardless, we think this is about having the pieces.
If you want to figure if the actor has something equiped instead, you'll have to check the $gameActors.actor(X).equips()[Y]. null when nothing equiped on that slot.
By default, slot 0 is weapon, 1 is shield or second weapon, and 3 is body.
Code:
if($gameActors.actor(1).equips()[0]) // Has actor 1 a weapon equiped?
if($gameActors.actor(1).equips()[1]) // Has actor 1 a shield/subweapon equiped?
if($gameActors.actor(1).equips()[3]) // Has actor 1 a chest armor equiped?
You can of course, remove the comment and just set the contents of each if, into a conditional branch of script call type.

Original thread: https://forums.rpgmakerweb.com/threads/check-for-weapon.149773/