29.09.2015, 04:25
(
Last edited by Gammix; 22/03/2016 at 09:50 PM.
)
Vars.inc
Version: 3 [BETA] (last updated on 22 March, 2016)
This include lets you save and load in memory variables at anytime in any script.
Now newest version support MySQL and SQLite both at the same time!!
What's the advantage?
In memory variables let you read their values across multiple scripts, and saving/loading them makes it powerful and fascinating.
Also, make use of MySQL and SQLite both at the same time without any hassle or errors.
Functions/stocks
Player Variables:
Server Variables:
Example
This is a simple stats saving and loading filterscript, which saves the user data from PVars to DB under OnPlayerDisconnect and loads in OnPlayerConnect.
Nothing could be as simple as this user database. Yes, you may also create a whole admin script/user database with this include, its pretty safe and faster according to the standards.
Switching database types
You can switch to any database by just setting the optional boolean parameter "db_type_sqlite" in all PVar/SVar functions of this include.
db_type_sqlite = false
(Works on MySQL database, so all the data will be written or read from MySQL database)
db_type_sqlite = true
(Works on SQLite database, so all the data will be written or read from SQLite <.db file> database)
Download
https://github.com/Gammix/Vars-Database
Version: 3 [BETA] (last updated on 22 March, 2016)
This include lets you save and load in memory variables at anytime in any script.
Now newest version support MySQL and SQLite both at the same time!!
What's the advantage?
In memory variables let you read their values across multiple scripts, and saving/loading them makes it powerful and fascinating.
Also, make use of MySQL and SQLite both at the same time without any hassle or errors.
Functions/stocks
Player Variables:
Code:
SavePVar(playerid, varname[], bool:db_type_sqlite = true); LoadPVar(playerid, varname[], bool:db_type_sqlite = true);
Code:
SaveSVar(varname[], bool:db_type_sqlite = true); LoadSVar(varname[], bool:db_type_sqlite = true);
This is a simple stats saving and loading filterscript, which saves the user data from PVars to DB under OnPlayerDisconnect and loads in OnPlayerConnect.
Nothing could be as simple as this user database. Yes, you may also create a whole admin script/user database with this include, its pretty safe and faster according to the standards.
Code:
#define FILTERSCRIPT #include <a_samp> #include <vars> public OnPlayerConnect(playerid) { // Load user data to PVars LoadPVar(playerid, "kills"); LoadPVar(playerid, "deaths"); LoadPVar(playerid, "score"); LoadPVar(playerid, "money"); return 1; } public OnPlayerDisconnect(playerid, reason) { // Save user PVar values to database SavePVar(playerid, "kills"); SavePVar(playerid, "deaths"); SavePVar(playerid, "score"); SavePVar(playerid, "money"); return 1; } public OnPlayerDeath(playerid, killerid, reason) { // Add +1 to kills SetPVarInt(killerid, "kills", GetPVarInt(killerid, "kills") + 1); // Add +1 to deaths SetPVarInt(playerid, "deaths", GetPVarInt(playerid, "deaths") + 1); // Add +1 to score SetPVarInt(killerid, "score", GetPVarInt(killerid, "score") + 1); // Add +500 to money GivePlayerMoney(killerid, 500); SetPVarInt(killerid, "money", GetPVarInt(killerid, "money") + 500); return 1; }
You can switch to any database by just setting the optional boolean parameter "db_type_sqlite" in all PVar/SVar functions of this include.
db_type_sqlite = false
(Works on MySQL database, so all the data will be written or read from MySQL database)
db_type_sqlite = true
(Works on SQLite database, so all the data will be written or read from SQLite <.db file> database)
Download
https://github.com/Gammix/Vars-Database