... R7 but
there is new function mysql_function_query .... there is code but it doesnt work and i dont know why
Код:
#include <a_samp>
#include <a_mysql>
#include <sscanf2>
#define USER "samp"
#define PASS "159753"
#define DB "samp"
#define IP "localhost"
#define LOGIN_DIALOG 1
#define REGISTER_DIALOG 2
#define COLOR_GRAD 0x6E76ADFF
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_BLUE 0x18A4FFFF
forward IsUsernameRegistered(playerid, usernm[]);
forward OnLoginPlayer(playerid, pas[]);
forward SavePlayerStats(playerid);
enum pdb
{
username[MAX_PLAYER_NAME],
pass[32], // He use 32 cells because Md5 is based 32 cell encriptation,
experience,
money,
admin,
maxexp,
logged,
}
new playerdb[MAX_PLAYERS][pdb];
new mysqlconnection;
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
mysql_debug(true);
print("Register Loading...");
mysqlconnection = mysql_connect(IP, USER, DB, PASS);
if(mysql_ping()>=1)
{
print("MySQL: Connected sucesfull");
}
else
{
print("Cannot connect to MySQL");
SendRconCommand("exit");
}
return 1;
}
public OnGameModeExit()
{
mysql_close();
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, playerdb[playerid][username], 24); // username is sa-mp defined 24 cells
mysql_function_query(mysqlconnection ,"SELECT * FROM users WHERE Name = '%s'", false, "IsUsernameRegistered", "s", playerdb[playerid][username]);
IsUsernameRegistered(playerid, playerdb[playerid][username]);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
mysql_function_query(mysqlconnection, "UPDATE users SET Money = %d WHERE Name ='%s'", false, "SavePlayerStats", "ds", GetPlayerMoney(playerid),playerdb[playerid][username]);
SavePlayerStats(playerid);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == REGISTER_DIALOG)
{
if(!response)
{
SendClientMessage(playerid, COLOR_GRAD,"You have been kicked duo the cancelation.");
Kick(playerid);
}
// The register syntax is INSERT INTO destination, the names of the fields and it's values.
mysql_function_query(mysqlconnection, "INSERT INTO users (Name,Password,Money) VALUES ('%s',md5('%s'), %d)", false, "ssd", playerdb[playerid][username], inputtext, 50000);
ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"Login to Account.","Enter your password below:","Login","Cancel");
}
if(dialogid == LOGIN_DIALOG)
{
if(!response)
{
SendClientMessage(playerid, COLOR_GRAD,"You have been kicked duo the cancelation.");
Kick(playerid);
}
mysql_function_query(mysqlconnection,"SELECT * FROM users WHERE Name = '%s' AND Password = md5('%s')", false, "OnLoginPlayer", "ss", playerdb[playerid][username], inputtext);
OnLoginPlayer(playerid, inputtext);
}
return 1;
}
public IsUsernameRegistered(playerid, usernm[])
{
mysql_store_result();
if(mysql_num_rows() != 0)
{
ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_PASSWORD,"Register Account.","Enter your password below:","Register","Cancel");
}
else
{
ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_PASSWORD,"Register Account.","Enter your password below:","Register","Cancel");
}
mysql_free_result();
return 1;
}
public OnLoginPlayer(playerid, pas[])
{
new result[1000];
mysql_store_result();
if(mysql_num_rows() != 0)
{
if(mysql_fetch_row_format(result , "|", mysqlconnection))
{
sscanf(result,"e<p<|>s[24]s[32]i>", playerdb[playerid]);
new str[80];
format(str, sizeof(str),"Welcome %s, you have been logged to your account",playerdb[playerid][username]);
SendClientMessage(playerid, COLOR_BLUE, str);
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
SpawnPlayer(playerid);
playerdb[playerid][logged] = 1;
}
}
else
{
ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"Login to Account.","Wrong password:","Login","Cancel");
}
mysql_free_result();
return 1;
}
public SavePlayerStats(playerid) // save player stats
{
if(playerdb[playerid][logged] == 1)
{
new pmoney[MAX_PLAYERS];
pmoney[playerid] = GetPlayerMoney(playerid);
mysql_free_result();
playerdb[playerid][logged] = 0;
}
return 1;
}
... yes but dont know why and where.. .. somebody help me please..
iґve got it ... but still doesnt work... 0 rows in DB and log is the same..