13.01.2015, 15:59
Hello , i added points system in my script but the players points don't save when he disconnect . Here is my code.
Admin can give them point by:
Following is the SaveData.
OnPlayerDisconnect.
OnPlayerConnect
Following is LoginPlayer code.
Admin can give them point by:
PHP код:
CMD:givepp(playerid, params[])
{
LoginCheck(playerid);
if(User[playerid][accountAdmin] >= 3)
{
new string[150], id, amount;
if(sscanf(params, "ui", id, amount)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /givepp [playerid] [amount]");
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "» "red"Player not connected.");
if(User[id][accountLogged] == false) return SendClientMessage(playerid, -1, "» "red"Player not logged in.");
format(string, 150, "[PREMIUM POINTS] "red"%s has given %s [%d] Premium Points.", GetName(playerid), GetName(id), amount);
SendAMessage(-1, string);
format(string, 150, ""green"[PREMIUM POINTS] "white"You have received "grey"%d "white"premium points from an "red"admin"white".", amount, User[id][accountPP]+amount);
SendClientMessage(id, -1, string);
format(string, 150, "» You have given {%06x}%s "white"premium points of "grey"%d"white".", GetPlayerColor(id) >>> 8, GetName(id), amount);
SendClientMessage(playerid, -1, string);
format(string, 128, "%s received %d Premium Points from %s.", GetName(id), amount, GetName(playerid));
Log("premium.txt", string);
User[id][accountPP] += amount;
SaveData(id);
}
else
{
SendClientMessage(playerid, -1, "» "red"You are not authorized to use this command.");
}
return 1;
}
PHP код:
stock SaveData(playerid)
{
new
Query[700]
;
format(Query, sizeof(Query), "UPDATE `users` SET `IP` = '%s', `admin` = %d, `kills` = %d, `deaths` = %d, `score` = %d, `money` = %d, `warn` = %d, `mute` = %d, `mutesec` = %d, `cmute` = %d, `cmutesec` = %d, `jail` = %d, `jailsec` = %d, `hours` = %d, `minutes` = %d, `seconds` = %d WHERE `username` = '%s'",
User[playerid][accountIP],
User[playerid][accountAdmin],
User[playerid][accountKills],
User[playerid][accountDeaths],
User[playerid][accountScore],
User[playerid][accountCash],
User[playerid][accountWarn],
User[playerid][accountMuted],
User[playerid][accountMuteSec],
User[playerid][accountCMuted],
User[playerid][accountCMuteSec],
User[playerid][accountJail],
User[playerid][accountJailSec],
User[playerid][accountGame][2],
User[playerid][accountGame][1],
User[playerid][accountGame][0],
User[playerid][accountPP],
DB_Escape(User[playerid][accountName])
);
db_query(Database, Query);
db_free_result(db_query(Database, Query));
return 1;
}
PHP код:
if(User[playerid][accountLogged] == true)
{
//Saves the statistics to the .db.
SaveData(playerid);
}
PHP код:
if(strcmp(fIP, User[playerid][accountIP], true) == 0)
{
SendClientMessage(playerid, -1, "You have been auto logged in.");
LoginPlayer(playerid);
}
PHP код:
function:LoginPlayer(playerid)
{
new
Query[900],
DBResult:Result,
string[128+40]
;
format(Query, sizeof(Query), "SELECT * FROM `users` WHERE `username` = '%s'", DB_Escape(pName(playerid)));
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
db_get_field_assoc(Result, "userid", Query, 7);
User[playerid][accountID] = strval(Query);
db_get_field_assoc(Result, "score", Query, 20);
User[playerid][accountScore] = strval(Query);
SetPlayerScore(playerid, User[playerid][accountScore]);
db_get_field_assoc(Result, "money", Query, 20);
User[playerid][accountCash] = strval(Query);
GivePlayerMoney(playerid, User[playerid][accountCash]);
db_get_field_assoc(Result, "kills", Query, 20);
User[playerid][accountKills] = strval(Query);
db_get_field_assoc(Result, "deaths", Query, 20);
User[playerid][accountDeaths] = strval(Query);
db_get_field_assoc(Result, "admin", Query, 7);
User[playerid][accountAdmin] = strval(Query);
db_get_field_assoc(Result, "joindate", Query, 150);
format(User[playerid][accountDate], 150, "%s", Query);
db_get_field_assoc(Result, "warn", Query, 5);
User[playerid][accountWarn] = strval(Query);
db_get_field_assoc(Result, "mute", Query, 5);
User[playerid][accountMuted] = strval(Query);
db_get_field_assoc(Result, "mutesec", Query, 8);
User[playerid][accountMuteSec] = strval(Query);
db_get_field_assoc(Result, "cmute", Query, 6);
User[playerid][accountCMuted] = strval(Query);
db_get_field_assoc(Result, "cmutesec", Query, 9);
User[playerid][accountCMuteSec] = strval(Query);
db_get_field_assoc(Result, "jail", Query, 5);
User[playerid][accountJail] = strval(Query);
db_get_field_assoc(Result, "jailsec", Query, 8);
User[playerid][accountJailSec] = strval(Query);
db_get_field_assoc(Result, "hours", Query, 6);
User[playerid][accountGame][2] = strval(Query);
db_get_field_assoc(Result, "minutes", Query, 8);
User[playerid][accountGame][1] = strval(Query);
db_get_field_assoc(Result, "seconds", Query, 8);
User[playerid][accountGame][0] = strval(Query);
db_get_field_assoc(Result, "premiumpoints", Query, 14);
User[playerid][accountPP] = strval(Query);
User[playerid][accountLogged] = true;
if(User[playerid][accountMuted] == 1)
{
format(string, 200, "PUNISHMENT: You have been muted from using the chat for %d seconds, You are muted the last time you logged out.", User[playerid][accountMuteSec]);
SendClientMessage(playerid, COLOR_RED, string);
}
if(User[playerid][accountCMuted] == 1)
{
format(string, 200, "PUNISHMENT: You have been muted from using the commands for %d seconds, You are muted the last time you logged out.", User[playerid][accountCMuteSec]);
SendClientMessage(playerid, COLOR_RED, string);
}
SendClientMessage(playerid, COLOR_YELLOW, "SERVER: You have successfully logged in to the server.");
if(User[playerid][accountAdmin] >= 1)
{
SendClientMessage(playerid, -1, "You have logged into your administrative account, Good luck doing your duties.");
}
PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
}
db_free_result(Result);
return 1;
}