ID:139041
 
Code:
bj/Jacket
icon = 'objs.dmi'
icon_state = "jacket"
Click()
if("leatherjacket" in usr.overlays)
usr.overlays -= "leatherjacket"
usr << "You take off the jacket"
else
usr.overlays += "leatherjacket"
usr << "You put the jacket on"


Problem description:
When I click the jacket, while still having it on, it keeps saying "You put the jacket on, resulting in more overlays of the leather jacket, so if the player clicks on the jacket too many times, it will be a chore to take it off.
Technically overlays is a list of icons. "leatherjacket" is not an icon. Shall I suggest a modification?

obj
Jacket
Click()
if(src in usr.overlays)
usr.overlays -= src
else
usr.overlays += src
In response to Lugia319
Good, but leatherjacket is an icon state in 'player.dmi', so how would I make "leatherjacket" overlay the player?
In response to BeignetLover
Make the icon state into an obj, then add it to the player using the following line.

src.overlays += new/obj/Jacket
In response to Gizhy
but leatherjacket and the icon "jacket" are two different icons. If I make the OBJ icon "leatherjacket" it will be animated.
In response to BeignetLover
I hope you know the "usr.overlays += new/obj/Jacket" was only an example. It's to show you what you need to do.

I'll word it more clear. Create an obj with the same icon AND icon_state as the one your trying to use. Then use "usr.overlays += new/obj/OBJ_YOU_MADE".
In response to Gizhy
I'd just like to make two quick notes.

First, you can add an overlay just by the path, you don't have to actually create the object: overlays += /obj/overlays/jacket

Second, the overlays list is not technically a list of "icons". They're a special internal datatype. See the bottom note in the reference entry. Trying to check if an overlay is already "equipped" with the in operator is probably a bad idea. You should keep track of which items the player is wearing in a separate list of your own.
In response to DarkCampainger
but to see what's in the list, I'd still need to use the in operator. Or is it just with overlays?
In response to BeignetLover
I handle this sorta deal with an obj var instead really.

obj
Jacket
var
Equipped = 0 // Equipped or not

Click()
if(src.Equipped == 0) // If it's not equipped
usr.overlays += src
src.Equipped = 1
else
usr.overlays -= src
src.Equipped = 0

In response to Lugia319
Well duh! I have no Idea why I didn't think of that. I guess it's because using if(derp in overlays) sounds cooler :P anyway, thanks
In response to Lugia319
Exactly...