1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved How to add sound to a plugin

Discussion in 'Development' started by PixelzChris, Apr 12, 2018.

  1. PixelzChris

    PixelzChris Silverfish

    Messages:
    17
    I'm not sure I think i need this:
    ```$level = $this->getServer()->getLevelByName("world"); //test world
    $player = $this->getServer()->getPlayer(); //get player
    $sound = "pocketmine\\level\\sound\\"."AnvilSound";
    $level->addSound(new $sound($player));
    ```
    BUT I need to find the class (if its anything wrong tell me how to add sound + class
     
  2. RyanShaw

    RyanShaw Witch

    Messages:
    69
    Adding sound is pretty simple, if you wanted to do it by event, this'll do. If not you can easily take what ive shown you to make your code work.
    PHP:
    use pocketmine\level\sound\AnvilUseSound;
    use 
    pocketmine\math\Vector3;

    $level $event->getPlayer()->getLevel();
    $x $event->getPlayer()->getX();
    $y $event->getPlayer()->getY();
    $z $event->getPlayer()->getZ();
    $pos = new Vector3($x$y$z);
    $level->addSound(new AnvilUseSound($pos));
     
     
    Last edited: Apr 13, 2018
  3. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    addsound can send sound but, why don’t you use LevelSoundEventPacket?
    you can send plenty of sounds.

    Example code
    PHP:
    use pocketmine\math\Vector3;
    use 
    pocketmine\network\mcpe\protocol\LevelSoundEventPacket;

    $this->getServer()->getLevelByName(“worldName”)->broadcastLevelSoundEvent(new Vector3(X,Y,Z), LevelSoundEventPacket::SOUND_BOW_HIT);
    //you can find sound name in LevelSoundEventPacket.php
    //about 160 sounds are defined
     
    Last edited: Apr 13, 2018
    PixelzChris, RyanShaw and OnTheVerge like this.
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    please do not abuse polls
    polls are for when you want to know something that is better tallied in numbers
     
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Class:
    PHP:
    use pocketmine\level\sound\FizzSound;
    use 
    pocketmine\math\Vector3;
    Code:
    PHP:
    $player->getLevel()->addSound(new FizzSound(new Vector3($player->getX(), $player->getY(), $player->getZ())));
     
  6. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    Packets are cumbersome to deal with when specifications are changed,
    but you can alleviate them by using pmmp functions, classes.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.