How to make a command...

Discussion in 'Development' started by Mespeczek, Jun 25, 2018.

  1. Mespeczek

    Mespeczek Silverfish

    Messages:
    16
    GitHub:
    Igomisz123
    Hello!

    How to make a command to check how many players played together on the server

    I kown how to create a command, but I don't know how to check the number of all players, even offline.
     
  2. Muqsit

    Muqsit Chicken Verified

    Messages:
    1,507
    GitHub:
    muqsit
    If you have only player data files in your players folder, you can count the number of files in your players folder.
    PHP:
    /** @var Server $server */
    $total_players count(scandir($server->getDataPath() . "players/"));
     
  3. Michael Haufe

    Michael Haufe Silverfish

    Messages:
    16
    Will not work! Added this to Broadcaster with:

    "ALLPLAYERS" => count(scandir($server->getDataPath() . "players/"));

    And error is:

    ParseError: "syntax error, unexpected '"ALLPLAYERS"' (T_CONSTANT_ENCAPSED_STRING), expecting ')'" (EXCEPTION) in "Broadcaster-master/src/Broadcaster/Broadcaster" at line 190
     
  4. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    PHP:
    "ALLPLAYERS" => count(scandir($server->getDataPath() . "players/");
    should work
     
  5. Michael Haufe

    Michael Haufe Silverfish

    Messages:
    16
    ErrorException: "count(): Parameter must be an array or an object that implements Countable" (EXCEPTION) in "Broadcaster-master/src/Broadcaster/Broadcaster" at line 190

    Code:

    Code:
    public function formatMessage($message){
            return $this->replaceVars($message, array(
                "MAXPLAYERS" => $this->getServer()->getMaxPlayers(),
                "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()),
                "PREFIX" => $this->cfg["prefix"],
                "SUFFIX" => $this->cfg["suffix"],
                "TIME" => date($this->cfg["datetime-format"]),
                "ALLPLAYERS" => count($this->getServer()->getDataPath() . "players/")
            ));
        }
     
  6. Muqsit

    Muqsit Chicken Verified

    Messages:
    1,507
    GitHub:
    muqsit
    :facepalm: that's an issue with your code, not my snippet.
    I didn't mention "ALLPLAYERS" anywhere in my code.

    Anyway, this is not the code I provided:
    Check again.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.