ID:146603
 
I have been trying to figure out a way to remove a overlay of a cirtain object path on the user's login.

Basicly in my coding, a ring of fire surrounds the player, but with the save code i'm using, the overlays still stick on when they relog, so i'm trying to figure out a way to remove the sepcified overlay path so no other overlays will be removed from the player, like if they have another overlay such as an outfit, it won't be removed.

I have tried things like src.overlays-=/obj/ElderKainObj/fire/FireN, and it doesn't work like on the login to remove them. So i started to play around with the Cut() proc.

I can use src.overlays.Cut() on the login to remove all overlays, but other than that, i don't want all of the overlays to go.

here is the overlay removal code i'm working on, but nothing happens.
mob
Login()
for(var/obj/ElderKainObj/fire/o in src.overlays)
src.overlays.Cut(o)


note: the icon paths for each of the overlays in the ring of fire are.

/obj/ElderKainObj/fire/FireN
/obj/ElderKainObj/fire/FireNE
/obj/ElderKainObj/fire/FireE
/obj/ElderKainObj/fire/FireSE
/obj/ElderKainObj/fire/FireS
/obj/ElderKainObj/fire/FireSW
/obj/ElderKainObj/fire/FireW
/obj/ElderKainObj/fire/FireNW
You can't loop through overlays like that, and when saving they're converted to a single icon so you also can't expect them to still be the same at login. Instead, don't save your overlays, and redo them when the character is loaded.

Lummox JR
The objects in the overlays list are not of type /obj, even if you added an object of type /obj to it. Anything added to it gets converted to an /image object.

Still, you cannot loop through it that way at all, even if you do for(var/image/I in overlays). You have to do something more like the following.
var/image/I
for(var/index = 1 to overlays.len)
I=overlays[index]

Still, you won't be able to subtract it based on its type. What you should probably look into is removing it on logout before the save instead of on login.

The best way of all to go about this is to have a seperate list that keeps track of the things you have added to the overlays and to manipulate that, then add its contents to the overlays list when needed.
atom
var/list/pre_overlays[0]
proc
add_overlay(overlay)
pre_overlays+=overlay
update_overlay()
remove_overlay(overlay)
pre_overlays-=overlay
update_overlay()
update_overlay()
overlays.Cut()
for(var/i in pre_overlays)
overlays+=i

Doing this, you can get around the fact that all your overlays are converted to /image objects since you still have versions of what they were previously to readd.
In response to Lummox JR
I use this Save Process
client/proc/SaveMob()
var/savefile/F = new("[src.ckey].sav")
F["Game"]<<usr

client/proc/LoadMob(char_ckey)
var/savefile/F = new("[src.ckey].sav")
F["Game"]>>src.mob

client/New()
if(usr) return ..()
else
var/player_sav = "[src.ckey].sav"
if(length(file(player_sav)))
var/savefile/F = new(player_sav)
F["Game"]>>src.mob
return..()
mob/Logout()
var/player_sav = "[src.ckey].sav"
var/savefile/F = new(player_sav)
F["Game"]<<usr
del src

client
verb
Save()
set category = "Commands"
SaveMob()
usr << "Saving Character..."
sleep(10)
usr << "Save Complete"

mob
Write(savefile/F)
..()
F["last_x"] << x
F["last_y"] << y
F["last_z"] << z
Read(savefile/F)
..()
var/last_x
var/last_y
var/last_z
F["last_x"] >> last_x
F["last_y"] >> last_y
F["last_z"] >> last_z
loc = locate(last_x, last_y, last_z)

How would I specify what u are talking about Lummox JR?

Becasue it automaticly saves the overlays. With the code I had in my earlier post, I could use the src.overlays.Cut() to remove all and that works just fine. But i'm not wanting all to be gone.
In response to ElderKain
ElderKain wrote:
Becasue it automaticly saves the overlays. With the code I had in my earlier post, I could use the src.overlays.Cut() to remove all and that works just fine. But i'm not wanting all to be gone.

What you need to do is during the save process, after saving the mob, remove the "overlays" value from the savefile. In fact that's easy enough to do in Write(). Then all you need is a proc that rebuilds your overlays from scratch when loading.

Two ways not to save your overlays:
mob/Write(savefile/F)
..()
F.dir.Remove("overlays")
F["last_x"] << x
F["last_y"] << y
F["last_z"] << z


Or...
mob/Write(savefile/F)
for(var/V in vars-"overlays")
if(issaved(vars[V]))
if(vars[V]!=initial(vars[V]))
F[V] << vars[V]
else F.dir.Remove(V)
F["last_x"] << x
F["last_y"] << y
F["last_z"] << z


You can use similar techniques with your icons, too, which will result in much smaller savefiles. If you're checking more than one var not to save, then I recommend keeping them in a list. Actually I recommend not saving icon, overlays, or underlays.

Lummox JR