ID:139004
 
Code:
proc
checkmacpos(skillname,mob/M)
for(var/i=1,i<=17,i++)
if(M.maclist[i]==skillname)
return(i)
mob
var
list
maclist[17]
skills = new/list()

verb
MacroSkill(N as num)
set hidden = 1
if(maclist[N])
call(maclist[N])(src)

obj
Skills
Click()
call(text2path("[src.type]/proc/Tech"))(usr)

MouseDrop(obj/O,srcLoc,OLoc,srcControl,OControl,params)
var/list/P = params2list(params)
var/obj/Btn = text2path("[src.type]/proc/Tech")
var/pos = ButtonPlacement(P["screen-loc"], Btn, usr)
if(checkmacpos(text2path("[src.type]/proc/Tech"),usr))
if(!pos && srcControl!="window1.info1") //REPLACE WITH NAME OF INTERFACE INFO PANEL
Btn=src
else if(pos)
Btn=src
else
return
else if(pos)
Btn=new Btn
if(pos)
if(O.screen_loc==pos && Btn.screen_loc && O.type in typesof(/obj/Skills))
O.screen_loc=Btn.screen_loc
else if(O.screen_loc==pos && O.type in typesof(/obj/Skills))
usr.client.screen-=O
Btn.screen_loc = pos
usr.client.screen+=Btn
else if(Btn)
usr.maclist[checkmacpos(Btn,usr)] = null
usr.client.screen-=Btn
proc
ButtonPlacement(btnloc, skillname,mob/M as mob)
var/num1 = copytext(btnloc,1,findtext(btnloc,":"))
var/middlenum = findtext(btnloc,",")
var/num2 = copytext(btnloc,middlenum,findtext(btnloc,":",middlenum))
if(num2!=",2")return
if(text2num(num1)<1 || text2num(num1)>17) return//FOR SCREEN LOC, 2 & 10 is the in between spaces for skill btns
var/prevmacloc = checkmacpos(skillname,M)
var/macpos = text2num(num1) //FOR SCREEN LOC, change -1 to whatever distance it needs to be

if(M.maclist[macpos] && prevmacloc)
M.maclist[prevmacloc]=M.maclist[macpos]
else if(prevmacloc)
M.maclist[prevmacloc]=null
M.maclist[macpos]=skillname

return "[num1][num2]"


Problem description:
Well, what I basicly want is, when a player logs out and logs in again, the skills that they placed on the hotbar and logged out with, are still on the hotbar in the exact same position. So basicly a savesystem for this. But I wasn't able to figure it out myself. Can anyone help me?
Bump.
Well I don't think that you can "save" it the way you are thinking of. But I think that you can save the skill's location on the bar as a variable, and load that up.
In response to Lugia319
Okay, but how would the skill objects still be placed on that location?
In response to Raimo
You would save the location of each skill in a savefile and then read it back from the savefile when the player logs in. Using the information you saved, you then determine where to put them on the hot bar.
In response to Complex Robot
But is there a way that I can loop through all the skills, then save their loc into the savefile? I was thinking of a for loop, but I don't think that would work out.
In response to Raimo
You can save lists directly into a savefile as a list.
Just glancing at your code, it looks like you're storing the data as lists. You can store them that way without doing anything special to them.

If you need their screen_loc, it'll save that variable automatically when an obj is saved. (Meaning you would simply have to add the object back to client.screen after you've loaded it up.)
In response to Raimo
Use some vars. Maybe some /mob vars. So it knows which skill is where. Then set their location appropriately when loaded.
In response to Complex Robot
Well, this is what I got now and it isn't working.
client
proc
Load()
var/savefile/F = new("Savefiles/[ckey].sav")
F["mob"] >> mob
F["maclist"]>>mob.maclist
var/obj/Skills/o
for(o in mob.maclist)
mob.client.screen+=o

..()
client
Del()
if(mob.cansave)
var/savefile/F = new("Savefiles/[src.key].sav")
F["mob"] << mob
F["maclist"]<<mob.maclist
..()
In response to Raimo
Well, the problem might be that you have src.key in one place and ckey in the other.
In response to Complex Robot
Still not working.
In response to Raimo
mob.client.screen+=o


This may be irrelevant, but what are you doing this for? You're already under the client parent or whatever, might as well do:

screen += o
In response to Complex Robot
I'm trying to do it with a list, but again a failure. This is what I got now.
mob/var/list/skillsonscreen = new/list()

client
Del()
if(mob.cansave)
var/savefile/F = new("Savefiles/[ckey].sav")
F["mob"] << mob
for(var/obj/Skills/o in mob.client.screen)
mob.skillsonscreen.Add(o)
for(var/obj/HUD/x)
mob.client.screen-=x
F["skillsonscreen"] << mob.skillsonscreen
..()
client
proc
Load()
var/savefile/F = new("Savefiles/[ckey].sav")
F["mob"] >> mob
mob.overlays += mob.prevoverlays
mob.underlays += mob.prevunderlays

mob.Skillsadd()
spawn(2)
mob.addHUD()
F["skillsonscreen"] >> mob.skillsonscreen
for(var/obj/Skills/p in mob.skillsonscreen)
mob.client.screen+=p

..()
In response to Raimo
client
Del()
var/savefile/F=new("Savefiles/[ckey].sav")
F["mob"]<<mob
for(var/mob/ghost/G in screen)
F[G.screen_loc]<<G.type
proc/Load()
var/savefile/F=new("Savefiles/[ckey].sav")
F["mob"]>>mob
var/I=1
while(I<10)
if(F["[I],1"])
var/T = F["[I],1"]
var/mob/ghost/G = new T
G.screen_loc="[I],1"
screen+=G
I++


This worked for me, though you may want to overwrite empty buffers, as the skill stays there even if it was removed unless overwritten with null. Also note that it only works on a bottom row hotbar used via HUD. A similar principle could be used on any edge of the map by simply adjusting the buffer names.
In response to Robertbanks2
What do you mean with the empty buffers?
In response to Raimo
The buffers/sub-directories(The things inside [] in F["[I],1"]) don't automatically delete when saving a new file, because you aren't overwriting them with anything. This means that if you remove a skill from the hotbar, then save with this system, it will pop back up when you load.

It's not incredibly difficult to counteract, you could add them to a list instead of individual buffers then put the list in a temp list during loading, then again to save to a single buffer/sub-directory. I chose not to to make the code less copy-pasteable, the concept is shown and you should be able to handle it from here.
In response to Robertbanks2
This is a pretty poor way of saving well, anything. You're limiting the open-endedness of system and preventing it from being easily expanded in the future. What the original poster should be doing is keeping track of the skills on their own instead of relying on client.screen.

mob
var
list/hotbar = list()
obj
skill
New(client/C)
C.screen += src


mob
verb
AddHotbar()
var/obj/skill/new_skill = new/obj/skill(client)
hotbar += new_skill
new_skill.screen_loc = "[hotbar.Find(src)],1"

proc
SaveHotbar()
var/savefile/my_save = new("[ckey].hotbar")
my_save["hotbar"] << hotbar
LoadHotbar()
var/savefile/my_save = new("[ckey].hotbar")
if(my_save["hotbar"]) my_save["hotbar"] >> hotbar


This is just an EXAMPLE, not hand-fed code, so you're meant to learn from it not use it. When the hotbar list is loaded, anything that was saved inside of it gets loaded as well, this includes all variables and whatnot, it will also call New() for the objects inside of it, which will add them to the player's screen. screen_loc is automatically saved with the object when you save the list, and should be loaded when the list gets loaded.
In response to Nadrew
You seem to have made a hobby of coming along just behind me and correcting whatever stupid things I say. Couldn't have come along sometime during the 2 days before I made an ass of myself?

Anyway, carry on making me look like a twat, I'm not particularly opposed to learning new things.