PacketPlayOutNamedSoundEffect Help!

Discussion in 'Plugin Development' started by OverDodo, Jun 23, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    OverDodo

    Hey,

    How can i use that Packet to play out an LEVEL_UP sound to only one player?
     
  2. public void onCommand(Command cmd, CommandSender sender, String commandLabel, String[] args)
    {
    //command name
    if(commandLabel.equalsIgnoreCase(<Sound ID>))
    {
    Player p = (Player) sender;
    World w = player.getWorld();
    Player t = player.getServer().getPlayer(args[0]);
    p.teleport(t);
    //Sound.ENDERMAN_TELEPORT is the sound. Just type in Sound. and it should give u a
    //on eclipse
    //player.getLocation() is where the sound will originate so make sure u put this after the teleport takes place.
    //or else no one would hear it
    //10 is the volume so this is loud enough to hear
    //1 is the pitch. i wouldnt change it.
    w.playSound(player.getLocation(), Sound.<Sound ID>, 10, 1);
    }
    }
     
  3. Offline

    Zombie_Striker

    @LandinosMC
    Please do not spoonfeed. All you needed to do was link to the playsound method ,Not only that, but this is not what he asked for. He is asking to play the sound for one player, but you are using the world object, which plays the sound for all players.

    @OverDodo
    Just use Player#playSound(Location, Sound, Int(Volume), int(Pitch)). The pitch should be 1, and for max volume, it should be 10.
     
  4. Offline

    OverDodo

    If you have a little bit of experience with Sounds, you should know, that players, who are near to that location can hear it too!
     
  5. Offline

    Horsey

    @OverDodo No, they can't. If you use player#playSound(); only the player you specified can hear the sound. The location is so that the sound can be played using stereo (or surround!) sound.
     
  6. Offline

    OverDodo

    whats with the "#"?
     
  7. Offline

    timtower Administrator Administrator Moderator

    @OverDodo Before the # is the class, the part after the # is the methodname.
     
Thread Status:
Not open for further replies.

Share This Page