Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function saveClient(%this)
- {
- //Create a new file object
- %f = new fileObject();
- //Open our file object for writing purposes
- %f.openForWrite("config/mydata/"@%this.bl_id@".txt");
- //Write our data
- //--------------
- %f.writeLine(%this.gold);
- echo("Saved "@%this.name@"\'s gold which is "@%this.gold);
- %f.writeLine(%this.level);
- echo("Saved "@%this.name@"\'s level which is "@%this.gold);
- //--------------
- //Close our file object
- %f.close();
- //Delete it
- %f.delete();
- }
- function loadClient(%this)
- {
- //Create a new file object
- %f = new fileObject();
- //Open our file object for readin purposes
- %f.openForRead("config/mydata/"@%this.bl_id@".txt");
- //Read our data
- //-------------
- %this.gold = %f.readLine();
- echo("Loaded "@%this.name@"\'s gold which is "@%this.gold);
- %this.level = %f.readLine();
- echo("Loaded "@%this.name@"\'s level which is "@%this.level);
- //-------------
- //Close our file object
- %f.close();
- //Delete it
- %f.delete();
- }
- //Declare package
- package saveAndLoad
- {
- function gameConnection::autoAdminCheck(%this)
- {
- parent::autoAdminCheck(%this);
- //when someone joins, let's load them up!
- loadClient(%this);
- }
- function gameConnection::onClientLeaveGame(%this)
- {
- //when someone leaves, let's save them before we call the parent!
- saveClient(%this);
- parent::gameConnection::onClientLeaveGame(%this);
- }
- };
- //Activate our package
- activatePackage(saveAndLoad);
Advertisement
Add Comment
Please, Sign In to add comment