22.07.2011, 00:17
TKsave
Introduction
This is a really basic include just to show you how useful SQLite can be. Information saves into a database and can be used easier for web files . I'm not going to make one of those "This is very efficient topic" because it's probably not as fast as most file saving systems.
How do I install this?
1. Put the include in your server directory -> Pawno -> includes
2. Add this to the top of your script
pawn Код:
#include <tksave>
pawn Код:
/*
native sql_setplayerdata(playerid, field[], data[]); - Sets a player's data (string)
native sql_isplayerindb(playerid); - Checks if a player is in the database
native sql_getplayerdata(playerid, field[]); - Gets a player's data (string)
native sql_getplayerint(playerid, field[]); - Gets a player int from the database
native sql_getplayerfloat(playerid, field[]); // Gets a player's float from the database
native sql_setplayerfloat(playerid, field[], Float:data); - Set's a players float (could be used for a position)
native sql_setplayerint(playerid, field[], data); // Sets a players int (Could be used for money or admin lvl)
native sql_addfield(field[], type, MAXSIZE); - Add a table field such as password (Type 0 = Number, Type 1 = String, Type 2 = Float)
native sql_getusercount(); // Get the amount of users registered
native sql_inittable(); // Set's up the database / table (Only need to use this once but it won't make a difference if you leave it there)
native sql_open(sql[]); //Opens a SQL database (Chose a name for your database). This must be above everything on OnGameModeInit or OnFilterScriptInit. You must add .db on the end!
native sql_close(sql[]); //Closes the database, this is to be used on OnGameModeInit or OnFilterScriptInit. You must add .db on the end!
*/
Saving a players position on Disconnect then loading it on OnPlayerSpawn.
pawn Код:
public OnFilterScriptInit()
{
sql_open("database.db");
sql_inittable();
sql_addfield("X", 2, 50);
sql_addfield("Y", 2, 50);
sql_addfield("Z", 2, 50);
return 1;
}
public OnFilterScriptExit()
{
sql_close("database.db");
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new Float:X, Float:Y, Float:Z;
sql_setplayerfloat(playerid, "X", X);
sql_setplayerfloat(playerid, "Y", Y);
sql_setplayerfloat(playerid, "Z", Z);
return 1;
}
public OnPlayerSpawn(playerid)
{
if(sql_isplayerindb(playerid))
{
SetPlayerPos(playerid, sql_getplayerfloat(playerid, "X"), sql_getplayerfloat(playerid, "Y"), sql_getplayerfloat(playerid, "Z"));
}
return 1;
}
HERE
Any bugs, post them here .