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

Solved Play sound to player?

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

  1. Moonafic

    Moonafic Silverfish

    Messages:
    24
    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:
    189
    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:
    82
    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:
    535
    GitHub:
    diamond-gold
    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:
    24
    ok dude wow i think im blind, anyways much thanks for help, thats what i need
     
  6. Doxestic

    Doxestic Spider Jockey

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

    Moonafic Silverfish

    Messages:
    24
    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:
    41
    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:
    24
    the problem is that sound plays on given coords
     
  10. RicardoMilos384

    RicardoMilos384 Slime

    Messages:
    82
    GitHub:
    ricardomilos384
    My bad, sorry
     
  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.