27.12.2012, 19:04
ok i made a filterscript and i want to create a file to store the information each time a player logs off and when he spawns if the file exists already load it up, is there anything wrong with this ?
pawn Код:
#define PATH "/Users/%s.ini"
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"PlayerData");
INI_WriteInt(File,"LSPDRank",PlayerData[playerid][LSPDRank]);
INI_WriteInt(File,"FBIRank",PlayerData[playerid][FBIRank]);
INI_WriteInt(File,"Cells",Cell[playerid]);
INI_WriteInt(File,"FPrison",FPrison[playerid]);
INI_WriteInt(File,"Jailed",Jailed[playerid]);
INI_WriteInt(File,"Jailed2",Jailed2[playerid]);
INI_WriteInt(File,"FBIJailed",FBIJailed[playerid]);
INI_WriteInt(File,"FBIJailed2",FBIJailed2[playerid]);
INI_WriteInt(File,"Wanted",PlayerData[playerid][Wanted]);
INI_WriteInt(File,"Minutes",countn[playerid]);
INI_WriteInt(File,"time",timeleft[playerid]);
INI_Close(File);
return 1;
}
public OnPlayerSpawn(playerid)
{
new pFile[128];
new name[24];
GetPlayerName(playerid,name,sizeof name);
format(pFile,sizeof pFile,"/Users/%s.ini",name);
if(fexist(pFile))
{
INI_ParseFile(pFile, "LoadUser_data", .bExtra = true, .extra = playerid);
}
else
{
fcreate(pFile);
}
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;
}
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("LSPDRank",PlayerData[playerid][LSPDRank]);
INI_Int("FBIRank",PlayerData[playerid][FBIRank]);
INI_Int("Cells",Cell[playerid]);
INI_Int("FPrison",FPrison[playerid]);
INI_Int("Jailed",Jailed[playerid]);
INI_Int("Jailed2",Jailed2[playerid]);
INI_Int("FBIJailed",FBIJailed[playerid]);
INI_Int("FBIJailed2",FBIJailed2[playerid]);
INI_Int("Wanted",PlayerData[playerid][Wanted]);
INI_Int("Minutes",countn[playerid]);
INI_Int("time",timeleft[playerid]);
return 1;
}
stock fcreate(filename[])
{
if (fexist(filename)){return false;}
new File:fhandle = fopen(filename,io_write);
fclose(fhandle);
return true;
}