| Blockland Forums > Modification Help |
| Variable Questions |
| << < (3/4) > >> |
| Fluff-is-back:
--- Quote from: jes00 on August 31, 2011, 06:52:54 AM ---So how would I * Save and load the players data only if they join the server. * Display the players variable. --- End quote --- What do you mean by display? Saving and loading could be done like this: If the server is going to be running non-stop then you could get away with using a variable like: --- Code: ---$Var[%client.bl_id] --- End code --- Note that this will be erased once the game is closed. if not, Then you could export the variables to a file corrosponding to the player's ID: to save: --- Code: ---function SaveVars(%client) { export("$var*", "config/Vars/" @ %client.bl_id @ ".cs"); } --- End code --- to load: --- Code: ---function gameConnection::AutoAdminCheck(%client) //This is called once a client joins the server { parent::AutoAdminCheck(%client); exec("config/Vars/" @ %client.bl_id @ ".cs"); } --- End code --- EDIT: Fixed a silly mistake |
| jes00:
--- Quote from: Fluff-is-back on August 31, 2011, 07:42:00 AM ---What do you mean by display? --- End quote --- Like in a bottom print. |
| Bloxxed:
--- Quote from: jes00 on August 31, 2011, 08:19:29 AM ---Like in a bottom print. --- End quote --- Code in the CityRPG or even I believe Team Deathmatch(?) |
| Chrono:
I suggest not following Fluff's code. It wont work and that'll only save $var, and not $var[ID HERE] If you were however, to use that method: --- Code: ---function GameConnection::saveVars(%client) { export("$var" @ %client.bl_id @ "*", "config/Vars/" @ %client.bl_id @ ".cs"); } --- End code --- to load: --- Code: ---package autoLoad { function gameConnection::AutoAdminCheck(%client) //This is called once a client joins the server { if(isFile("config/Vars/" @ %client.bl_id @ ".cs")) exec("config/Vars/" @ %client.bl_id @ ".cs"); else %client.configureDefaultVars(); return Parent::AutoAdminCheck(%client); } }; activatePackage(autoLoad); --- End code --- and to remove data of a user who has left the server: --- Code: ---package autoSave { function GameConnection::onClientLeaveGame(%client) { %client.saveVars(); deleteVariables("$var" @ %client.bl_id @ "*"); return Parent::onClientLeaveGame(%client); } }; activatePackage(autosave); --- End code --- Explanations for each function: Saving: Let's say the client's ID was 5344. It would export anything as $var[5344,*], meaning, if you were to have something like $var[5344,faction] and $var[5344,points] it would save both to the file, instead of just one variable. Auto load: Package the autoadmin check function, which is called whenever any player joins. If the player has a file, load it, otherwise, give him default values (you would have to make this function yourself as GameConnection::configureDefaultValues(%client) ) And then for the autoadmin system to work properly, return whatever the default function is supposed to. Auto save: Package the function for when clients leave the server. Save the player's data using the previous function made, saveVars. Delete the no longer needed variables. Then continue the onLeave function. --- Quote from: jes00 on August 31, 2011, 08:19:29 AM ---Like in a bottom print. --- End quote --- Depends what you want to display. |
| jes00:
--- Quote from: Chrono on August 31, 2011, 12:34:44 PM ----Lot of talking- --- End quote --- So would this work? --- Code: ---/========================================================================= // 7. Auto Save And Load //========================================================================= ////////////////////// // 7.1 Auto Save ///// ////////////////////// package AutoSave { function GameConnection::onClientLeaveGame(%client) //This is called when a client leaves the server { %client.saveVars(); deleteVariables("$Gold" @ %client.bl_id @ "*"); deleteVariables("$MP" @ %client.bl_id @ "*"); deleteVariables("$Health" @ %client.bl_id @ "*"); deleteVariables("$Class" @ %client.bl_id @ "*"); return Parent::onClientLeaveGame(%client); } }; activatePackage(AutoSave); ////////////////////// // 7.2 Auto Load ///// ////////////////////// package AutoLoad { function gameConnection::AutoAdminCheck(%client) //This is called once a client joins the server { if(isFile("config/Vars/" @ %client.bl_id @ ".cs")) exec("config/Vars/" @ %client.bl_id @ ".cs"); else %client.configureMedievalRpgSaves(); return Parent::AutoAdminCheck(%client); } }; activatePackage(AutoLoad); --- End code --- And to save a var --- Code: ---export("$VarName" @ %client.bl_id @ "*", "config/MedievalRpgSaves/" @ %client.bl_id @ ".cs"); --- End code --- --- Quote from: Chrono on August 31, 2011, 12:34:44 PM ---Depends what you want to display. --- End quote --- For example: how much gold the player has. |
| Navigation |
| Message Index |
| Next page |
| Previous page |