Hello, I'm making a game and I'm just a little confused onQuit event. What I'm trying to do is if a player quits the game it will message each player in the game saying '$player left the game. ($count/24)' With the code I have I'm getting this when the player joins and quits: '$player joined the game. (2/24)' '$player left the game. (2/24)' See the problem? because the player is still in the world when the message is sent its still counted as 2 when it should be 1. so I need to know how to subtract 1 from the count. this is what I have in QuitEvent: PHP: public function onQuit(PlayerQuitEvent $event) { $player = $event->getPlayer(); $level = $this->getServer()->getLevelByName($this->currentLevel); $levelArena = $level; $playersArena = $levelArena->getPlayers(); $gamecount = count($this->getServer()->getLevelByName($this->currentLevel)->getPlayers(-1)); foreach($playersArena as $pl) $pl->sendMessage(TextFormat::YELLOW . $player->getNameTag() . TextFormat::YELLOW . " left the game. (" . TextFormat::AQUA . $gamecount . TextFormat::RESET . TextFormat::AQUA . "/24" . TextFormat::YELLOW . ")"); }}
Replace PHP: $gamecount = count($this->getServer()->getLevelByName($this->currentLevel)->getPlayers(-1)); with PHP: $gamecount = count($this->getServer()->getLevelByName($this->currentLevel)->getPlayers()) -1;