Sound Volume and Pitch

Discussion in 'Plugin Development' started by the_merciless, Jun 7, 2013.

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

    the_merciless

    Is there a way to play the default volume and pitch of a sound,

    eg:

    player.playSound(player.getLocation(), args[0], vol, pitch);

    where args[0] is what sound the player typed,
    vol would be replaced with the correct volume for the sound and same for pitch.
     
  2. Offline

    ZeusAllMighty11

    Hey, the_merciless !


    It seems that you almost have it, but you need to parse the sound enum value into an actual. For example:

    Code:java
    1.  
    2. // as in your example
    3. player.playSound(player.getLocation(), Sound.valueOf(args[0]), Float.parseFloat(/* Some float*/), Float.parseFloat(/*Some float*/);
    4.  


    However, I can not recall off the top of my head if Sound has a valueOf() method. If it does not, it may have a fromName() method or something similar, in which you can compare.

    But keep note that enumeration values often use _ (underscores), and you will need to recognize this when parsing. You can also create your own method to parse your own sound, try reading around.

    Cheers,
    ~GG
     
  3. Offline

    Minnymin3

    TheGreenGamerHD
    I think its easier to do 1F instead of Float.parseFloat(1)
     
  4. Offline

    ZeusAllMighty11

    Minnymin3

    Not everyone uses 1 as their float value!
     
  5. Offline

    the_merciless

    Thats not exactly what i meant. The sound name is fine, i just wanted to ensure the pitch was the correct pitch for the sound, but it seems 1 is the correct pitch for all sounds. So i have it working perfectly now with this code:

    Code:
    for (Sound sound : Sound.values()){
                    if (sound.name().equalsIgnoreCase(playerdata.getString(p.getName() + ".Sound"))){
                        p.playSound(p.getLocation(), sound, 5, 1);
                        return;
                    }
                }
     
  6. Offline

    Minnymin3

    you can use #F for your float. USE ALL DA NUMBERS :p

    Yeah 1 is the correct pitch. Or at least it is close enough.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  7. Offline

    FunnyGopher

    1 is default volume, and 0 is default pitch.
     
    mine-care likes this.
Thread Status:
Not open for further replies.

Share This Page