Record of max players online
#1

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?
Reply
#2

pawn Код:
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();
Untested, but should work except for typos
The code should be quite self-explaining, but feel free to ask if you got a question.
Reply
#3

You rock! Thanks very much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)