PHP: public function onChat(PlayerChatEvent $event){ if($event instanceof PlayerChatEvent){ $player = $event->getPlayer(); $player->getLevel()->addSound(new PopSound($player), [$player]); } } I want to send a sound to all players when someone talks, but on this way i think itll send a sound to the player who talks only
You don't need to check the instanceof. The parameter type hint already asserts that. And to your question: do you know what this line means? If you do, you won't be asking this. PHP: $player->getLevel()->addSound(new PopSound($player), [$player]); And if you don't, please, before copying any code, understand it first.
that code is hit and i removed instanceof and instead of that code i wanna send the sound to everybody privately only they can hear itll not mix the sounds all i need is a function that calls all player, i wish there was getAllPlayer();
There is a function that returns all players in a level called Level::getPlayers(). The default value for the second argument to addSound is to send to nearby players. If the above are not enough, I can only tell you to learn PHP.
1. Check edited post. 2. It does. What is this? https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/level/Level.php#L456
I already told you: The default value of the second parameter to Level::addSound() would be to send the sound to all players that use that chunk, which suits your purpose. If you do not even know what a parameter is, I don't have much to tell you except "Learn PHP". This is PocketMine Forums, not PHP Forums. Please do not ask PHP questions here. This is not code writing service. We are here to discuss about PocketMine API. We are not here to discuss tiny things. (But sadly, most people here do not have a macroscopic view on plugins at all)
And we have already discussed that sufficiently here. As I already mentioned, you don't need a player parameter at all, because the default value would be to broadcast it. Simply pass nothing.
He Want To Add IN All Players PHP: foreach($this->getServer()->getOnlinePlayers() as $p){$p->getLevel()->addSound(new PopSound($p), array($p));}