Check if Actor has Accessory/Head/Body Armor Equipped

Hello guys!


Quick question.... How do you put in the conditional branch script call if you want to check if Actor 'A' has a Body armor equipped? Same goes for Accessory and Headgear.


To put it simply, I'd like to check if the armor slot (based on equip type) is empty or not.


Something similar to this: $game_actors[12].weapons.empty? 


but that was for weapon, how about headgear/accessory/etc. ?


I don't think $game_actors[12].armors.empty?  will be able to tell specifically based on it's equip type..


Please help, guys.. Thanks a lot.
Code:
!$game_actors[12].equips[slot_id].object.nil?



will be true if the slot is filled, and false if there is nothing there.  Replace slot_id with 0:weapon, 1:shield, 2:head, 3:body, 4:accessory.
I have been trying for a while to do the exact same thing, but I don't see how to use that script call.  If I put it into a conditional branch, so that if true the NPC says one thing, if false says another, I get an error message because the conditional cannot detect whether it is true or not.  Presumably there's another step required?
Code:
!$game_actors[12].equips[slot_id].object.nil?



will be true if the slot is filled, and false if there is nothing there.  Replace slot_id with 0:weapon, 1:shield, 2:head, 3:body, 4:accessory.

I tried using


!$game_party.members[0].equips[4].object.nil?


to check the 1st member's accessory, but it comes up with an error message says: undefined method 'object' for nil:nilclass


or something like that... I tried new game but it doesn't work... Did I do something wrong?
I wonder if it compresses the array so there are no 'empty' elements ...


Can you please try this in a script call, and play with the console on, and let me know what it says?  Might need to grab a screenshot of the console window, as you can't copy/paste from it:

Code:
p $game_party.members[0].equips.to_s
That's the same error message I got, and I tried it in new game.  I see you changed the script call to party.members, but that's not the cause as I got it with game_actors as per the original.
Just did some testing.  Leave out .object

Code:
!$game_party.members[0].equips[4].nil?

or 

!$game_actors[id].equips[4].nil?



will be true if the actor/party member has an accessory equipped.
I wonder if it compresses the array so there are no 'empty' elements ...


Can you please try this in a script call, and play with the console on, and let me know what it says?  Might need to grab a screenshot of the console window, as you can't copy/paste from it:

Code:
p $game_party.members[0].equips.to_s

This is what it says: console.png


FYI my first party member only got a weapon equipped and the rest of the slots are empty
I figured out the problem and the solution is above your post.
Works fine for me.


Thanks.
Just did some testing.  Leave out .object

Code:
!$game_party.members[0].equips[4].nil?

or 

!$game_actors[id].equips[4].nil?



will be true if the actor/party member has an accessory equipped.

Alright thanks a lot! It worked perfectly!

Original thread: https://forums.rpgmakerweb.com/threads/check-if-actor-has-accessory-head-body-armor-equipped.70734/