01.09.2011, 23:59
I am currently making a custom roleplay script. For saving I made a custom system like thing. I am just wonder is this faster then all the other file saving methods.
Saving The Player
Loading The Player
Saving The Player
pawn Код:
stock SavePlayer(playerid)
{
if(fexist(PlayerInfo[playerid][File])) fremove(PlayerInfo[playerid][File]);
new line[256], File:file;
file = fopen(PlayerInfo[playerid][File], io_append);
format(line, 256, "Password %s\n", PlayerInfo[playerid][Password]); fwrite(file, line);
format(line, 256, "AdminLevel %i\n", PlayerInfo[playerid][AdminLevel]); fwrite(file, line);
format(line, 256, "SkinID %i\n", PlayerInfo[playerid][SkinID]); fwrite(file, line);
format(line, 256, "Money %i\n", PlayerInfo[playerid][Money]); fwrite(file, line);
format(line, 256, "Banned %i\n", PlayerInfo[playerid][Banned]); fwrite(file, line);
format(line, 256, "BanReason %s\n", PlayerInfo[playerid][BanReason]); fwrite(file, line);
format(line, 256, "Veh1 %i\n", PlayerInfo[playerid][Veh1]); fwrite(file, line);
format(line, 256, "Veh2 %i\n", PlayerInfo[playerid][Veh2]); fwrite(file, line);
format(line, 256, "Veh3 %i\n", PlayerInfo[playerid][Veh3]); fwrite(file, line);
format(line, 256, "Faction %i\n", PlayerInfo[playerid][Faction]); fwrite(file, line);
format(line, 256, "FactionRank %i\n", PlayerInfo[playerid][FactionRank]); fwrite(file, line);
format(line, 256, "Jail %i\n", PlayerInfo[playerid][Jail]); fwrite(file, line);
format(line, 256, "JailTime %i\n", PlayerInfo[playerid][JailTime]); fwrite(file, line);
format(line, 256, "JailSlot %i\n", PlayerInfo[playerid][JailSlot]); fwrite(file, line);
format(line, 256, "House %i", PlayerInfo[playerid][House]); fwrite(file, line);
fclose(file);
}
pawn Код:
stock LoadPlayer(playerid)
{
new line[256], varible[256], value[256];
new File:file = fopen(PlayerInfo[playerid][File], io_read);
while(fread(file, line))
{
if(sscanf(line, "s[256]s[256]", varible, value) == 0)
{
if(strcmp(varible, "Password", true) == 0) format(PlayerInfo[playerid][Password], 32, "%s", value);
else if(strcmp(varible, "AdminLevel", true) == 0) PlayerInfo[playerid][AdminLevel] = strval(value);
else if(strcmp(varible, "SkinID", true) == 0) PlayerInfo[playerid][SkinID] = strval(value);
else if(strcmp(varible, "Money", true) == 0) PlayerInfo[playerid][Money] = strval(value);
else if(strcmp(varible, "Banned", true) == 0) PlayerInfo[playerid][Banned] = strval(value);
else if(strcmp(varible, "BanReason", true) == 0) format(PlayerInfo[playerid][BanReason], 32, "%s", value);
else if(strcmp(varible, "Veh1", true) == 0) PlayerInfo[playerid][Veh1] = strval(value);
else if(strcmp(varible, "Veh2", true) == 0) PlayerInfo[playerid][Veh2] = strval(value);
else if(strcmp(varible, "Veh3", true) == 0) PlayerInfo[playerid][Veh3] = strval(value);
else if(strcmp(varible, "Faction", true) == 0) PlayerInfo[playerid][Faction] = strval(value);
else if(strcmp(varible, "FactionRank", true) == 0) PlayerInfo[playerid][FactionRank] = strval(value);
else if(strcmp(varible, "Jail", true) == 0) PlayerInfo[playerid][Jail] = strval(value);
else if(strcmp(varible, "JailTime", true) == 0) PlayerInfo[playerid][JailTime] = strval(value);
else if(strcmp(varible, "JailSlot", true) == 0) PlayerInfo[playerid][JailSlot] = strval(value);
else if(strcmp(varible, "House", true) == 0) PlayerInfo[playerid][House] = strval(value);
}
}
fclose(file);
}