ID:1368306
 
(See the best response by Kaiochao.)
Code:
obj/item/equip/weapon
Equip()
set name = "Equip/Unequip"
var/icon/I=icon(src.icon"[src.icon_state]eq")
usr.overlays += I


Problem description: For example: If I have a shield equipped, and I equip gloves; the gloves appear above the shield. So I want to know how to set the layer of I.

Basically I want to know if there is some way to set the layer of the variable I, which is the src's equipped icon.

There is a variable called layer. You can set that after you create the icon but before you add it to the overlays. Set the layer of the gloves lower than the shield.

Check the reference for details.
Best response
You should use image(), not icon(). The /image object has a layer variable and is immensely more suitable as an overlay than an /icon object.
You should look into image().

Edit: Kaio got it.
Ohh, okay. Thanks a bunch!
Well I have one more problem! Now when I try to remove the overlay it doesnt work..
        
Equip()
set name = "Equip/Unequip"
var/image/I=image(src.icon,"[src.icon_state]eq")
if(src.equipped == 0)
if(usr.wepeq == 0)
//////////////////
usr.wepeq = 1
src.equipped = 1
src.suffix = "Equipped"
//////////////////
I.layer = 500 //
usr << "You wield the [src]"
//////////////////
usr.overlays += I


//ADD STATS//

else
usr << "You already have a weapon equipped"
else
usr.overlays -= I
usr.wepeq = 0
///////////////
src.equipped = 0
src.suffix = ""

Adding the overlay works, but removing doesnt.
That is because you are creating a new I, you need to remove the existing I.
That's a very brief reply. Removing the overlay worked before when it was set as icon, but now that it is set to image it doesnt remove. Care to explain in more detail and as to how I can remove this existing I?
I think this may be due to the fact that images are handled as virtual entities. They don't really "exist" in a form that can be manipulated after-the-fact.

Can anyone who knows more than I do confirm that fuzzy bit of knowledge?
I'm not 100% sure right now (and can't test right now, soo...)
I am going to assume it's because...you're creating a new image that is not exactly the same as the one you overlay'd.

You're setting the image's layer after you create it, but before you overlay it.

But, when you're attempting to remove it, you are only subtracting an image that has the default layer, it's untouched - and therefore not the same image.

Try this:
var/image/I=image(icon = src.icon, icon_state="[src.icon_state]eq", layer=500)

and remove the other I.layer line.
This worked, thanks!!!
In response to Syama108
Syama108 wrote:
This worked, thanks!!!

No probs.