Add-On developers: You can use player persistence to save any tagged field on the client or player object by using the RegisterPersistenceVar() function. Here is some example code:Code: [Select]//load the persistence add-on now, if they have it enabled.//you can also use ForceRequiredAddOn if your add-on doesn't work without persistenceLoadRequiredAddOn("Script_Player_Persistence");if(isFunction(RegisterPersistenceVar)) //quick way to check if the persistence add-on loaded{ //usage: RegisterPersistenceVar(string <tagged field to match>, bool <match all>, string <datablock classname>); RegisterPersistenceVar("myVariable", false, ""); // save %client.myVariable and %player.myVariable to persistence file (if those values are set) RegisterPersistenceVar("myPrefix", true, ""); // save any tagged field on %client/%player starting with "myPrefix", // eg %client.myPrefixFoo %client.myPrefix_24, etc. // This is more expensive than a straight match and can have unintended consequences, so be careful RegisterPersistenceVar("myDatablockRef", false, "ItemData"); // save %client/%player.myDatablockRef to persistence but verifies that it is of class "ItemData" // and translates the id number into a datablock name before saving. // Datablock id numbers will vary depending on the order and number of add-ons loaded, // so use this if you need to save a datablock reference.}//optionally, you can package into the apply persistence function if you need to do custom stuff to fully restore the player's statepackage <MyAddOn>PersistencePackage{ function GameConnection::applyPersistence(%client, %gotPlayer, %gotCamera) { Parent::applyPersistence(%client, %gotPlayer, %gotCamera); //Do custom stuff here... }};activatePackage(<MyAddOn>PersistencePackage);Player Persistence files are saved as config/server/persistence/<blid>.txt
//load the persistence add-on now, if they have it enabled.//you can also use ForceRequiredAddOn if your add-on doesn't work without persistenceLoadRequiredAddOn("Script_Player_Persistence");if(isFunction(RegisterPersistenceVar)) //quick way to check if the persistence add-on loaded{ //usage: RegisterPersistenceVar(string <tagged field to match>, bool <match all>, string <datablock classname>); RegisterPersistenceVar("myVariable", false, ""); // save %client.myVariable and %player.myVariable to persistence file (if those values are set) RegisterPersistenceVar("myPrefix", true, ""); // save any tagged field on %client/%player starting with "myPrefix", // eg %client.myPrefixFoo %client.myPrefix_24, etc. // This is more expensive than a straight match and can have unintended consequences, so be careful RegisterPersistenceVar("myDatablockRef", false, "ItemData"); // save %client/%player.myDatablockRef to persistence but verifies that it is of class "ItemData" // and translates the id number into a datablock name before saving. // Datablock id numbers will vary depending on the order and number of add-ons loaded, // so use this if you need to save a datablock reference.}//optionally, you can package into the apply persistence function if you need to do custom stuff to fully restore the player's statepackage <MyAddOn>PersistencePackage{ function GameConnection::applyPersistence(%client, %gotPlayer, %gotCamera) { Parent::applyPersistence(%client, %gotPlayer, %gotCamera); //Do custom stuff here... }};activatePackage(<MyAddOn>PersistencePackage);
You can also use default persistence.http://forum.blockland.us/index.php?topic=174411.msg4480468#msg4480468
What exactly does the match all bool do?
Basically lets you register just once to save a set of data that all starts with a similar prefix. Look at the example in the comments next to it.
LoadRequiredAddOn("Script_Player_Persistence");if(isFunction(RegisterPersistenceVar)){ RegisterPersistenceVar("studs", false, "");}