Solved Play sound to player?

Discussion in 'Development' started by Moonafic, Jan 13, 2021.

  1. Moonafic

    Moonafic Silverfish

    Messages:
    18
    Im trying to play sound to player with LevelSoundEventPacket but the sound stays on given position so when i leave him i cant hear it. Is there a way to play sound to player but not to position?
     
  2. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    170
    GitHub:
    ethaniccc
    If you want to broadcast a sound to all online players, just foreach Server->getOnlinePlayers() and make a LevelSoundEventPacket for each with their current position
     
  3. RicardoMilos384

    RicardoMilos384 Slime

    Messages:
    81
    GitHub:
    ricardomilos384
    you gan also do like this

    PHP:
    use pocketmine\network\protocol\mcpe\PlayerSoundPacket;

    $pk PlaySoundPacket;
    $pk->soundName "random.pop"// string
    $pk->volume 1// numeric
    $pk->pitch 1// numeric
    $pk->$player->x
    $pk->$player->y;
    $pk->$player->z;
    $player->dataPacket($pk); // send sound only to one player

    sound list can be found here
    https://www.digminecraft.com/lists/sound_list_pe.php
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    513
    You can set $pk->disableRelativeVolume to true then anyone who receive the packet will hear it at full volume regardless of position
     
    ethaniccc and Moonafic like this.
  5. Moonafic

    Moonafic Silverfish

    Messages:
    18
    ok dude wow i think im blind, anyways much thanks for help, thats what i need
     
  6. Doxestic

    Doxestic Spider Jockey

    Messages:
    39
    omg i searched for this list for about 1 month thanks xD
     
  7. Moonafic

    Moonafic Silverfish

    Messages:
    18
    nah thats not helping. im trying to make ambients for server and they are 50 secs long but when you play sound to player with any method the sound stays on given coords and if you go far from it you wont hear it anymore :(
     
  8. Doxestic

    Doxestic Spider Jockey

    Messages:
    39
    you should send data packet for all of players with there own coord like this:
    PHP:
    use pocketmine\network\protocol\mcpe\PlayerSoundPacket;

    foreach(
    $this->getServer()->getOnlinePlayers() as $player){
    $pk PlaySoundPacket;
    $pk->soundName "random.pop"// string
    $pk->volume 1// numeric
    $pk->pitch 1// numeric
    $pk->$player->x;
    $pk->$player->y;
    $pk->$player->z;
    $player->dataPacket($pk);
    }
     
  9. Moonafic

    Moonafic Silverfish

    Messages:
    18
    the problem is that sound plays on given coords
     

Share This Page

  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.