saving system not working - Y_INI -
Chrillzen - 16.10.2013
Hey. My cash works with the saving system I have (Kush's tutorial) but everything else doesn't. Here's the problem.
I tried registering a new account with no other accounts in the users folder. Then I went to buy 10 grams of marijuana and I gave myself admin level 4, then I quit the server.
Then I registered a new account and I checked my stats, and I had 10 grams of marijuana and admin level 4.
Does anyone know why this is happening?
Here's two examples on how I give myself the stats.
pawn Code:
CMD:makeadmin(playerid, params[])
{
new pID, value, id, string[124];
if(PlayerInfo[playerid][pAdmin] < 4 && !IsPlayerAdmin(playerid)) return SCM( playerid, COLOR_GREY, "[Error]: You're not authorized to use this command.");
else if (sscanf(params, "ui", pID, value)) return SCM(playerid, COLOR_GREY, "[Usage]: /makeadmin [playerid/partofname] [level 1-4].");
else if (value < 0 || value > 4) return SCM(playerid, COLOR_LIGHTRED, "[Error]: Invalid administrator level, 0-4.");
else if(!IsPlayerConnected(id)) return SCM(playerid, COLOR_LIGHTRED, "[Error]: That player is not connected.");
format(string, sizeof(string), "AdmCmd: %s has set %s's admin-level to %d.", GetName(playerid), GetName(id), value);
SendClientMessageToAll(COLOR_LIGHTRED,string);
PlayerInfo[pID][pAdmin] = value;
return 1;
}
pawn Code:
CMD:knock(playerid, params[])
{
PlayerInfo[playerid][dMarijuana] += 10;
return 1;
}
My LoadUser data:
pawn Code:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);
INI_Int("Cash",PlayerInfo[playerid][pCash]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("Kills",PlayerInfo[playerid][pKills]);
INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
INI_Int("LSD",PlayerInfo[playerid][dLSD]);
INI_Int("Cocaine",PlayerInfo[playerid][dCocaine]);
INI_Int("Marijuana",PlayerInfo[playerid][dMarijuana]);
INI_Int("Respect",PlayerInfo[playerid][pRespect]);
INI_Int("Cigarettes",PlayerInfo[playerid][pCigarettes]);
return 1;
}
UserPath
pawn Code:
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PATH,playername);
return string;
}
OnPlayerDisconnect
pawn Code:
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_WriteInt(File,"LSD",PlayerInfo[playerid][dLSD]);
INI_WriteInt(File,"Cocaine",PlayerInfo[playerid][dCocaine]);
INI_WriteInt(File,"Marijuana",PlayerInfo[playerid][dMarijuana]);
INI_WriteInt(File,"Respect",PlayerInfo[playerid][pRespect]);
INI_WriteInt(File,"Cigarettes",PlayerInfo[playerid][pCigarettes]);
INI_Close(File);
When registering a new account.
pawn Code:
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Cash",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"LSD",0);
INI_WriteInt(File,"Cocaine",0);
INI_WriteInt(File,"Marijuana",0);
INI_WriteInt(File,"Respect",0);
INI_WriteInt(File,"Cigarettes",0);
INI_Close(File);
Re: saving system not working - Y_INI -
Chrillzen - 16.10.2013
Okay, I've seemed to fix it myself by resetting all the variables OnPlayerConnect.
Re: saving system not working - Y_INI -
gtakillerIV - 16.10.2013
You should reset all the variables to 0 under OnPlayerDisconnect. EX:
Code:
PlayerInfo[playerid][dMarijuana] = 0;
EDIT: Haha you got it
Re: saving system not working - Y_INI -
tyler12 - 16.10.2013
// Rename accountInformation to your enum name
for(new accountInformation:i; i < accountInformation; i++)
{
PlayerInfo[playerid][i] = 0;
}
under OnPlayerConnect. This will loop through your enum and reset each variable to 0.