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

Sounds

Discussion in 'Development' started by LucGamesDE, May 21, 2017.

  1. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    How can I play sounds by their id?
     
  2. Jonas

    Jonas Baby Zombie

    Messages:
    192
    PHP:
    $player->getLevel()->addSound(new \pocketmine\level\sound\AnvilFallSound($player));
     
  3. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    Please read my question carefully before answering...
     
  4. Michael

    Michael Baby Zombie

    Messages:
    113
    GitHub:
    michaelm04
    The parameters for addSound() are:
    \pocketmine\level addSound(Sound $sound, array $players = null).

    So construct the sound with the id you want through \pocketmine\level\sound\GenericSound __construct(Vector3 $pos, $id, $pitch = 0)

    PHP:
    /** So all together now */
    $player //Player instance from somewhere
    $sound = new GenericSound($player1002/*id of your choice*/0/*Pitch if needed*/);
    /** optional array of players */
    $player->getLevel()->addSound($sound$player->getLevel()->getPlayers());
     
    jasonwynn10 and LucGamesDE like this.
  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.