06.11.2014, 18:12
PVars.inc
What is this?
The per-player variable system in SA-MP is mainly used for simple data storing. However, PVars aren't that much useful, except for sharing the data across scripts, but there's "CallRemoteFunction" for that. Some people really only use them just for the storing, and nothing else!
That being said, I've decided to code this library that introduces automatic PVar saving! This makes them much more useful and also allows easier control over user data.
Note that I've released something similar over 2 years ago, but since I requested my topics to be removed, I've decided to recreate it using SQLite.
Features
Note: "DeletePVar" will remove the value from the database and "SetPlayerName" will automatically readjust the records in the database to the new player's name.
Callbacks
There are two callbacks:
This callback is called before a player's PVars are loaded. Returning 0 under this callback will prevent the PVars from loading automatically.
This callback is called after a player's PVars have loaded successfully.
Functions
Loads the player's PVars. This is useful for login systems, where you can return 0 under "OnPVarAttemptLoad" and then load them when a player logs in.
Allows you to disable saving for specific PVars. Setting to "false" will prevent the PVar from being saved.
Exceptions
There might be a few PVars in your script that you don't want to save at all. This can be fixed by disabling auto save for that specific variable.
Example (under OnPlayerConnect):
Download
http://pastebin.com/6GwvDwx0
What is this?
The per-player variable system in SA-MP is mainly used for simple data storing. However, PVars aren't that much useful, except for sharing the data across scripts, but there's "CallRemoteFunction" for that. Some people really only use them just for the storing, and nothing else!
That being said, I've decided to code this library that introduces automatic PVar saving! This makes them much more useful and also allows easier control over user data.
Note that I've released something similar over 2 years ago, but since I requested my topics to be removed, I've decided to recreate it using SQLite.
Features
- Saving and loading on the fly! You don't need any other additional code.
- Multiple script support. You can use this in multiple scripts!
- Easier user data management.
Note: "DeletePVar" will remove the value from the database and "SetPlayerName" will automatically readjust the records in the database to the new player's name.
Callbacks
There are two callbacks:
pawn Код:
public OnPVarAttemptLoad(playerid);
pawn Код:
public OnPVarsLoaded(playerid, count);
Functions
pawn Код:
native LoadPVarsForPlayer(playerid);
pawn Код:
native SetPVarAutoSave(playerid, name[], bool:status);
Exceptions
There might be a few PVars in your script that you don't want to save at all. This can be fixed by disabling auto save for that specific variable.
Example (under OnPlayerConnect):
pawn Код:
// "TempVar" will not be saved or loaded.
SetPVarAutoSave(playerid, "TempVar", false);
http://pastebin.com/6GwvDwx0