ID:170605
 
I have a problem with logging out with an overlay equipped because when you do so the icon is stuck on the char forever. Does anyone know how to fix this?
Remove all the overlays before the person logs off:
mob/Logout()
for(var/o in overlays)
overlays.Remove(o)

If you want to save the overlays:
mob/Logout()
var/savefile/F = new("characters/[name]/overlays.sav")
F<<overlays
for(var/o in overlays)
overlays.Remove(o)
..()

mob/Login()
..()
var/savefile/F = new("characters/[name]/overlays.sav")
var/list/input = list()
F>>input
for(var/o in input)
overlays += o
In response to Hazman
Eh I still get the same problem.

obj
Test
icon = 'Weapons.dmi'
icon_state="s"
verb
get()
set src in oview(1)
usr << "You pick up test."
usr.contents+=new/obj/Test
del(src)
drop()
set src in usr
src.loc=locate(usr.loc)
new/obj/Test(usr.loc)
Equip()
src.suffix="Equipped"
usr.overlays+=new/obj/overlays/Test
Unequip()
src.suffix=""
usr.overlays-=new/obj/overlays/Test







obj
overlays
Test
icon = 'Weapons.dmi'
icon_state = "s"


Here this might answer why i get the problem >.< The overlay already saves but the thing is that when you logout and come back you can't the the overlay off when you un equip
In response to WickedlyAndy
OK, I have another idea:
mob/Logout()
for(var/obj/Test/t in contents)
if(t.suffix=="equipped")
t.Unequip()
..()

That will unequip all the Tests before the mob logs off. Or it should, anyway.
In response to Hazman
Is there a way to equip it when logging in?
In response to WickedlyAndy
You could add a variable to each Test that says whether it should be equipped or not, then when the mob logs in you loop through the Tests, equipping the ones that should be equipped:
obj
Test
var/equippedonlogin //make a new variable called equippedonlogin.
mob/Logout() //when a player logs out...
for(var/obj/Test/t in contents) //check all of his Test
if(t.suffix="equipped") //objects to see if they are equipped
t.equippedonlogin=1 //if they are, make the variable we made earlier turn to 1
t.Unequip() //and make them unequip.
..() //Do everything that Logout() normally does.

mob/Login() //When a mob logs in
..() //Do all the normal stuff, then...
for(var/obj/Test/t in contents) //Loop through all his Tests
if(t.equippedonlogin) //And check to see if they should be equipped.
t.Equip() //If they should, Equip them and...
t.equippedonlogin=0//make them not equippedonlogin.
In response to Hazman
Thanks A lot these overlays have been being evil to me.
In response to Hazman
eh How would i make it Only equip the weapon unequipped upon logging out?
In response to WickedlyAndy
It does. Or, at least, it should. Try making some differently named weapons and trying it with them.
In response to Hazman
Meh It doesn't Reequipped them for some reason, >.< I dunno how to make the Equipped on login thing
In response to WickedlyAndy
I'll put comments in my last code, so it explains what it's doing.
In response to Hazman
I still have my original problem now the overlay icon is stuck on when i unequip after logging out with it on.


And does rebooting force a logout on the host?
In response to WickedlyAndy
Did you just copy and paste the code? If so, you'll notice that the word "equipped" appears in my code with a lowercase "E", and in your code with an uppercase "E". So you'll need to change my code ever-so-slightly to make it work.
In short, don't just copy and paste code from the forum.
In response to Hazman
Lol No i didn't copy and paste, I'm not that stupid to let something that minor to get in my way. >.< I beleive the error might be in my saves or something. So I've been trying to fix it but eh, I can't get it to work.
In response to WickedlyAndy
Can you equip and unequip them normally? If not, the problem might be in your overlay code - everytime you add or remove an overlay, you create a new one. Try replacing all the new/obj/Test/whatever with just src
In response to Hazman
Equip and Unequip work fine, I think its something to do with my saves >.<
In response to WickedlyAndy
Are you using a library for your save system, or are you building your own?
In response to Hazman
Its mixed, Part libary and Mine
In response to WickedlyAndy
Have you tried deleting the saves then trying again? Also, which library is it and how is it modified?
In response to Hazman
lol Yes i deleted the saves and its from an RPG start and uses Deadron's basecamp