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:
//load the persistence add-on now, if they have it enabled.
//you can also use ForceRequiredAddOn if your add-on doesn't work without persistence
LoadRequiredAddOn("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 state
package <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