new string[128];
format(string, sizeof(string), "SELECT * FROM `accounts` WHERE `username` = '%s'", plname);
mysql_function_query(dbHandle, string, true, "OnQueryFinish", "ii", THREAD_CHECK_ACCOUNT_CONNECT, playerid);
switch(gPlayerAccount[playerid])
{
case 0: DisplayDialogForPlayer(playerid, 2); //register
case 1: DisplayDialogForPlayer(playerid, 1); //login
}
public OnQueryFinish(resultid, playerid, ConnectionHandle)
{
new szRows, szFields;
if(resultid != THREAD_NO_RESULT)
{
cache_get_data(szRows, szFields);
}
switch(resultid)
{
case THREAD_CHECK_ACCOUNT_CONNECT:
{
if (szRows) {
new data[130];
cache_get_field_content(0, "Registered", data);
PlayerInfo[playerid][pReg] = strval(data);
if (PlayerInfo[playerid][pReg] == 1)
gPlayerLogged[playerid] = 1;
else
gPlayerLogged[playerid] = 0;
} else {
gPlayerLogged[playerid] = 0;
}
}
}
return 1;
}
if(cache_num_rows())
{
Follow this thread https://sampforum.blast.hk/showthread.php?tid=485633
EDIT: Also, you don't have to use "cache get data" and "(rows)" as written in this thread, use it just like this when you have done everything else. pawn Код:
|
public Update (playerid, type) {
new var[128];
switch (type) {
case pLevelx: {
format (var,128,"UPDATE `accounts` SET `Level` = '%d' WHERE `Username`='%s'", PlayerInfo[playerid][pLevel], PlayerName(playerid));
mysql_tquery (dbHandle, var, "OnQueryFinish", "ii", THREAD_NO_RESULT, playerid);
}
case pAdminx: {
format (var,128,"UPDATE `accounts` SET `AdminLevel` = '%d' WHERE `Username`='%s'", PlayerInfo[playerid][pAdmin], PlayerName(playerid));
mysql_tquery (dbHandle, var, "OnQueryFinish", "ii", THREAD_NO_RESULT, playerid);
}
case pDonateRankx: {
format (var,128,"UPDATE `accounts` SET `DonateRank` = '%d' WHERE `Username`='%s'", PlayerInfo[playerid][pDonateRank], PlayerName(playerid));
mysql_tquery (dbHandle, var, "OnQueryFinish", "ii", THREAD_NO_RESULT, playerid);
}
case pSPos_xx: {
format (var,128,"UPDATE `accounts` SET `SPos_x` = '%f' WHERE `Username`='%s'", PlayerInfo[playerid][pSPos_x], PlayerName(playerid));
mysql_tquery (dbHandle, var, "OnQueryFinish", "ii", THREAD_NO_RESULT, playerid);
}
case pSPos_yx: {
format (var,128,"UPDATE `accounts` SET `SPos_y` = '%f' WHERE `Username`='%s'", PlayerInfo[playerid][pSPos_y], PlayerName(playerid));
mysql_tquery (dbHandle, var, "OnQueryFinish", "ii", THREAD_NO_RESULT, playerid);
}
case pSPos_zx: {
format (var,128,"UPDATE `accounts` SET `SPos_z` = '%f' WHERE `Username`='%s'", PlayerInfo[playerid][pSPos_z], PlayerName(playerid));
mysql_tquery (dbHandle, var, "OnQueryFinish", "ii", THREAD_NO_RESULT, playerid);
}
case pSPos_rx: {
format (var,128,"UPDATE `accounts` SET `SPos_r` = '%f' WHERE `Username`='%s'", PlayerInfo[playerid][pSPos_r], PlayerName(playerid));
mysql_tquery (dbHandle, var, "OnQueryFinish", "ii", THREAD_NO_RESULT, playerid);
}
}
return 1;
}
for (new i = 0; i < NUMBER_OF_QUERIES; i++) // NUMBER_OF_QUERIES defined as 10
Update (playerid, i);
PlayerInfo[playerid][pLevel] = cache_get_field_content_int(0, "Level");
PlayerInfo[playerid][pAdmin] = cache_get_field_content_int(0, "AdminLevel");
PlayerInfo[playerid][pSPos_x] = cache_get_field_content_int(0, "SPos_x");
PlayerInfo[playerid][pSPos_y] = cache_get_field_content_int(0, "SPos_y");
PlayerInfo[playerid][pSPos_z] = cache_get_field_content_int(0, "SPos_z");
PlayerInfo[playerid][pSPos_r] = cache_get_field_content_int(0, "SPos_r");
PlayerInfo[playerid][pDonateRank] = cache_get_field_content_int(0, "DonateRank");
SaveAccount(playerid)
{
new Query[ 300 ];
mysql_format(MySQLHandle, Query, sizeof(Query), "UPDATE users SET SKILL_M4 = %d, SKILL_SNIPERRIFLE = %d WHERE IDPlayer = %d", PlayaInfo[ playerid ][ SKILL_M4 ], PlayaInfo[ playerid ][ SKILL_SNIPERRIFLE ], PlayaInfo[ playerid ][ IDPlayer ]);
mysql_tquery(MySQLHandle, Query);
//...
}
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
if(cache_num_rows())
{
Complications, complications and complications... First of all, UPDATE only pos X , pos Y and pos Z on disconnect. Things like level , donate rank etc UPDATE when it changes. Second: Why do you need that type? Save it normally, like the God commands! Third, look at my codes below ----
pawn Код:
cache_num_rows() pawn Код:
|