ID:158197
 
I am having a problem with Deadron's CharacterHandling Library. I use a clothing system in my game. When I put on clothes and save, then exit and log back in, the clothes can't be removed. Help me Please!

Tman1114
overlays is a super-finicky list. Your best choice is just to not save it at all, and then reconstruct it when you load the mob. Like so:

mob
Write(var/savefile/F)
..()
F.dir.Remove("overlays")
Read(var/savefile/F)
..()
for(var/obj/O in list_of_equipped_items)
O.equip()
In response to Garthor
Here's my code for your reference.

Clothes:
obj
BlueShorts
layer=MOB_LAYER+1
name = "Blue Shorts"
icon='Clothes.dmi'
icon_state="BlueShorts"
var/wearing = 0
verb
Wear()
set category = "Clothing"
set src in usr
if(src.wearing == 1)
usr << "You are already wearing that!"
return 0
else
src.wearing = 1
usr<<"You put on the Blue Shorts."
usr.overlays+= src
TakeOff()
set src in usr
set category = "Clothing"
set name = "Take Off"
if(src.wearing == 0)
usr << "You're not wearing that!"
return 0
else
usr<<"You take off the Blue Shorts."
usr.overlays-= src
src.wearing = 0
PickUp()
set category = "Interact"
set src in oview(1)
set name = "Pick Up"
usr<<"You found a pair of Blue Shorts!"
src.loc=usr
usr.UpdateInventory()
Drop()
set category = "Interact"
usr<<"You drop the Blue Shorts."
usr.overlays-=src
src.wearing = 0
src.loc=locate(usr.x,usr.y,usr.z)
usr.UpdateInventory()

Logout:
mob
verb
Logoff()
set category = "Other"
set name = "Logout"
if(initgender == 1)
icon = 'newchar.dmi'
icon_state = "male"
if(initgender == 2)
icon = 'newchar.dmi'
icon_state = "female"
Logout()
In response to Tman1114
I guess you'd have to also do TakeOff() for all the items you're wearing as well before saving.
In response to Garthor
Then ow would I put them back on when the save is loaded?
In response to Tman1114
I use a manual list for holding "overlays" and another for "underlays" that I want saved with the player. When the player saves, however, his/her overlays/underlays lists are nulled out and the actual saving occurs. After that, a proc that reconstructs the player's overlays and underlays is called.

mob/var/list/Overs = list()
mob/var/list/Unders = list()

obj/clothing/shirt
verb/Wear()
usr.overlays += src.icon
usr.Overs += src.icon
verb/Take_Off()
usr.overlays -= src.icon
usr.Overs -= src.icon

mob/proc/add_overs()
for(var/over in src.Overs)
src.overlays += over

mob/Write(savefile/F)
src.overlays = null
..()
src.add_overs()
In response to Spunky_Girl
I adapted that code to fit my system and it works perfectly.

Thanks!