problem with load player stats -
nton - 01.08.2012
hi i create this system but when close server and open when player conect weapons not load
where is my wrong ?
PHP код:
#define PATH "/Users/%s.ini"
PHP код:
enum pInfo
{
pPass,
pCash,
pAdmin,
pKills,
pDeaths,
pScore,
pW1,
pWam1,
pW2,
pWam2,
pW3,
pWam3,
pW4,
pWam4,
pW5,
pWam5,
pW6,
pWam6,
pW7,
pWam7,
pW8,
pWam8
}
PHP код:
new PlayerInfo[MAX_PLAYERS][pInfo];
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("Score",PlayerInfo[playerid][pScore]);
INI_Int("WEAPON 1",PlayerInfo[playerid][pW1]);
INI_Int("WEAPON AMMU 1",PlayerInfo[playerid][pWam1]);
INI_Int("WEAPON 2",PlayerInfo[playerid][pW2]);
INI_Int("WEAPON AMMU 2",PlayerInfo[playerid][pWam2]);
INI_Int("WEAPON 3",PlayerInfo[playerid][pW3]);
INI_Int("WEAPON AMMU 3",PlayerInfo[playerid][pWam3]);
INI_Int("WEAPON 4",PlayerInfo[playerid][pW4]);
INI_Int("WEAPON AMMU 4",PlayerInfo[playerid][pWam4]);
INI_Int("WEAPON 5",PlayerInfo[playerid][pW5]);
INI_Int("WEAPON AMMU 5",PlayerInfo[playerid][pWam5]);
INI_Int("WEAPON 6",PlayerInfo[playerid][pW6]);
INI_Int("WEAPON AMMU 6",PlayerInfo[playerid][pWam6]);
INI_Int("WEAPON 7",PlayerInfo[playerid][pW7]);
INI_Int("WEAPON AMMU 7",PlayerInfo[playerid][pWam7]);
INI_Int("WEAPON 8",PlayerInfo[playerid][pW8]);
INI_Int("WEAPON AMMU 8",PlayerInfo[playerid][pWam8]);
return 1;
}
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PATH,playername);
return string;
}
stock udb_hash(buf[]) {
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
PHP код:
public OnPlayerDisconnect(playerid, reason)
{
GetPlayerWeaponData(playerid,1,PlayerInfo[playerid][pW1],PlayerInfo[playerid][pWam1]);
GetPlayerWeaponData(playerid,2,PlayerInfo[playerid][pW2],PlayerInfo[playerid][pWam2]);
GetPlayerWeaponData(playerid,3,PlayerInfo[playerid][pW3],PlayerInfo[playerid][pWam3]);
GetPlayerWeaponData(playerid,4,PlayerInfo[playerid][pW4],PlayerInfo[playerid][pWam4]);
GetPlayerWeaponData(playerid,5,PlayerInfo[playerid][pW5],PlayerInfo[playerid][pWam5]);
GetPlayerWeaponData(playerid,6,PlayerInfo[playerid][pW6],PlayerInfo[playerid][pWam6]);
GetPlayerWeaponData(playerid,7,PlayerInfo[playerid][pW7],PlayerInfo[playerid][pWam7]);
GetPlayerWeaponData(playerid,8,PlayerInfo[playerid][pW8],PlayerInfo[playerid][pWam8]);
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,"Score", GetPlayerScore(playerid));
INI_WriteInt(File,"WEAPON1",PlayerInfo[playerid][pW1]);
INI_WriteInt(File,"WEAPONAMMU1",PlayerInfo[playerid][pWam1]);
INI_WriteInt(File,"WEAPON2",PlayerInfo[playerid][pW2]);
INI_WriteInt(File,"WEAPONAMMU2",PlayerInfo[playerid][pWam2]);
INI_WriteInt(File,"WEAPON3",PlayerInfo[playerid][pW3]);
INI_WriteInt(File,"WEAPONAMMU3",PlayerInfo[playerid][pWam3]);
INI_WriteInt(File,"WEAPON4",PlayerInfo[playerid][pW4]);
INI_WriteInt(File,"WEAPONAMMU4",PlayerInfo[playerid][pWam4]);
INI_WriteInt(File,"WEAPON5",PlayerInfo[playerid][pW5]);
INI_WriteInt(File,"WEAPONAMMU5",PlayerInfo[playerid][pWam5]);
INI_WriteInt(File,"WEAPON6",PlayerInfo[playerid][pW6]);
INI_WriteInt(File,"WEAPONAMMU6",PlayerInfo[playerid][pWam6]);
INI_WriteInt(File,"WEAPON7",PlayerInfo[playerid][pW7]);
INI_WriteInt(File,"WEAPONAMMU7",PlayerInfo[playerid][pWam7]);
INI_WriteInt(File,"WEAPON8",PlayerInfo[playerid][pW8]);
INI_WriteInt(File,"WEAPONAMMU8",PlayerInfo[playerid][pWam8]);
INI_Close(File);
}
PHP код:
public OnPlayerDeath(playerid, killerid, reason)
{
GetPlayerWeaponData(playerid,1,PlayerInfo[playerid][pW1],PlayerInfo[playerid][pWam1]);
GetPlayerWeaponData(playerid,2,PlayerInfo[playerid][pW2],PlayerInfo[playerid][pWam2]);
GetPlayerWeaponData(playerid,3,PlayerInfo[playerid][pW3],PlayerInfo[playerid][pWam3]);
GetPlayerWeaponData(playerid,4,PlayerInfo[playerid][pW4],PlayerInfo[playerid][pWam4]);
GetPlayerWeaponData(playerid,5,PlayerInfo[playerid][pW5],PlayerInfo[playerid][pWam5]);
GetPlayerWeaponData(playerid,6,PlayerInfo[playerid][pW6],PlayerInfo[playerid][pWam6]);
GetPlayerWeaponData(playerid,7,PlayerInfo[playerid][pW7],PlayerInfo[playerid][pWam7]);
GetPlayerWeaponData(playerid,8,PlayerInfo[playerid][pW8],PlayerInfo[playerid][pWam8]);
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,"Score", GetPlayerScore(playerid));
INI_WriteInt(File,"WEAPON1",PlayerInfo[playerid][pW1]);
INI_WriteInt(File,"WEAPONAMMU1",PlayerInfo[playerid][pWam1]);
INI_WriteInt(File,"WEAPON2",PlayerInfo[playerid][pW2]);
INI_WriteInt(File,"WEAPONAMMU2",PlayerInfo[playerid][pWam2]);
INI_WriteInt(File,"WEAPON3",PlayerInfo[playerid][pW3]);
INI_WriteInt(File,"WEAPONAMMU3",PlayerInfo[playerid][pWam3]);
INI_WriteInt(File,"WEAPON4",PlayerInfo[playerid][pW4]);
INI_WriteInt(File,"WEAPONAMMU4",PlayerInfo[playerid][pWam4]);
INI_WriteInt(File,"WEAPON5",PlayerInfo[playerid][pW5]);
INI_WriteInt(File,"WEAPONAMMU5",PlayerInfo[playerid][pWam5]);
INI_WriteInt(File,"WEAPON6",PlayerInfo[playerid][pW6]);
INI_WriteInt(File,"WEAPONAMMU6",PlayerInfo[playerid][pWam6]);
INI_WriteInt(File,"WEAPON7",PlayerInfo[playerid][pW7]);
INI_WriteInt(File,"WEAPONAMMU7",PlayerInfo[playerid][pWam7]);
INI_WriteInt(File,"WEAPON8",PlayerInfo[playerid][pW8]);
INI_WriteInt(File,"WEAPONAMMU8",PlayerInfo[playerid][pWam8]);
INI_Close(File);
}
PHP код:
public OnPlayerSpawn(playerid)
{
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW1],PlayerInfo[playerid][pWam1]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW2],PlayerInfo[playerid][pWam2]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW3],PlayerInfo[playerid][pWam3]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW4],PlayerInfo[playerid][pWam4]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW5],PlayerInfo[playerid][pWam5]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW6],PlayerInfo[playerid][pWam6]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW7],PlayerInfo[playerid][pWam7]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW8],PlayerInfo[playerid][pWam8]);
return 1;
}
Re: problem with load player stats -
Misiur - 01.08.2012
You are calling weapons loader in OnPlayerDisconnect instead of spawn/connect
Re: problem with load player stats -
nton - 01.08.2012
I correct
Re: problem with load player stats -
Misiur - 01.08.2012
Where do you load the data? In OnPlayerConnect? This is the part I need to help you. Also I suggest moving saving data to separate function like:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
SavePlayerData(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
SavePlayerData(playerid);
return 1;
}
stock SavePlayerData(playerid) {
GetPlayerWeaponData(playerid,1,PlayerInfo[playerid][pW1],PlayerInfo[playerid][pWam1]);
GetPlayerWeaponData(playerid,2,PlayerInfo[playerid][pW2],PlayerInfo[playerid][pWam2]);
GetPlayerWeaponData(playerid,3,PlayerInfo[playerid][pW3],PlayerInfo[playerid][pWam3]);
GetPlayerWeaponData(playerid,4,PlayerInfo[playerid][pW4],PlayerInfo[playerid][pWam4]);
GetPlayerWeaponData(playerid,5,PlayerInfo[playerid][pW5],PlayerInfo[playerid][pWam5]);
GetPlayerWeaponData(playerid,6,PlayerInfo[playerid][pW6],PlayerInfo[playerid][pWam6]);
GetPlayerWeaponData(playerid,7,PlayerInfo[playerid][pW7],PlayerInfo[playerid][pWam7]);
GetPlayerWeaponData(playerid,8,PlayerInfo[playerid][pW8],PlayerInfo[playerid][pWam8]);
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,"Score", GetPlayerScore(playerid));
INI_WriteInt(File,"WEAPON1",PlayerInfo[playerid][pW1]);
INI_WriteInt(File,"WEAPONAMMU1",PlayerInfo[playerid][pWam1]);
INI_WriteInt(File,"WEAPON2",PlayerInfo[playerid][pW2]);
INI_WriteInt(File,"WEAPONAMMU2",PlayerInfo[playerid][pWam2]);
INI_WriteInt(File,"WEAPON3",PlayerInfo[playerid][pW3]);
INI_WriteInt(File,"WEAPONAMMU3",PlayerInfo[playerid][pWam3]);
INI_WriteInt(File,"WEAPON4",PlayerInfo[playerid][pW4]);
INI_WriteInt(File,"WEAPONAMMU4",PlayerInfo[playerid][pWam4]);
INI_WriteInt(File,"WEAPON5",PlayerInfo[playerid][pW5]);
INI_WriteInt(File,"WEAPONAMMU5",PlayerInfo[playerid][pWam5]);
INI_WriteInt(File,"WEAPON6",PlayerInfo[playerid][pW6]);
INI_WriteInt(File,"WEAPONAMMU6",PlayerInfo[playerid][pWam6]);
INI_WriteInt(File,"WEAPON7",PlayerInfo[playerid][pW7]);
INI_WriteInt(File,"WEAPONAMMU7",PlayerInfo[playerid][pWam7]);
INI_WriteInt(File,"WEAPON8",PlayerInfo[playerid][pW8]);
INI_WriteInt(File,"WEAPONAMMU8",PlayerInfo[playerid][pWam8]);
INI_Close(File);
}
Re: problem with load player stats -
nton - 01.08.2012
Ι did but did not work when the player spawn he have this weapon
AddPlayerClass(0, 2124.2084960938, -2548.5417480469, 18.233121871948, 269.1425, 28, 50, -1, -1, -1, -1);
Re: problem with load player stats -
Misiur - 01.08.2012
Listen, if you don't show me your OnPlayerConnect part I won't be able to help you. Also -1 is not a valid argument, use
pawn Код:
AddPlayerClass(0, 2124.2084960938, -2548.5417480469, 18.233121871948, 269.1425, 0, 0, 0, 0, 0, 0);
Re: problem with load player stats -
nton - 01.08.2012
i tried but nothing
Re: problem with load player stats -
nton - 01.08.2012
I made it myself :}
thanks for help