05.06.2011, 21:08
Hi guys,is possibile to save in a file a record of max players online and reading it in the server with a command?How?
stock GetPlayerRecord()
{
new File:file = fopen("playerrecord.txt"); // Open a file
new string[8];
fread(file, string); // Read the content of the file
fclose(file); // Dont forget to close the file
return strval(string); // convert it to an integer and return the value
}
stock GetOnlinePlayers()
{
new count;
// Count all connected players
for (new i = 0; i < MAX_PLAYERS; i ++) count += IsPlayerConnected(i);
return count;
}
stock UpdatePlayerRecord()
{
// Check if there is a new player record
new onlines = GetOnlinePlayers();
if (onlines <= GetPlayerRecord()) return;
new File:file = fopen("playerrecord.txt");
new string[8];
format(string, 8, "%d", onlines); // convert the playercount to a string
fwrite(file, string); // And put it in the file
fclose(file);
}
// In OnPlayerConnect:
// Checks for a new player record every time a player joins
UpdatePlayerRecord();