Good time, I have a question: how to send a message to all except a certain player, for example, Steve?
This might help, it might wrong tho PHP: $list = $this->getServer()->getOnlinePlayers();$name = "Steve";if($list[$name]->getName() == "Steve") { //sorry i have to get player object with name Steve and get it name, then compare with Steve :P return false; } else { $list->sendMessage("Bla?"); }
Better this: PHP: foreach($this->getServer()->getOnlinePlayers() as $p) if($p->getName() !== "Steve") $p->sendMessage("Hello!");
He can does because it's an players array but he can't do $list[$name] because $name is a string not an integer index.
Please explain to me how this should work. PHP: $this->getServer()->getOnlinePlayers()->sendMessage("Doesn't work."); Code: [Server thread/CRITICAL]: Error: "Call to a member function sendMessage() on array" (EXCEPTION)
PHP: function broadcastMessage($players, string $message, Player $except = null) { $players = $players instanceof Player ? [$players] : $players; foreach($players as $player) { if($player !== $except) $player->sendMessage($message); }}