ID:263635
 
Code:
obj
Weapon
Lightsaber
icon_state="obisaber"
dmg=150
var
ltype
activated
r
g
bl
verb
Activate()
if(usr.Weapon==src)
if(activated)
view(usr)<<sound('deactivate.wav')
sleep(3)
activated=0
for(var/obj/Weapon/Lightsaber/L in usr)
if(L.ltype=="One Sided")
usr.overlays-='Lightsaber.dmi'
if(L.ltype=="Dual Sabers")
usr.overlays-='Dual Sabers.dmi'
if(L.ltype=="Double Sided")
usr.overlays-='Double Sided Saber.dmi'
else
view(usr)<<sound('activate.wav')
sleep(3)
activated=1
var/icon/S=new(locate(0,0,0))
if(ltype=="One Sided")
S.icon='Lightsaber.dmi'
if(ltype=="Dual Sabers")
S.icon='Dual Sabers.dmi'
if(ltype=="Double Sided")
S.icon='Double Sided Saber.dmi'
S+=rgb(r,g,bl)
usr.overlays+=S


Problem description:
I'm coding a lightsaber system, and you have a lightsaber object in your inventory, with an inventory icon. When you Activate it, there is an overlay on the player icon with the color r,g,bl for the rgb() proc. The problem is, I can't find a way to have the overlay disappear when deactivating the lightsaber, since using usr.overlays=null would make the player naked.
You need to make a variable to store the icon, modify the icon's RGB, THEN add and remove it as an overlay. As far as I know, if you overlay an icon, then change it, then try to remove it, it won't remove, because it doesn't recognize it as the same icon you overlayed.
If you want to be able to remove an overlay, you'll have to store a reference to it. So, my suggestion:

1) Give weapons a variable, var/image/overlay
2) When they are created, use the image proc to create the proper image for the overlay, make any color modifications, and store it in the overlay variable.
3) When equipping, overlays += overlay
4) When unequipping, overlays -= overlay

In addition: the ltype variable is silly. Single / dual / double should be subtypes of Lightsaber.
In response to Garthor
Garthor wrote:
If you want to be able to remove an overlay, you'll have to store a reference to it. So, my suggestion:

1) Give weapons a variable, var/image/overlay
2) When they are created, use the image proc to create the proper image for the overlay, make any color modifications, and store it in the overlay variable.
3) When equipping, overlays += overlay
4) When unequipping, overlays -= overlay

In addition: the ltype variable is silly. Single / dual / double should be subtypes of Lightsaber.

I've delt with this problem a couple of times in my games. I tried what you suggested above Garthor before. It works, as long as it's not a situation where you need to save/load. Because, I personally don't like to save icons in savefiles, it takes up way too much space but, unfortunately you also lose the reference when you don't save overlays/underlays/icons so, I simply keep a list of all items that are supposed to be displayed on the character along with their associated layer, rgb scheme, etc...and I reapply each time something is removed.