PHP: public function onRun($currentTick){ $players = $this->plugin->getServer()->getLevelByName("GDHub")->getPlayers();Foreach($players as $array){Echo(count($players)); if (count($players) >= 1) {Echo('test 1'); $this->tts--; $this->plugin->getServer ()->broadcastPopup($this->plugin->gameprefix . C::GREEN . "Starting in" . $this->tts, $array); if ($this->tts == 0) {Echo('test 2'); $this->plugin->getServer()->broadcastMessage($this->gameprefix . "Test"); } } } }} Try this
When i change PHP: if(count($pl) > 1) { to PHP: if(count($pl) > 0) { it work and start timer with 0 players in world but if it is PHP: if(count($pl) > 1) { and i join arena it doesnt start.. It start when join 2nd player or why it dont work???
Learn how logic operators work in PHP. PHP: // Check if there is at least one player in the worldif(count($pl) >= 1) { // do stuff} You should already know PHP before you start writing PocketMine plugins, or you'll be stuck here with stupid issues like this until you finally decide to learn PHP.
Why it doesnt work with count($pl) >= 5 ?? It is god or no?? PHP: <?phpnamespace GetDown;use pocketmine\Player;use pocketmine\Server;use pocketmine\scheduler\PluginTask;use pocketmine\utils\Config;use pocketmine\utils\TextFormat;use pocketmine\utils\TextFormat as C;use GetDown\Main;use pocketmine\math\Vector3;use pocketmine\plugin\Plugin;class Timer extends PluginTask{ private $plugin; public $tts; public function __construct(Main $plugin) { $this->plugin = $plugin; $this->tts = 30; parent::__construct($plugin); } /** * @param $currentTick */ public function onRun($currentTick) { foreach ($this->plugin->getServer()->getLevelByName("GDHub")->getPlayers() as $pl) { if (count($pl)>=5) { $this->tts--; //$pl->setExpLevel($pl->getExpLevel() - 1); $pl->sendPopup($this->tts); if ($this->tts == 0) { $this->plugin->getServer()->getScheduler()->cancelTask($this->getTaskId()); $pl->sendMessage($this->plugin->gameprefix . C::GREEN . "Game started!"); $this->plugin->changePhase(2); $pl->teleport(new Vector3(1, 1, 1, "gd1")); $this->plugin->getServer()->getScheduler()->cancelTask($this->getTaskId()); } } } }}
count can be used only when the array PHP: <?phpnamespace GetDown;use pocketmine\Player;use pocketmine\Server;use pocketmine\scheduler\PluginTask;use pocketmine\utils\Config;use pocketmine\utils\TextFormat;use pocketmine\utils\TextFormat as C;use GetDown\Main;use pocketmine\math\Vector3;use pocketmine\plugin\Plugin;class Timer extends PluginTask{ private $plugin; public $tts; public function __construct(Main $plugin) { $this->plugin = $plugin; $this->tts = 30; parent::__construct($plugin); } /** * @param $currentTick */ public function onRun($currentTick) { $p = $this->plugin->getServer()->getLevelByName("GDHub")->getPlayers(); if(count($p)>=5) { foreach($p as $pl) { $this->tts--; //$pl->setExpLevel($pl->getExpLevel() - 1); $pl->sendPopup($this->tts); if ($this->tts == 0) { $this->plugin->getServer()->getScheduler()->cancelTask($this->getTaskId()); $pl->sendMessage($this->plugin->gameprefix . C::GREEN . "Game started!"); $this->plugin->changePhase(2); $pl->teleport(new Vector3(1, 1, 1, "gd1")); $this->plugin->getServer()->getScheduler()->cancelTask($this->getTaskId()); } } } }}