It don't change the data on database -
DarkMythHunter - 12.09.2018
PHP код:
IRCCMD:setscore(botid, channel[], user[], host[], params[])
{
if(!IRC_IsAdmin(botid, channel, user)) return IRC_Notice(botid, user, "\x0204[ERROR]:\x02 You are don't have permission to use this command!");
if(!IsPlayerWhiteList(user)) return IRC_Notice(botid, user, "\x0204[ERROR]:\x02 You are don't have permission to use this command!");
new targetid, score, string[144];
if(sscanf(params, "ud", targetid, score)) return IRC_Notice(gGroupID, user,"\x0214[USAGE]:\x02 !setscore [player id] [score]") && IRC_Notice(gGroupID, user,"\x0214[FUNCTION]:\x02 Set a player's score");
if(!IsPlayerConnected(targetid)) return IRC_Notice(botid, user, "\x0204[ERROR]:\x02 That player is not online!");
if(IsPlayerNPC(targetid)) return IRC_Notice(botid, user, "\x0204[ERROR]:\x02 You cannot set an NPC's score!");
if(pInfo[targetid][pIsPlayerLogged] == false) IRC_Notice(botid, user, "\x0204[ERROR]:\x02 This player hasn't logged-in yet!");
if(pInfo[targetid][pIsPlayerSpawned] == false) IRC_Notice(botid, user, "\x0204[ERROR]:\x02 This player hasn't spawned yet!");
pInfo[targetid][pHours] = score;
SetPlayerScore(targetid, score);
format(string, sizeof(string), "*"COL_WHITE" %s "COL_ORANGE"has set your score to "COL_WHITE"%i", user, score);
SendClientMessage(targetid, -1, string);
format(string, sizeof(string), "*"COL_WHITE" %s "COL_ORANGE"has set "COL_WHITE"%s"COL_ORANGE"'s score to "COL_WHITE"%i", user, pInfo[targetid][pUsername], score);
SendMessageToAllAdmins(string, -1, pInfo[targetid][pAdminLevel] > 0 ? targetid : INVALID_PLAYER_ID);
format(string, sizeof(string), "\x0203[INFO]:\x02 \x1D%s\x1D has set \x1D%s\x1D's score to \x1D%d\x1D", user, pInfo[targetid][pUsername], score);
IRC_GroupSay(gGroupID, channel, string);
SendToLog("/setscore", user, pInfo[targetid][pUsername], score);
return 1;
}
This one don't work correctly, it do changes the online player score but it does not change the data in the database. So if the player logged off, and logged in the old score will still load.
This is the other one for /setoffscore, for offline players. This one works.
PHP код:
IRCCMD:setoffscore(botid, channel[], user[], host[], params[])
{
if(!IRC_IsAdmin(botid, channel, user)) return IRC_Notice(botid, user, "\x0204[ERROR]:\x02 You are don't have permission to use this command!");
if(!IsPlayerWhiteList(user)) return IRC_Notice(botid, user, "\x0204[ERROR]:\x02 You are don't have permission to use this command!");
new targetName[MAX_PLAYER_NAME], score, _query[120];
if(sscanf(params, "s[24]d", targetName, score)) return IRC_Notice(gGroupID, user,"\x0214[USAGE]:\x02 !setoffscore [username] [score]") && IRC_Notice(gGroupID, user,"\x0214[FUNCTION]:\x0F Set an offline player's score");
if(IsValidAccount(targetName) == 0) return IRC_Notice(botid, user, "\x0204[ERROR]:\x02 You have inputed an invalid account name!");
format(_query, sizeof(_query), "UPDATE `accounts` SET `Hours` = %d WHERE `Username` = '%s'", score, targetName);
mysql_tquery(handle, _query);
format(_query, sizeof(_query), "\x0203[INFO]:\x02 \x1D%s\x1D has set \x1D%s\x1D's score to \x1D%d\x1D", user, targetName, score);
IRC_GroupSay(gGroupID, channel, _query);
SendToLog("!setscore", user, targetName, score);
return 1;
}
Re: It don't change the data on database -
UFF - 12.09.2018
Код:
format(_query, sizeof(_query), "UPDATE `accounts` SET `Hours` = %d WHERE `Reg_ID` = '%d'", score, pInfo[targetid][pRegID]);
mysql_tquery(handle, _query);
Instead of Reg_ID and pInfo[targetid][pRegID], use your users reg ids column name and Reg variable. Use this code at the bottm of the /setscore command.
Re: It don't change the data on database -
iLearner - 12.09.2018
This is not how saving works, with set score you're supposed to save the score in a local variable that's all.
The saving / loading system should do the rest. (Normally you load userdata on login into local variables and then save those variables again to mysql when player leaves).