A script call to check if the player has a piece of armour equipped? (Solved)

Hello, I'm looking for a script call to check if the player is wearing a certain piece of armour.
I want to make a common event that would change the actor's graphic depending on the armour they have on.
Something like this:

Condition: wearing item y -> change graphic to 1
Condition: wearing item x -> change graphic to 2
Condition: wearing item x && wearing item y -> change graphic to 3

The game I'm making is very small so I think it'll be easier to use a common event rather than a script, if it's possible.
There are only two pieces of armour in the game.
I'd appreciate it if anybody helped me with this.
You can check that by using this:
Code:
$game_actors[actor_id].equips[3] == $data_armors[armor_id]
Put it either as a condition for your conditional branch or as a standalone script call that includes the graphic changes as well.

You have to change "actor_id" and "armor_id" to be real IDs.

The number 3 refers to the armor, if you want to access a different equipment you have to use a different number there.
0 -> Weapon
1 -> Shield
2 -> Head
3 -> Body
4 -> Accessory

EDIT: If you want you can simply compare the equipped item ID with the one of the item that you are checking. This goes under the assumption that the equipped item and the one you are going to check are part of the same array (both armors or both weapons).

This, however, doesn't work if you are checking the dual-wielding slot as it might contain a weapon instead of an armor.

Code:
$game_actors[actor_id].equips[slot_id].id == item_id
You have to change actor_id, slot_id and item_id to be real IDs.

actor_id -> your actor ID (the one you are going to inspect)
slot_id -> the equipment slot where the item is supposed to be (see above)
item_id -> the id of the item you are comparing it to
Thank you, this is very helpful.
However I've noticed that I might have to change the conditions a bit, because the second and the third seem to override the first one.

I figure it would be something like this:
Condition: wearing item y and not wearing item x -> change graphic to 1
Condition: wearing item x and not wearing item y -> change graphic to 2

How do I make a "negative" condition?
If you press F1 and check ruby syntax you have a thorough explanation on how negative conditions work. In your situation you can use this:
Code:
($game_actors[actor_id].equips[slot_id].id == item_id) && ($game_actors[actor_id].equips[another_slot_id].id != other_item_id)
The first part of it checks if the item with ID equal to item_id is equipped in slot with ID equal to slot_id, the last part (in the parenthesis) checks if the other slot (another_slot_id) contains an item that is not the one with ID equal to other_item_id. The "&&" part then checks if both conditions are true.
Similarly you can do this:
Code:
($game_actors[actor_id].equips[slot_id].id != item_id) && ($game_actors[actor_id].equips[another_slot_id].id == other_item_id)
or this:
Code:
($game_actors[actor_id].equips[slot_id].id == item_id) && ($game_actors[actor_id].equips[another_slot_id].id == other_item_id)

However, doing so requires a very long condition and I do not recommend doing it that many times. It is hard to modify later on. What I recommend is checking if one item is equipped first. If it is not, there is no way both items are equipped (since one is already missing). You can then check the other slot in both branches with a different meaning each time: in the else branch it means only that one is equipped, otherwise both are equipped.

Code:
@> Conditional Branch: ($game_actors[actor_id].equips[slot_id].id == item_id)
  @> Conditional Branch: ($game_actors[actor_id].equips[another_slot_id].id == other_item_id)
    @> Comment: If you are here both items are equipped
    @>
  @> Else
    @> Comment: If you are here only the first item is equipped
    @>
  @> End
@> Else
  @> Conditional Branch: ($game_actors[actor_id].equips[another_slot_id].id == other_item_id)
    @> Comment: If you are here then only the second item is equipped
    @>
  @> End
@> End
I figured it out myself before you replied.
The way I wrote this was:

Change graphic to 0
Condition: $game_actors[1].equips[2] == $data_armors[61] && $game_actors[1].equips[4] == $data_armors[62]
>Change graphic to 3​
Condition: $game_actors[1].equips[2] == $data_armors[61] && !($game_actors[1].equips[4] == $data_armors[62])
>Change graphic to 2​
Condition: $game_actors[1].equips[4] == $data_armors[62] && !($game_actors[1].equips[2] == $data_armors[61])
>Change graphic to 1​

It works and I haven't noticed the game being slower or anything like that. I don't plan on adding any new equippable items so I think I'll leave the common event as it is. Thank you for your help.
@kat821 When your query is resolved to your satisfaction, please Report your post and ask for the thread to be closed. Mods may not see an individual post, or a change in the title, but will see a Report. In this instance, someone else Reported it so that it could be picked up.
Thanks.

Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/a-script-call-to-check-if-the-player-has-a-piece-of-armour-equipped-solved.107935/