ID:1372086
 
(See the best response by Ss4toby.)
Code:
obj/proc
itemCreation(mob/user/p , obj/item/clothe/i , var/color)
var/obj/item/clothe/z = new i.type
if(istype(i, /obj/item/clothe/shirt))
i.icon = p.gender == "male" ? 'male shirt.dmi' : 'female shirt.dmi'

z.icon = i.icon

if(i.canDye) z.icon += color

z.Move(p)

/////// this is how I equip the items
else if(istype(src, /obj/item/clothe))
if(!usr.buying)
if(!worn)
worn = 1
usr.overlays += src
src.suffix = "Equipped"
usr << "You equip: [src]----Type: [src.type]"

else
src.worn = 0
usr.overlays -= src
src.suffix = "


Problem description: My problem is that when I unequip an item, the icon stays. It's not removed from the player.

Best response
Oddly enough the easiest solution I could find was instead of overlays += src and overlays -= src, to use src.icon instead..

//equip
usr.overlays += src.icon

//unequipt
usr.overlays -= src.icon


Now, if you are depending on layers then this method would not be idea at all. So, an alternative (although not really great) is to use a separate list and simply apply that.

mob/var/list/overlayObjects=new/list

obj/Stuff
Click()
if(!src.suffix)
src.suffix="Equipt"
else
src.suffix=""
usr.overlays=usr.overlayObjects


There are several cons to using the second method I showed. First con would be by applying a list, it creates memory build, which will slow down the server(memory = lag without CPU in essence).

To help prevent memory build, use a procedure to check if the list is null or empty. If list is null when adding an object, have the procedure set the list to new/list and then add the object. If the list is empty when after an object is removed, have the game transform the list to null. Also, you really want to use world/mob=mob/whatever, this will help crop variables. BYOND basically adds X amount of memory per variable, and this depends on the type (number, string, list). So, the more variables every single base path has, the more memory is used. Therefore, if an extra variable can be avoided, it's idea to do so.

Example of the best way I can think of:
world/mob=/mob/Attackable/Player//This set default player mob to this path

mob/Attackable
var
list/overlayObjects
Player
desc="You are a player mob, given to clients by default."
var
randomExample="this was just a random example"
proc
addOverlay(obj/O)
if(isobj(O))
if(!istype(overlayObjects,/list/))
overlayObjects=new/list
overlayObjects+=O
overlays=overlayObjects

removeOverlay(obj/O)
if(isobj(O))
if(istype(overlayObjects,/list/))
overlayObjects-=O
if(overlayObjects.len==0)
overlayObjects=null
overlays=new/list
else
overlays=overlayObjects

obj/Cloth
icon='Shirt.dmi'
layer=MOB_LAYER+2
verb/ChangeColor(var/color as color)
src.icon=icon(initial(icon))//This tid-bit will use the icon that was originally pathed in the scripts
src.icon+=color
Click()
var/mob/Attackable/m
if(istype(usr,/mob/Attackable/))
m=usr
else
return
if(!src.suffix)
src.suffix="Equipt"
m.addOverlay(src)
else
src.suffix=""
m.removeOverlay(src)


As a heads up, if you decide to go with the last mentioned method, you will want to use addOverlay with icons as well. This being, because when add/removeOverlay are ran, they will set overlay to them, making anything added to the players overlay but not in the list disappear (from overlapping them of course).
In response to Ss4toby
obj/items
suffix = "Unequipped"
Click()
if(src.suffix == "Unequipped")
src.suffix = "Equipped"
usr.overlays += src
else
src.suffix = "Unequipped"
usr.overlays -= src

mob/proc/reload_icons()
for(var/obj/o in src.contents)
if(o.suffix == "Equipped")
src.overlays += o

When you are saving your player, remove all icon, overlays, and underlays data from the savefile and reload it when loading the player.

mob
Write(savefile/f)
..()
f["x"] << src.x
f["y"] << src.y
f["z"] << src.z
// remove any data that's can be repopulated at log in
f.dir.Remove("icon", "overlays", "underlays")
Alright so I would like to thank Ss4toby for that gem he shared about variables and memories. He's on the right track. Actually, I think he's right on the train. Is there another way to do this though?
Other than the two mentioned and Neimo's no there isn't. Like I said, you can simply use src.icon, but you won't be able to apply dynamic layering to it. Also, there is a way that might work with images instead of icons, I haven't tested it but it seems like it would work.

Neimo's method might be best. Unless you are worried about order not being stuck with(which shouldn't be an issue if you are using layers).

How about this, are you using layer or do you just want the image to appear over the layer and have the player worry about which they click on first XD? That little tid bit might help to give you a good answer.
In response to Ss4toby
Well I have a hair object and it's not under the /obj/item though. If I use "usr.overlays += src.icon," the item is underneath the hair object. If use "usr.overlays += src" and "usr.overlays -= src" the item is not removed from the mob.

Should I just put everything inside a list and equip it that way?
Well, the methods me and Neimo mention would work best for your described situation.
Alright then. I will put the hair object under and obj/item and work my way from there. Thank you!
In response to Ss4toby
So I decided to go with your last example. Everything looks good except for an undefined variable i,m getting.

Error: "items.dm:460:error: m.addOverlays: undefined proc
items.dm:466:error: m.removeOverlays: undefined proc
items.dm:453:warning: m: variable defined but not used
"
Not sure why i'm getting this problem.

world
fps = 25 // 25 frames per second
icon_size = 32 // 32x32 icon size by default

view = "24x22" // show up to 6 tiles outward from center (13x13 view)
name = "Bleach Lost Generation"

mob = /mob/user

mob/user/proc
addOverlay(obj/O)
removeOverlay(obj/O)

obj/item
clothe
canDye = 0
layer = 4.2

shirt
name = "Shirt"
canDye = 1
icon = 'male shirt.dmi'
varies = 1
price = 100

Click()
else if(istype(src, /obj/item/clothe))
var/mob/user/m
if(istype(usr , /mob/user/)) m = usr
else return
if(!usr.buying)
if(suffix != "Equipped")

m.addOverlays(src)
src.suffix = "Equipped"

else

src.suffix = ""
m.removeOverlays(src)

<dm>
Your procs are named addOverlay() and removeOverlay() but you're calling them as addOverlays() and removeOverlays()
For hair, just change the layering. There's a really simple way of reloading/loading hair as well.

obj/hair
// this can be changed for certain hair objects
// that you want to appear below or above certain overlays
layer = 4.05

For accessories you can do the same thing, except if you want them to be above clothing, make sure the layer is over the clothing layer, but underneath the hair layer. Unless that's what's intended.

obj/items/accessories
layer = 4.04
// note: you can user layers as so: 4.041, 4.042, etc

And so on.
In response to MisterPerson
WOW! I can't believe I overlooked something so simple. Thank you!

Thanks Neimo. Didn't realize that it can be done that way.
Luchasi, I was checking out the new version of BYOND (I think it's beta testing) and found a method you could use.

The new version has a color var in all atoms. Using this var, you can change the color of something easily, and won't need to create resource build. Two things though, the new release seems kind of unstable, and from what I've read the color var only works in hardware rendering mode.

Example of color var used on overlay:
obj/hair
layer=MOB_LAYER+1
icon='hair.dmi'

mob/verb/Hair()
var/obj/hair/O=new
O.color=input("") as color
src.overlays+=O
alert("Remove")
src.overlays-=O


Edit: Also, it appears as though the color var is opposite of what we're use to. Instead of the base icon needing to be black, it needs to be white. I don't really know why >.<..
In response to Ss4toby
Good to know thank you. Yeah I'm straying away from the beta at the moment because how unstable it is. It really distorts the map.