ID:141951
 
Code:
obj
clickable
equip
icon='visual.dmi'
icon_state="equip"
Click()
if(!usr.playing)
return
var/obj/gun/templist[]=new
for(var/n in usr.weapons)
templist+=n
var/obj/gun/q=input("Select from your weapons.")in (templist)|null
usr.overlays-=usr.selected_weapon //Here.
usr.selected_weapon=q
usr.update_gun_icon(q)
usr.ammo=q.ammo


Problem description:

Whenever I equip the missile launcher, everything seems fine; my overlays are added with the missile launcher icon. However when I switch again to the pistol, the icon of the missile launcher stays on the screen while the pistol also pops up. The reason I find this odd is because whenever I reselect the missile launcher, the pistol icon does go away. What's up?

Could you post the code for the update_gun_icon procedure? I have a feeling your problem is in there.
In response to Devourer Of Souls
I wouldn't think so :/

mob
proc
update_gun_icon(obj/gun/a)
if(!a)
return
src.overlays+=a
In response to Speedro
Well... This worked fine for me. I'm not sure why you've got some of this complicated code stringing around, but it's probably causing some problems in places you don't know. I changed 'selected_weapon' to 'selected_weapon.icon' because the overlays were appearing under the mob for me, but if that's intended in your game go ahead and change it back. But I didn't experience any sticky overlay problems, at least.

obj
clickable
equip
Click()
var/obj/gun/q=input("Select from your weapons.","Choose a weapon.")as null|obj in usr.weapons
if(q)
if(usr.selected_weapon) usr.overlays-=usr.selected_weapon.icon //Here.
usr.selected_weapon=q
usr.overlays+=usr.selected_weapon.icon
usr.ammo=q.ammo


EDIT: Small change.
In response to Devourer Of Souls
Hmm, yes. It worked some-how immediately after I replicated your code?


Also as soon as I added a new weapon to the list, suddenly the missile launcher was a problem again. It's the only one that doesn't get removed when I switch items. I ran a debug test and it confirmed that it did, in fact, apparently remove the missile launcher.

obj
clickable
equip
icon='visual.dmi'
icon_state="equip"
Click()
if(!usr.playing)
return
if(usr.selection_in_progress)
return
usr.selection_in_progress=1
var/obj/gun/q=input("Select from your weapons.","Choose a weapon.")as null|obj in usr.weapons
if(q&&q!=usr.selected_weapon)
if(usr.selected_weapon)
world<<"[usr.selected_weapon] should be removed from overlays now."
usr.overlays-=usr.selected_weapon //Here.
usr.selected_weapon=q
usr.overlays+=usr.selected_weapon
usr.ammo=q.ammo
usr<<"<b>You have equipped <font size=5> \icon [q] </font> ([q])"
usr.selection_in_progress=0