Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved How to use addSound() ?

Comments in 'Plugin Development' started by hoyinm14mc, May 11, 2015.

  1. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Why I do $player->getLevel()->addSound(new FizzSound(new Vector3($player->x, $player->y, $player->z)), $this->getServer()->getOnlinePlayers()); and nothing happens?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    $player->getX(); etc?
  3. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    I think not this problem..
    There is no error, but I cannot hear any sound
  4. SpiderPig
    Offline

    SpiderPig Active Member

    Joined:
    Sep 21, 2013
    Posts:
    128
    Minecraft User:
    SpiderPig
    It's sending the packet to everyone but the XYZ aren't where the player is. So they cannot hear it.
    iksaku likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Note that $player itself is already a Vector3 and you don't need to construct another one.
    Also, the constructor is inherited from Vector3, so it is
    new FizzSound($x. $y, $z)
    Last edited: May 11, 2015
    Falk likes this.
  6. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Example?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $level->addSound(new FizzSound($player));
  8. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Used your solution, but
    Code:
    [Server] 14:35:13 [INFO] hoyinm[/192.168.0.102:43167] logged in with entity id 1 at (FACTIONS, 5.0731, 76, -89.4601)
    [Server] 14:35:15 [INFO] There are 1/100 players online: hoyinm
    [Server] 14:35:31 [INFO] Welcome hoyinm to the server!
    [Server] 14:35:35 [CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerCommandPreprocessEvent' to 'AuthMePE v0.1.7_beta': Argument 1 passed to pocketmine\level\sound\FizzSound::__construct() must be an instance of pocketmine\math\Vector3, string given, called in /storage/emulated/0/PocketMine/plugins/AuthMePE-master/src/AuthMePE/AuthMePE.php on line 127 and defined on AuthMePE\AuthMePE
    [Server] 14:35:35 [NOTICE] InvalidArgumentException: "Argument 1 passed to pocketmine\level\sound\FizzSound::__construct() must be an instance of pocketmine\math\Vector3, string given, called in /storage/emulated/0/PocketMine/plugins/AuthMePE-master/src/AuthMePE/AuthMePE.php on line 127 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/level/sound/FizzSound" at line 27
    [Server] 14:35:35 [INFO] hoyinm: gordon
    [Server] 14:35:37 [INFO] hoyinm left the game
    [Server] 14:35:37 [INFO] hoyinm[/192.168.0.102:43167] logged out due to client disconnect
    [Server] 14:35:37 [INFO] There are 0/100 players online:
  9. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Used this solution, no error but cannot hear any sound
  10. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $level->addSound(new FizzSound($player->getLocation()))
    DeBe, Falk and hoyinm14mc like this.
  11. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Finally!!
    Falk likes this.
  12. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Yup :) Didn't you want to send a Sound to everyone? If yes, try
    PHP:
    foreach($this->getServer()->getOnlinePlayers() as $player){
       
    $level->addSound(new FizzSound($player->getLocation()))
    }
    xpyctum likes this.
  13. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Of course!)
    PEMapModder and LDX like this.
  14. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Does it work?
  15. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Yep :)
  16. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Nice:) Maybe leave a like?:3
    TonyDroide and iksaku like this.
  17. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    You am lucky today :3
    PEMapModder likes this.
  18. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    433
    Plugins:
    14
    Minecraft User:
    shoghicp
    Seems like you did not even read the API usage and just tried to use something without knowing what it means.

    First of all, Player (and other entities) extends Position, which extends Vector3. getLocation() is redundant and wasteful. Second, you have a parameter for the list of players to send this sound, if null, will get the players that view the current chunk for the sound.

    This will send EACH online player the sounds from ALL the other players. If there are 80 players at the same time... 80 sounds in the same tick. Just imagine how that sounds, and it might even crash your device.

    This is why plugin developers should read the API docs seriously, otherwise your plugin can be the bottleneck of the entire system.

    By the way:
    PHP:
    //Send a sound to all online players originating from location (can be any kind of vector3, entity or player object)
    $level->addSound(new FizzSound($player), $this->getServer()->getOnlinePlayers());

    //Send a sound to nearby players (this might be what you want, so it won't go on different levels and/or regions of the world)
    $level->addSound(new FizzSound($player));
  19. reidq7
    Offline

    reidq7 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    178
    Minecraft User:
    reidq7
    Way to add music? :)
  20. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    I don't think MCPE support custom sounds yet :p
    hoyinm14mc likes this.

Share This Page

Advertisement