10.08.2010, 08:50
(
Last edited by Carlton; 19/08/2010 at 06:00 PM.
)
C-MySQL
Information Hi, I recently released a include called C-MySQL, the old include was:
- Slow
- Confusing
- Little opportunity (Speed increasing wise)
Setup
There's a new way to set this up now. Instead of the useless parameters that made the include confusing, there are now defines that you can fill out. These defines are below:
pawn Code:
#define ACCOUNT_TABLE ""
#define USERNAME_FIELD ""
#define PASSWORD_FIELD ""
pawn Code:
#define ACCOUNT_TABLE "Accounts"
#define USERNAME_FIELD "Username"
#define PASSWORD_FIELD "Password"
pawn Code:
#if defined MYSQL_PLUGIN
#include <a_mysql>
#else
#include <mysql>
#endif
pawn Code:
//#define MYSQL_PLUGIN // Defined = BlueG's plugin. | Undefined = Strickenkid's plugin.
Functions (List)
Code:
native CMySQL_Create(Username[], Password[], bool:md5 = true, ThreadID = -1, extraID = -1); native CMySQL_Delete(Username[], ThreadID = -1, extraID = -1); native CMySQL_SetInt(Username[], Field[], Value, ThreadID = -1, extraID = -1); native CMySQL_CustomDataSet(Username[], Custom[], ThreadID = -1, extraID = -1); native CMySQL_Set(Username[], Field[], Value[], bool:md5 = false, ThreadID = -1, extraID = -1); native CMySQL_SetFloat(Username[], Field[], Float:Value, ThreadID = -1, extraID = -1); native CMySQL_SetBool(Username[], Field[], bool:Value, ThreadID = -1, extraID = -1); native CMySQL_Load(Username[], ThreadID = -1, extraID = -1); native CMySQL_Exists(Username[]); native CMySQL_Int(Username[], Field[], ThreadID = -1, extraID = -1); native CMySQL_Get(Username[], Field[], Storage[], ThreadID = -1, extraID = -1); native Float:CMySQL_Float(Username[], Field[],ThreadID = -1, extraID = -1);
CMySQL_Create(Username[], Password[], bool:md5 = true, ThreadID = -1, extraID = -1)
Username - The account's username.
Password - The account's password.
bool:md5 - If true (default), then it md5 hashes the password, otherwise it doesn't.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:
pawn Code:
CMySQL_Create("Carlton", "MyPassword");
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:
pawn Code:
CMySQL_Delete("Carlton");
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:
pawn Code:
CMySQL_SetInt("Carlton", "AdminLevel", 1337);
Username - The account's username.
Custom - The custom saving query.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:
pawn Code:
CMySQL_CustomDataSet("Carlton", "AdminLevel = 1337, Money = 10000, SkinID = 17");
Username - The account's username.
Field - The field you would like to set the value to.
bool:md5 - If false (default), then it md5 hashes the value, otherwise it doesn't.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:
pawn Code:
CMySQL_Set("Carlton", "Password", "MyNewPassword", true);
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:
pawn Code:
CMySQL_SetFloat("Carlton", "PosX", 1337.0);
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:
pawn Code:
CMySQL_SetBool("Carlton", "IsHungry", true);
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:
pawn Code:
#define MYSQL_LOAD_ACCOUNT (0)
CMySQL_Load("Carlton", MYSQL_LOAD_ACCOUNT, playerid);
public OnQueryFinish(...) {
mysql_store_result();
....
}
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the account exists.
Example:
pawn Code:
if(CMySQL_Exists("Carlton")) return print("Your account exists!");
Username - The account's username.
Field - The field you would like to get the value from.
ThreadID - For threading usages.
extraID - For threading usages.
returns the value of the field.
Example:
pawn Code:
new MyMoney = CMySQL_Int("Carlton", "Money");
Username - The account's username.
Field - The field you would like to get the value from.
Storage - The string you'd like to store the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns nothing.
Example:
pawn Code:
new MyEmail[16];
CMySQL_Get("Carlton", "Email", MyEmail);
print(MyEmail);
Username - The account's username.
Field - The field you would like to get the value from.
ThreadID - For threading usages.
extraID - For threading usages.
returns the value of the field.
Example:
pawn Code:
SetPlayerPos(playerid, CMySQL_Float("Carlton", "CrashPosX"), CMySQL_Float("Carlton", "CrashPosY"), CMySQL_Float("Carlton", "CrashPosZ"),
pawn Code:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>
new MyMoney[MAX_PLAYERS], MyKills[MAX_PLAYERS];
stock GetUserName(playerid) {
new name[24];
GetPlayerName(playerid, name, 24); return name;
}
CMD:register(playerid, params[]) {
if(CMySQL_Exists(GetUserName(playerid))
return SendClientMessage(playerid, 0xFFFFFFA, "<> Your account exists already!");
new password[32];
if(sscanf(params, "s[32]", password))
return SendClientMessage(playerid, 0xFFFFFFA, "<> /register <password>");
if(strlen(password) > 32)
return SendClientMessage(playerid, 0xFFFFFFA, "<> Your password must be 32 characters or less.");
CMySQL_Create(GetUserName(playerid), password);
}
CMD:login(playerid, params[]) {
if(!CMySQL_Exists(GetUserName(playerid))
return SendClientMessage(playerid, 0xFFFFFFA, "<> Your account doesn't exist!");
new password[32];
if(sscanf(params, "s[32]", password))
return SendClientMessage(playerid, 0xFFFFFFA, "<> /login <password>");
if(strlen(password) > 32)
return SendClientMessage(playerid, 0xFFFFFFA, "<> Your password must be 32 characters or less.");
new Passwordz[32];
CMySQL_Get(GetUserName(playerid), "Password", Passwordz, true);
if(!strcmp(Passwordz, password, true)) {
SendClientMessage(playerid, 0xFFFFFFA, "<> You're now logged.");
CMySQL_Load(GetUserName(playerid), 1, playerid);
}
}
stock GetMyAdminLevel(Username[]) {
return CMySQL_Int(Username, "AdminLevel");
}
public OnPlayerDisconnect(playerid, reason) {
new string[128];
format(string, 128, "Money = %i, MyKills = %i", GetPlayerMoney(playerid), GetPlayerScore(playerid));
CMySQL_CustomDataSet(GetUserName(playerid), string);
}
public OnQueryFinish( query[], resultid, extraid, connectionHandle ) {
mysql_store_result();
new Data[128];
mysql_fetch_row_format(Data, "|");
sscanf(Data, "p<|>ii", MyMoney[extraid], MyKills[extraid]);
GivePlayerMoney(playerid, MyMoney[extraid]);
}
You will need either BlueG's or Strickenkids plugin, these can be found below:
http://forum.sa-mp.com/forumdisplay.php?f=18
Thanks to
Strickenkid - Plugin.
BlueG - Plugin.
Download
Click below.