ID:2301258
 
Hello!

I was wondering how you would go about saving the overlay of skills to a HUD hotbar after dragging and dropping it onto it?



Rather than saving them, you could just save the location they are supposed to be at, and upon loading the savefile, retrieve the information and place the skills where necessary.

Example : (This is just a push in the right direction, you will more likely than not have to make small alterations)
obj
var/id
var/obj/skillin

Hotkeys
New(client/c)
..()//calls the default action for the New() proc [It will work as if it wasnt overriden]
c.mob.hudobjects+=src//keep track of the objects you add to your HUD for easier manipulation
c.screen+=src//add the hotkey to the screen


Hotkey1
screen_loc="1,1"//each hotkey has a unique screen_loc and id
id=1

Hotkey2
screen_loc="2,1"
id=2

Hotkey3
screen_loc="3,1"
id=3

Hotkey4
screen_loc="4,1"
id=4


Skill
New(mob/M)
..()
M.acquired_skills+=src//when a new skill is created [new/obj/Skill/punch(src)] add it to a list to keep track of the skills the player has learned

MouseDrop(obj/Slot)//when the skill is dropped on an object
if(istype(Slot,/obj/Hotkeys))//check the objects type to see if its a hotkey
Slot.Skilladd(src,usr)//if so, execute the Skilladd proc to add the skill to the hotkey


proc
Skilladd(obj/S,mob/user)
var/obj/skillremove//declare skillremove, which is used to clear out any skills that must be removed
if(skillin)//such as skills that are already in the hotkey you are trying to place a new skill in
skillremove=skillin
if(S in user.hudobjs)//or to remove any duplicates located on a different hotkey
skillremove=S

if(skillremove)//if a skill to remove is found
skillremove.id=0//set its id to a null value
skillremove.screen_loc=null//along with its screen_loc
user.client.screen-=skillremove//remove it from the client's screen
user.hudobjects-=skillremove//and thus remove it from the list of onscreen objects you are keeping track of

skillin=S
S.id=id//now assign the id of the hotkey to the original skill you wanted to equip
S.screen_loc=screen_loc//then assign the screen_loc
user.client.screen+=S//add it to the player's screen
user.hudobjects+=S//add it to the list of onscreen objects being tracked

mob
var/list
hudobjects=list()
acquired_skills=list()

proc
LoadSkills()//call this after loading the save file, and after you have repopulated the HUD with the hotkeys
for(var/obj/Skill/O in acquired_skills)//check through all of the learned skills
if(O.id)//if any of these skills have an id, this means the skill was equipped the last time the game was saved
for(var/obj/Hotkeys/H in hudobjects)//check through all of the hotkeys onscreen
if(H.id==O.id) H.Skilladd(O,src)//if the unique id of the hotkey is the same as the id of the skill,
//add the skill to that hotkey


If you are big on saving memory by reducing the size of savefiles, I have something that will help you (optional)
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/


//Replace the previous snippets with this appropriately

mob
var/list
hudobjects=list()
acquired_skills=list()//skill list for saving
tmp/skill_list=list()//skill list for usage during gameplay temporary variables are automagically ignored by the Write() function


obj
Skill
New(mob/M)
..()
for(var/s in M.acquired_skills)//search through all acquired skills
if(findtext(s,"[type]"))//if any are found which posess the same type as this skill
M.acquired_skills-=s//remove it
M.acquired_skills+="[type]|0;"//assign a unique text string to the skill list for saving, in the format "skilltype|on screen status;current location onscreen"
M.skill_list+=src//add skill to the list for manipulation during gameplay

proc
Skilladd(obj/S,mob/user)
var/obj/skillremove
if(skillin)
skillremove=skillin
if(S in user.hudobjs)
skillremove=S

if(skillremove)
skillremove.id=0
skillremove.screen_loc=null
user.client.screen-=skillremove
user.hudobjects-=skillremove
for(var/s in user.acquired_skills)//check for duplicates and remove them
if(findtext(s,"[skillremove.type]"))
user.acquired_skills-=s

for(var/s in user.acquired_skills)//check for duplicates and remove them
if(findtext(s,"[skillremove.type]"))
user.acquired_skills-=s
skillin=S
S.id=id
S.screen_loc=screen_loc
user.client.screen+=S
user.hudobjects+=S
user.acquired_skills+="[S.type]|1;[S.screen_loc]"//assign a unique text string to the skill list for saving,
//in the format "skilltype|on screen status;current location onscreen"

mob
proc
GetSkills(skilltxt)//this procedure is used to decipher the text strings
var/x,y,typetxt,s_onscreen,s_screenloc

for(x=1;x<=length(skilltxt);x++)
store="[copytext(skilltxt,x,x+1)]"//search the string character by character looking for the first separator
if(store=="|") break//if you find the 1st separator, break the loop, take note that the location of this separator is stored in x
for(y=1;y<=length(skilltxt);y++)
store="[copytext(skilltxt,e,e+1)]"//search the string character by character looking for the second separator
if(store==";") break//if you find the 2nd separator, break the loop, take note that the location of this separator is stored in y


typetxt=text2path(copytext(skilltxt,1,x))//copy the text from the first character to the location preserved by x
//convert this text into a type path and store this in a variable
s_onscreen=text2num(copytext(skilltxt,x+1,y))//copy the text from the character in front of x to the location preserved by y
//convert this text into a number and store this in a variable
s_screenloc=copytext(skilltxt,y+1,0)//copy the text from the character in front of y to the end of the text string
//store this in a variable
var/obj/A=new typetxt//using the information just obtained, create the skill
if(s_onscreen)//if the skill was last saved as on screen
A.screen_loc=s_screenloc//assign it the stored screen location


LoadSkills()
for(var/obj/S in acquired_skills)//search through all of the skill strings
GetSkills(S)//break them down into skills
for(var/obj/Skill/O in skill_list)
if(O.id)
for(var/obj/Hotkeys/H in hudobjects)
if(H.id==O.id) H.Skilladd(O,src)


I have compiled neither of the two provided snippets, so if there's a problem I'll fix it.
I'm not too sure about the inner workings of BYOND as an article of software, but I'm sure that when compared to an object with all of its variable values saved, a text string would be considerably smaller in size.