Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Send sound

Comments in 'Plugin Development' started by CaptainKenji17, Feb 10, 2016.

  1. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    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
    Last edited: Feb 10, 2016
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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.
    Vaivez66 likes this.
  3. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    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();
    Last edited: Feb 10, 2016
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1. There is a function that returns all players in a level called Level::getPlayers().
    2. The default value for the second argument to addSound is to send to nearby players.
    3. If the above are not enough, I can only tell you to learn PHP.
    Last edited: Feb 10, 2016
    TutoGamerWalid likes this.
  5. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    What is it

    it is not, it does send a sound to only 1 player not even nearby
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  7. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    How to use the Level::getPlayers in this code?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I already told you:
    1. 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.
    2. If you do not even know what a parameter is, I don't have much to tell you except "Learn PHP".
    3. This is PocketMine Forums, not PHP Forums. Please do not ask PHP questions here.
    4. 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)
    Vaivez66 likes this.
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    You can try it with foreach
  10. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Still need my help?
  11. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I'm currently programming this as of the request in the plugin request section (check there)
  12. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    yes ive learned nothing from these peeps all i need is a replace code to let this plugin work​
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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.
    Hittmana likes this.
  14. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    PHP:
    $sound = new Popsound($player);

    $player->getLevel()->addSound($sound);
  15. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    He Want To Add IN All Players

    PHP:
    foreach($this->getServer()->getOnlinePlayers() as $p){
    $p->getLevel()->addSound(new PopSound($p), array($p));
    }

Share This Page

Advertisement