#define PATH "GoldUser/%s.ini"
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Gold",PlayerInfo[playerid][pGold]);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Gold",PlayerInfo[playerid][pGold]);
INI_Close(File);
return 1;
}
Don t save the stats when a player disconnects . Save them right after you modify them , because otherwise in case of a server stop or restart, the data will be lost.
OnPlayerDisconnect is not called if the server crashes or restarts. |
CMD:setgold(playerid, params[]) { if(IsPlayerAdmin(playerid)) { new string[400], tname[MAX_PLAYER_NAME], targetid, maxcookies; if(sscanf(params, "ii", targetid, maxcookies)) { return SendClientMessage(playerid, 0xF8F8F8FFF, "Syntax: {Ffffff}/setgold <id> <amount>"); } for(new i=0;i<MAX_PLAYERS; i++) continue; { if((!IsPlayerConnected(targetid)) || (targetid == INVALID_PLAYER_ID)) { SendClientMessage(playerid,-1, "{f00f00}ERROR: {FFFFFF}Player isn't Connected!"); } } if(maxcookies < 0 || maxcookies > 100000000) { return SendClientMessage( playerid, 0xF8F8F8FFF, "{f00f00}ERROR: {FFFFFF}highest amount is 100000000."); } else { GetPlayerName(targetid, tname, sizeof(tname)); format(string, sizeof(string), "{A9C4E4}an administrator has set %s's golds amount to %i.", tname, maxcookies); SendClientMessageToAll(0xF8F8F8FFF, string); GameTextForPlayer(targetid,"~W~W~P~O~R~W! ~B~N~G~I~R~C~P~E! ~Y~GOLD! ~R~:)",3000,3); PlayerPlaySound(targetid, 17802, 0.0, 0.0, 0.0); new INI:File = INI_Open(UserPath(targetid)); PlayerInfo[targetid][pGold] = maxcookies; INI_WriteInt(File,"Gold",maxcookies); INI_Close(File); return 1; } } else { SendClientMessage(playerid, 0xf8F8F8FFF,"{F00f00}ERROR: {FFFFFF}You aren't authorized to use this command."); } return 1; }
I had that issue, so you basically save stats on callback "On Gamemode Exit"?
|
CMD:setgold(playerid, params[]) { if(IsPlayerAdmin(playerid)) { new string[400], tname[MAX_PLAYER_NAME], targetid, maxcookies; if(sscanf(params, "ii", targetid, maxcookies)) { return SendClientMessage(playerid, 0xF8F8F8FFF, "Syntax: {Ffffff}/setgold <id> <amount>"); } for(new i=0;i<MAX_PLAYERS; i++) continue; { if((!IsPlayerConnected(targetid)) || (targetid == INVALID_PLAYER_ID)) { SendClientMessage(playerid,-1, "{f00f00}ERROR: {FFFFFF}Player isn't Connected!"); } } if(maxcookies < 0 || maxcookies > 100000000) { return SendClientMessage( playerid, 0xF8F8F8FFF, "{f00f00}ERROR: {FFFFFF}highest amount is 100000000."); } else { GetPlayerName(targetid, tname, sizeof(tname)); format(string, sizeof(string), "{A9C4E4}an administrator has set %s's golds amount to %i.", tname, maxcookies); SendClientMessageToAll(0xF8F8F8FFF, string); GameTextForPlayer(targetid,"~W~W~P~O~R~W! ~B~N~G~I~R~C~P~E! ~Y~GOLD! ~R~:)",3000,3); PlayerPlaySound(targetid, 17802, 0.0, 0.0, 0.0); new INI:File = INI_Open(UserPath(targetid)); PlayerInfo[targetid][pGold] = maxcookies; INI_WriteInt(File,"Gold",maxcookies); INI_Close(File); return 1; } } else { SendClientMessage(playerid, 0xf8F8F8FFF,"{F00f00}ERROR: {FFFFFF}You aren't authorized to use this command."); } return 1; }
public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
SendClientMessage(playerid, -1, "Welcome back");
}
else
{
SendClientMessage(playerid, -1, "welcome it's ur first time");
}
return 1;
}