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

What is the function to play a sound to the player?

Comments in 'Plugin Development' started by Calrizer, Jun 9, 2015.

  1. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Hi again,

    Sorry to be a bother again today but I was just wondering how to play a sound to the player.

    Any response is appreciated :)

    -Calrizer
  2. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    A little something like this.
    PHP:
    $player->getLevel()->addSound(new LaunchSound($player), $player->getViewers());
    Calrizer likes this.
  3. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    So 'LaunchSound' is the name of the sound.
    Is there a list where I can see all the sounds? I had a look at the documentation and couldn't find anything.
    Tethered_ and Angelo Vidrio like this.
  4. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    Here and Here
    Angelo Vidrio, Calrizer and xiaoq like this.
  5. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    It's weird, I've got no errors but it's not playing the sound. Any other ideas??
  6. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Use a different sound maybe
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why is it $player->getViewers()? The second parameter should be the players to send the sound to.
    If you want to use the default (near players), pass null instead or simply skip that value.
  8. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Yeah @PEMapModder is correct, just drop the second parameter and it works.

Share This Page

Advertisement