ID:2302992
 
(See the best response by Ter13.)
Code:
proc
Equip(mob/m, Equipment/item)
if(item.equipped)
if(m.equipment["[item.slot_type]"])
var/Equipment/e = m.equipment["[item.slot_type]"]
m.overlays -= e.icon
var/type = null
if(item.slot_type == "Accessory")
type = (m.equipment["Accessory 1"]) ? "Accessory 2" :"Accessory 2"

if(type)
m.equipment[type] = item
else
m.equipment["[item.slot_type]"] = item
m.overlays += item.icon
item.overlays+='Equipped.dmi'
else
if(item.type == "Accessory")
if(m.equipment["Accessory 1"] == item)
m.equipment["Accessory 1"] = null
else
m.equipment["Accessory 2"] = null
else
m.equipment["[item.slot_type]"] = null
m.overlays -= item.icon
item.overlays-='Equipped.dmi'
item.equipped = !item.equipped


Problem description:

I am trying to make an equipment system which if an item with a lower layer-precedence than any of the items already overlayed on the mob; it'll move itself underneath the equipment. I know that a way to do this would be to re-adjust the overlays every time something is equipped which sounds very inefficient because, I would need to use a for-loop() to do so. Anyone got any suggestions or algorithms I can use because, I don't know what I need to do.
Icons don't have layers. You need to add the item itself as an overlay, not its icon. I told you this already on the Discord.
In response to Unwanted4Murder
I didnt understand what you meant but now I understand what you meant. apologies.
Best response
Something neat you may not know, is that you can use types as overlays.

obj/item/equipment
var
equip_overlay = /overlay/herpyderp
proc
Equip()
overlays += equip_overlay

Unequip()
overlays -= equip_overlay

overlay
parent_type = /obj
plane = FLOAT_PLANE

herpyderp
icon = 'herp.dmi'
layer = FLOAT_LAYER


For overlays, you want to use FLOAT_LAYER, which is a special value that allows overlays to appear as though they are exactly on the same layer as their parent object.

Any negative layer value is a float layer. Float layers will sort properly amongst themselves so that they never have to be updated or shuffled around by assigning different negative numbers.

-3 will appear below -2, -4 will appear below -3, etc. If you set up your overlays in such a way as to use different negative offsets from one another, you won't have to worry about changing your overlays list at all.
In response to Ter13
Get out of here! I helped him for like an hour on the Discord, these are my points! lol

In all seriousness though I didn't know that, pretty neat.