ID:160733
 
I have some code that Equips items to players, its quite simple and works like this, usr.overlays += Item.

Now the question I wish to ask is, if I was to change the Item in any way, for example, its layer, or icon, would I be able to use usr.overlays -= Item?

I was wondering because I seem to have quite a few problems where if I change the Item its self, the code wont allow me to remove that Item from an overlay on a player. usr.overlays -= I just wont seem to work, unless I keep the Item un-changed.

Could anyone tell me why this is? and maybe suggest a better way to add an item to someone without using, usr.overlays += 'icon.dmi'?

Thank you.

One trick is to remove the overlay, make the wanted changes, then add it again.
Ginseng wrote:
I have some code that Equips items to players, its quite simple and works like this, usr.overlays += Item.

Yes, but seems like you use the term 'equip' for overlays too much. The term is, 'adding overlays'.

Could anyone tell me why this is?

Because this is how it works. In order to remove an overlay, you need to remove the same value you've used to add it, or it won't work. With objects, this means you need to use an object that has the same variables. If the object changes, its overlay counterpart ('snapshot') changes too, so it's used to add&remove a separate overlay than the old one. What you need to do is basically what Jemai said. If the object can be changed while the item is equipped, you need to account your code for that by updating the overlay - remove before the changes then re-add the overlay.