ID:173551
 
This is just a simple peice of code that any other BYOND 'rpg' has, picking up equipping blah blah. Well in the overlays i used an image (Maz had sudgested) so i did. It was working fine until i had set the image's layer to something, then it just plain wouldn't remove. Any help on fixing this?

obj/Armor/Shield
Click()
if(get_dist(usr,src)<=1)
if(usr.Inventory<=5)
usr.Inventory++
Move(usr)
DblClick()
if(src.loc==usr)
if(src.suffix=="Equipped")
src.suffix=null
var/image/I=image(src.icon,src.icon_state)
for(I in usr.overlays)
usr.overlays-=I
else
for(var/obj/Armor/Shield/A in usr)
A.suffix=null
src.suffix="Equipped"
var/image/I=image(src.icon,"[src.icon_state]")
I.layer=99
usr.overlays+=I
You can't do for(var/I in overlays).
The overlays list is weird. You can overlays.Cut() or something similar to remove all of the items in it, though.
In response to Jon88
Should've known, but still doesn't remove.

obj/Armor/Shield
New()
src.name="[src.name] shield"
Click()
if(get_dist(usr,src)<=1)
if(usr.Inventory<=5)
usr.Inventory++
Move(usr)
DblClick()
if(src.loc==usr)
if(src.suffix=="Equipped")
src.suffix=null
var/image/I=image(src.icon,src.icon_state)
usr.overlays.Remove(I)
else
for(var/obj/Armor/Shield/A in usr)
A.suffix=null
src.suffix="Equipped"
var/image/I=image(src.icon,"[src.icon_state]")
I.layer=99
usr.overlays+=I
In response to Crashed
Instead of declaring the image when unequipping, simply give each armor a variable for its own overlay image, and use that.

Oh, and you need to seriously overhaul your equipment system. This is how one should work:

Each mob has a variable for seperate armor pieces:
mob
var/obj/item/armor/body/bodyarmor
var/obj/item/armor/helm/helmet
var/obj/item/lefthand
var/obj/item/righthand
//etc.

Then, pieces of armor are simply put into the correct slot. Alternatively, if you want people to be able to lose limbs (or have certain races with, say, four arms), you can use datums to keep track of each slot, and store the datums in a list.
In response to Garthor
I don't bother with datums, I just use a list of text strings paired with objects.
In response to Hedgemistress
Datums tend to be a bit neater, however, because you can move all the code where you need to check if a weapon can be weilded into it. It's really a matter of code organization.
In response to Jon88
Jon88 wrote:
You can't do for(var/I in overlays).

Well, you can, sort of.
<code> for(var/i = 1 to 4) var/obj/o = new /obj() o.icon = 'icon.dmi' o.icon_state = "[i]" src.overlays += o </code>
If you added the overlays like that (or in a similiar manner), then you can use a for loop, like:
<code> for(var/i in src.overlays) src << i:icon_state </code>
That would then output the icon states of your overlays, in the case of the above code, 1, 2, 3 and 4.
<code> for(var/i = 1 to 4) src.overlays += icon('icon.dmi',"[i]") </code>
If you add overlays like that, then, the for loop to output the icon state's of the overlays outputs null. If you have it output the type of the overlay, then, in both cases it outputs "/image" for each overlay.