[Include] PVars.inc - Automatic PVar saving!
#1

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
  • 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.
The PVars will automatically save when they are modified and load when a player connects to the server.

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);
This callback is called before a player's PVars are loaded. Returning 0 under this callback will prevent the PVars from loading automatically.

pawn Код:
public OnPVarsLoaded(playerid, count);
This callback is called after a player's PVars have loaded successfully.

Functions

pawn Код:
native LoadPVarsForPlayer(playerid);
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.

pawn Код:
native SetPVarAutoSave(playerid, name[], bool:status);
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):

pawn Код:
// "TempVar" will not be saved or loaded.
SetPVarAutoSave(playerid, "TempVar", false);
Download
http://pastebin.com/6GwvDwx0
Reply


Messages In This Thread
PVars.inc - Automatic PVar saving! - by Emmet_ - 06.11.2014, 18:12
Re: PVars.inc - Automatic PVar saving! - by sammp - 06.11.2014, 18:21
Re: PVars.inc - Automatic PVar saving! - by JacobEdwards - 06.11.2014, 23:24
Re: PVars.inc - Automatic PVar saving! - by daniscape - 29.11.2014, 22:05
Re: PVars.inc - Automatic PVar saving! - by Crayder - 04.05.2015, 21:05
Re: PVars.inc - Automatic PVar saving! - by hamzajaved780 - 05.05.2015, 02:53
Re: PVars.inc - Automatic PVar saving! - by Crayder - 05.05.2015, 04:45
Re: PVars.inc - Automatic PVar saving! - by Emmet_ - 05.05.2015, 05:11
Re: PVars.inc - Automatic PVar saving! - by Sellize - 05.05.2015, 06:25
Re: PVars.inc - Automatic PVar saving! - by Emmet_ - 05.05.2015, 06:31

Forum Jump:


Users browsing this thread: 1 Guest(s)