ID:139797
 
Code:
obj
ironchainleggings
icon='LowerClothes.dmi'
icon_state="IronChainLeggingsDwarf"
name="Iron Chain Leggings"
Dropped=0
verb/Equip()
if(usr.legs==0)
if(usr.hobbit==1)
icon='LowerClothes.dmi'
usr.overlays+="IronChainLeggingsHobbit"
src.name+="{Equipped}"
usr.legs=1
src.equip=1
if(usr.dwarf==1)
src.name+="{Equipped}"
icon='LowerClothes.dmi'
usr.overlays+="IronChainLeggingsDwarf"
usr.legs=1
src.equip=1
else
usr<<"You're already wearing something on your legs."
verb/UnEquip()
if(src.equip==1)
if(usr.hobbit==1)
icon='LowerClothes.dmi'
usr.overlays-="IronChainLeggingsHobbit"
src.name="Iron Chain Leggings"
usr.legs=0
src.equip=0
if(usr.dwarf==1)
icon='LowerClothes.dmi'
usr.overlays-="IronChainLeggingsDwarf"
src.name="Iron Chain Leggings"
usr.legs=0
src.equip=0
else
usr<<"You aren't wearing that."
verb/Drop()
if(src.equip==0)
src.Dropped=1
view()<<"[usr.name] drops a [src.name]."
src.loc=usr.loc
else
usr<<"Unequip that first."
verb/Pick_Up()
if(src.Dropped==1)
set src in oview(1)
src.Dropped=0
view()<<"[usr.name] picks up a [src.name]."
src.loc=usr


Problem description: Normally, I can easily add an overlay. But for some reason, the leggings won't be visible on the character. Anyone know what's wrong? It could possibly be that I use seperate icon files.

Well I'm not really an expert coder.. but I believe you can do "usr.overlays += /obj/ironchainleggings" or just make a new dmi file, and put the file into the new dmi file, and then "usr.overlays += 'New.dmi'" and I don't think you can add the "icon = 'LowerClothes.dmi'" within the Equip verb... but idk, like I said, I'm not a expert. :P
Does the player's icon contain an icon state named "IronChainLeggingsDwarf" (or Hobbit as the case may be)?
When you add a string to overlays, it's counted as an icon_state--but it's based on the icon of the atom it belongs to, not the atom of the obj whose proc added it. If the player has no icon state of that type, it won't be shown.

There are numerous issues with this equipment system I'd recommend addressing before fixing the overlay thing though.

- The Dropped var is unnecessary and bug-prone. To check if an obj is being held or not, just look to see if its loc is a mob. ismob(loc) is more than adequate.

- The get and drop verbs should really be universal to all objs you can pick up. Special handling for equipment isn't too hard to handle as you'll see below.

- Equipment should always be managed by the mob, not the objs. You should be keeping these either in vars that belong to the mob, or a list. For example you might have var/obj/item/equipment/leggings/leggings as the var identifying which leggings are in use, and then all you have to do is set usr.leggings=src to equip and usr.leggings=null to unequip. Another common option is to use slots, so usr.equipment[slot]=src to equip and usr.equipment[slot]=null to unequip. Likewise it's easy to tell if the item is equipped or not by comparing it to the var or slot's current value.

This is the rough outline of a better system:

mob
var/list/equipment // don't initialize this; not all mobs need it

obj/item
verb/Get()
set src in oview(1)
loc = usr
verb/Drop()
set src in usr
loc = usr.loc

equipment
var/slot

Drop()
if(usr.equipment && usr.equipment[slot] == src && !Unequip()) return
..()

proc/ApplyEffects(mob/M, worn)
// if worn is true, apply effects to M
// otherwise this has been removed, so remove the effects

verb/Equip()
set src in usr
if(!usr.equpiment) usr.equipment = list()
var/obj/item/equipment/old = usr.equipment[slot]
if(old == src) return 1 // already equipped
if(old && !old.Unequip()) return 0 // can't unequip the old one
usr.equipment[slot] = src
usr << "You equip [src]."
ApplyEffects(usr, 1)
return 1

verb/Unequip()
set src in usr
if(!usr.equpiment) return 0
if(usr.equipment[slot] != src) return 0 // not equipped
usr.equipment -= slot
if(!usr.equipment.len) usr.equipment = null // no need for the list now
usr << "You unequip [src]."
ApplyEffects(usr, 0)
return 1


All you need to do then to make this work is give each item a slot, and override ApplyEffects() for the various equipment. ApplyEffects() can be made easier to handle by just working with general vars as well.

Lummox JR
In response to Garthor
The player icons and the armor icons are in seperate icon files.
In response to Colin1011
Then adding a text string to overlays won't work, as Lummox has said. You'll need to add an actual object with the desired appearance data.