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

How to add Sound

Discussion in 'Development' started by Atomization, Jul 24, 2018.

  1. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    How do i add sound using LevelSoundEventPacket? i get no errors, but the code doesn't work and i don't here the sound
    PHP:
    use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
    PHP:
    $sound = new LevelSoundEventPacket();
    $sound->evid LevelSoundEventPacket::SOUND_EXPLODE;
    $sound->data 0;
    $sound->position $this->player->asVector3();

    $player->dataPacket($sound);
     
  2. Saiini14 TV

    Saiini14 TV Silverfish

    Messages:
    15
    GitHub:
    saini14
    Try this maybe?
    PHP:
    /**
    * @param LevelSoundEventPacket $sound
    * @param Player $player
    */
    public function sound(LevelSoundEventPacket $sound, Player $player)
    {
    $sound = new LevelSoundEventPacket();
    $sound->evid = LevelSoundEventPacket::SOUND_EXPLODE;
    $sound->data = 0;
    $sound->position = $this->player->asVector3();
    $player->dataPacket($sound);

    }


    ( dont quote me on this if it does not work )
     
  3. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    what is the $this?
     
  4. Saiini14 TV

    Saiini14 TV Silverfish

    Messages:
    15
    GitHub:
    saini14
    What do you mean? i dont see a $this used anywhere
     
  5. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    PHP:
    function sendSound(Player $playerint $sound){
                
    $pk = new LevelSoundEventPacket();
                
    $pk->position $player->asVector3();
                
    $pk->sound 81;
                
    $pk->extraData $type;
                
    $pk->pitch $pitch;
                
    $player->dataPacket($pk);
    }
    $sound->position = $this->player->asVector3();
     
  6. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    $pk->sound = $sound; you mean. Also, $pitch and $type are undefined.
     
  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.