Problem in saving Player data using dini. -
DJDhan - 20.07.2010
I have problem in my code that I have tried to solve for a long time now but can't really fix it.
So, I need your help fixing them.
I use "dini" system to save player data to files. Here is a simple example on how I save the data.
Code:
enum data
{
Kills
};
Code:
new pinfo[MAX_PLAYERS][data];
Code:
public OnPlayerConnect(playerid)
{
new file[128];
format(file,128,"/20accounts/%s.ini",name(playerid));
if(fexist(file))
{
login(playerid);
}
return 1;
}
Code:
login(playerid)
{
new file[128];
format(file,128,"/20accounts/%s.ini",name(playerid));
pinfo[playerid][Kills] = dini_Int(file,"Kills");
return 1;
}
Code:
public OnPlayerDeath(playerid,killerid,reason)
{
pinfo[killerid][Kills]++;
return 1;
}
Code:
public OnPlayerDisconnect(playerid,reason)
{
new file[128];
format(file,128,"/20accounts/%s.ini",name(playerid));
dini_IntSet(file, "Kills", pinfo[playerid][Kills]);
return 1;
}
The register command:
Code:
if(!strcmp(cmdtext,"/register",true))
{
new file[128];
format(file,128,"/20accounts/%s.ini",name(playerid));
dini_Create(file);
dini_IntSet(file, "Kills", pinfo[playerid][Kills]);
return 1;
}
The values in the file remain 0 (zero) no matter what I do.
Can anyone give it a shot?
Re: Problem in saving Player data using dini. -
Grim_ - 20.07.2010
pawn Code:
public OnPlayerConnect(playerid)
{
new file[128];
format(file,128,"/accounts/%s.ini",name(playerid));
if(fexist(file))
{
login(playerid);
}
return 1;
}
^ That format of the file is incorrect. You're missing "20" before "accounts".
Re: Problem in saving Player data using dini. -
DJDhan - 20.07.2010
Erm sorry but that is just a typo. I'll correct it. It isn't like that in the script though, no typos anywhere.
Re: Problem in saving Player data using dini. -
Kar - 20.07.2010
maybe make a stock loadplayer and save playeR? i dont see whats wrong here. but i only have the word kills in my gm 4 times and mine works fine.
you should make one of these
pawn Code:
format(pfile, sizeof(pfile), pfile_path, Playername(playerid));
instead of having to put accounts/w/e everytime
Re: Problem in saving Player data using dini. -
DJDhan - 20.07.2010
I tried "stock", "public" and simply "login(playerid)" and it did not make any difference. Before "saving the data under OnPlayerDisconnect", I used a function "logout(playerid)" and tried to debug. I came to know that it never actually executed "logout(playerid)". Hence I put it under OnPlayerDisconnect but it doesn't save the data anyhow.
Re: Problem in saving Player data using dini. -
Kar - 20.07.2010
is this in a small script. or in a big one. because in some scripts if you put to much in certain publics it doesn't save sometimes. yesterday i noticed i had a scm in onplayerdeath and it was never sending<.<
is kills the only thing not saving?
Re: Problem in saving Player data using dini. -
DJDhan - 20.07.2010
This system is a part of my gamemode. And no, it's not only the "Kills" but there are more than 10 stats that are not being updated in the file. I have read other registration scripts but I can't see any problem in my script.
Re: Problem in saving Player data using dini. -
Kar - 20.07.2010
Take A Look At Mine Nixiie Help me make it
pawn Code:
new pfile[128]; // Holds the dir. where the player file is stored
#define pfile_path "Users/%s.ini"
pawn Code:
enum Playerinfo_Enum
{
Kills,
Deaths,
LastVeh,
IsCuffed,
HasDrugs,
HasCrack,
WeedAmount,
Seeds,
SeedPlanted,
PickupableDrugs,
};
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
PlayerInfo[playerid][Deaths]++;
PlayerInfo[killerid][Kills]++;
pawn Code:
stock LoadPlayer(playerid)
{
SetPlayerScore(playerid, dini_Int(pfile, "Score"));
GivePlayerMoney(playerid, - GetPlayerMoney(playerid) + dini_Int(pfile, "Money"));
SetPlayerWantedLevel(playerid, dini_Int(pfile, "WantedLevel"));
SetPlayerDrunkLevel(playerid, dini_Int(pfile, "DrunkLevel"));
SetPlayerFightingStyle(playerid, dini_Int(pfile, "FightStyle"));
StoreSecond[playerid] = dini_Int(pfile, "SecondsLogged");
StoreMinute[playerid] = dini_Int(pfile, "MinutesLogged");
StoreHour[playerid] = dini_Int(pfile, "HoursLogged");
PlayerInfo[playerid][Kills] = dini_Int(pfile,"Kills");
PlayerInfo[playerid][Deaths] = dini_Int(pfile,"Deaths");
PlayerInfo[playerid][WeedAmount] = dini_Int(pfile, "Weed");
PlayerInfo[playerid][Seeds] = dini_Int(pfile, "Seeds");
SetPlayerFacingAngle(playerid, dini_Int(pfile, "Angle"));
return 1;
}
stock SavePlayer(playerid)
{
format(pfile, sizeof(pfile), pfile_path, Playername(playerid));
new Float:angle;
GetPlayerFacingAngle(playerid,angle);
dini_FloatSet(pfile, "Angle", playerid);
dini_IntSet(pfile, "Score", GetPlayerScore(playerid));
dini_IntSet(pfile, "Money", GetPlayerMoney(playerid));
dini_IntSet(pfile, "Hourslogged", StoreHour[playerid]);
dini_IntSet(pfile, "MinutesLogged", StoreMinute[playerid]);
dini_IntSet(pfile, "SecondsLogged", StoreSecond[playerid]);
dini_IntSet(pfile, "WantedLevel", GetPlayerWantedLevel(playerid));
dini_IntSet(pfile, "DrunkLevel", GetPlayerDrunkLevel(playerid));
dini_IntSet(pfile, "FightStyle", GetPlayerFightingStyle(playerid));
dini_IntSet(pfile,"Kills",PlayerInfo[playerid][Kills]);
dini_IntSet(pfile,"Deaths",PlayerInfo[playerid][Deaths]);
dini_IntSet(pfile,"Weed", PlayerInfo[playerid][WeedAmount]);
dini_IntSet(pfile,"Seeds", PlayerInfo[playerid][Seeds]);
IsLogged[playerid] = 0;
StoreSecond[playerid] = 0;
StoreMinute[playerid] = 0;
StoreHour[playerid] = 0;
return 1;
}
pawn Code:
CMD:login(playerid, params[])
{
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
new ppw[20], str[128];
format(pfile, sizeof(pfile), pfile_path, Playername(playerid));
if(sscanf(params, "s", ppw)) return SendMsg(playerid, RED, "*USAGE: /register [password] - Max length is 20 & minium is 3");
if(strlen(ppw) < 3) return SendMsg(playerid, RED, "*Error: Password Is Under The Limit Sorry");
if(strlen(ppw) > 20) return SendMsg(playerid, RED, "*Error: Password Is Over The Limit Sorry");
if(IsLogged[playerid] == 1) return SendMsg(playerid, RED, "*Error: |- You Are Already Logged In -|");
if(!dini_Exists(pfile)) return SendMsg(playerid, RED, "*Error: No account with that username is registered, please register");
if(strcmp(dini_Get(pfile, "Password"), ppw, true) == 1) return SendMsg(playerid, RED, "*Error: Wrong Password. Password Did Not Match With The One You Have Register With.");
format(str, sizeof(str), "*Success: You have Successfully Logged In %s", Playername(playerid), dini_Int(pfile, "AdminLevel"));
SendMsg(playerid, LIME, str);
LoadPlayer(playerid);
IsLogged[playerid] = 1;
SetTimerEx("TimePlayerLogged", 1000, true, "i", playerid);
return 1;
}
CMD:register(playerid, params[])
{
new ppw[20], str[128];
format(pfile, sizeof(pfile), pfile_path, Playername(playerid));
if(sscanf(params, "s", ppw)) return SendMsg(playerid, RED, "*USAGE: /register [password] - Max length is 20 & minium is 3");
else if(strlen(ppw) < 3) return SendMsg(playerid, RED, "*Error: Password Is Under The Limit Sorry");
else if(strlen(ppw) > 20) return SendMsg(playerid, RED, "*Error: Password Is Over The Limit Sorry");
else if(IsLogged[playerid] == 1) return SendMsg(playerid, RED, "*Error: You Are Logged In | No Need To Register Again!");
else if(dini_Exists(pfile)) return SendMsg(playerid, RED, "*Error: This Username Is Already Registered In Our Database Please Login! Or Create A Different Account");
else
{
format(pfile, sizeof(pfile), pfile_path, Playername(playerid));
dini_Create(pfile);
dini_Set(pfile, "Password", ppw);
dini_IntSet(pfile, "Score", 0);
dini_IntSet(pfile, "Money", 0);
dini_IntSet(pfile, "AdminLevel", 0);
dini_IntSet(pfile, "Hourslogged", 0);
dini_IntSet(pfile, "MinutesLogged", 0);
dini_IntSet(pfile, "SecondsLogged", 0);
dini_IntSet(pfile, "WantedLevel", 0);
dini_IntSet(pfile, "DrunkLevel", GetPlayerDrunkLevel(playerid));
dini_IntSet(pfile, "FightStyle", GetPlayerFightingStyle(playerid));
dini_IntSet(pfile,"Weed", 0);
dini_IntSet(pfile,"Seeds", 0);
dini_IntSet(pfile, "Jail", 0);
format(str, sizeof(str), "*Success: You Has Successfully Registered %s And With The Password Of %s", Playername(playerid), ppw);
SendMsg(playerid, GREEN, str);
GivePlayerMoney(playerid,25000);
}
return 1;
}
just trying to help ya for all the times you helped me>.<
Re: Problem in saving Player data using dini. -
DJDhan - 20.07.2010
Well, thanks for that code but I don't see my problem by looking at your code either. I am assuming you call "LoadPlayer(playerid)" under OnPlayerConnect and "SavePlayer(playerid)" under OnPlayerDisconnect. That's what I did before I transfered my code to OnPlayerDisconnect.
Re: Problem in saving Player data using dini. -
Kar - 20.07.2010
i dont call it under onplayerconnect. i call it on /login [password]
I see you must use Auto login?
meh i dont im making a cnr. so no auto login
and my save player is called onplayerdisconnect.
try removing the auto login and test if it works