Not all online players get item, only 1 random people get it. Is it because i use the mt_rand function? PHP: foreach(Server::getInstance()->getOnlinePlayers() as $online) {if(mt_rand(1, 100) === 1){ $money = 50000; EconomyAPI::getInstance()->addMoney($online, $money); $online->sendMessage(TF::GRAY . " You received " . TF::YELLOW . "Easy money boo"); } }
Code: if(mt_rand(1, 100) == 1){ foreach(Server::getInstance()->getOnlinePlayers() as $online) { $money = 50000; EconomyAPI::getInstance()->addMoney($online, $money); $online->sendMessage(TF::GRAY . " You received " . TF::YELLOW . "Easy money boo"); } }
That’s a very inefficient method of choosing a random player. Also, don’t call the server instance like that. Do it through your plugin, since it extends plugin base. Anyways, here’s what you’re wanting: PHP: // This is choosing random player$player = $this->getServer()->getOnlinePlayers()[array_rand($this->getServer()->getOnlinePlayers())] Now do what ever you want with the player object.
Sorry for my miscommunication but what i meant is "not all online players get the money" what i want is for all online players to get the money
PHP: foreach($this->getServer()->getOnlinePlayers() as $players){$players->sendMessage("You got money");$this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->addMoney($players, 5000);