ID:157532
 
In my game I have it so that you can have different clothes in your inventory and that if you click the clothing item, it adds it to your character as an overlay.

But I also want it so that if you click the clothing item when it's already on you, it'll check if that clothing icon's already in your overlays variable and take off the clothing overlay if it is.

So how do I detect if a certain icon (like the icon of certain clothing items being clicked on) is already being used as a user's overlay?

"if(M.icon in src.mob.overlays)" and "if(M in src.mob.overlays)" in "client/Click(mob/M)" always come out as false for me.
How about you just subtract the overlay regardless. If it's in the overlays list, it'll be remove.
In response to Spunky_Girl
It's because there's a bunch of different type of clothes in my game that can be worn at the same time (hats, glasses, jackets)

so when something is clicked, it checks if the mob's accessory variable is 1, and if so then that's where the overlay check would happen.

It can't just subtract the overlay since it's different depending on what cloth item was clicked.

For example of what I'm trying to explain, my code that doesn't work looks like this so far:

            if(M.accessory==1)
if(M in usr.contents)
if(M.icon in src.mob.overlays)
src.mob.overlays -= M
src << "You take off '[M.name]'"
else
src.mob.overlays += M
src << "You put on '[M.name]'"
In response to MartialArtistAbu
set up a different variable for each item 0_0. Since there are different layers for clothing anyways. Its more time consuming but less mind boggolingg.
In response to Darkjohn66
I thought of that before and it was how I handled it in the game 6 years ago, but I'd prefer a way that doesn't involve multiple variables and checks ...

Although there's different types of clothing, there's still multiple things people can wear just on their head at the same time like glasses and a bow and a little cap
In response to MartialArtistAbu
There's two solutions to this problem I believe.

1. If you'd like, create a variable for each "body part", ie hands, torso, etc, that stores the object itself that's being added to the overlays, and then when you want to "replace" that overlay, subtract it from the overlays before storing the other object.

mob/var/hands = list()
obj/clothing/hands/gloves
verb/equip()
if(usr.hands == src) usr.overlays =- src
else usr.overlays += src


2. Do what I do, and have a separate list to handle overlays that stores objects themselves rather than just the icons like what the overlays list does. Then you can use that list instead of the "special" built in one.

mob/var/list/overs = list()
obj/clothing/hands/gloves
verb/equip()
if(src in usr.overs) usr.overlays -= src
else usr.overlays += src
You could always set the users overlays to null every time they equip/unequip an item, and then just re-add all the overlays they will need.
//our equipment
mob/player/var/list/equipment=list()

mob/proc/control_overlays(obj/equipment/o)
//if the item is not equipped remove the overlay
if(src.equipment[o.slot]!=o || !(src.equipment[o.slot]))
src.overlays-=src.equipment[o.slot]
src.overlays-=o
//if it is add it
else
src.overlays+=equipment[o.slot]

obj/equipment
//the slot that the item is equipped to
var/slot
verb/equip()
var/mob/player/p=usr
//add the item to the spot in equipment
p.equipment.Add([src.slot]==src)
//then call the overlays proc
p.control_overlays(src)

verb/unequip()
var/mob/player/p=usr
//remove the item
p.equipment.Remove([src.slot])
//..
p.control_overlays(src)

//a new equipment type
head
//the types slot this is where it will be located in\
our equipment

slot="Head"