Play Sound Effects

Discussion in 'Plugin Development' started by r0306, Jul 10, 2012.

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

    r0306

    As the title implies, how can I play sound effects from mobs. For example, if I wanted to play the effect of a ghast shriek. I tried using playEffect() but the shriek was more like a zombie growl. Does anyone know the data to make the shriek high pitched?

    Is it possible to send packets of the sound effect to clients?
     
  2. Offline

    bartboy8

    World world = player.getWorld();
    world.playEffect(location,Effect.GHAST_SHRIEK,0);

    Possibly editing the end value will change the pitch... im not quite sure.
     
  3. bartboy8 According to this: http://www.wiki.vg/Protocol#Sound.2FParticle_Effect_.280x3D.29 there is no data value for sound effects, so changing 0 to anything else shouldn't have any effect. But there seems to be two ghast sounds: mob.ghast.charge and mob.ghast.fireball. Now if you look here: https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/Effect.java#L38 you see that bukkit translates it to two different effects.

    r0306 That means for you try Effect.GHAST_SHRIEK as well as Effect.GHAST_SHOOT
     
  4. Offline

    bartboy8

    GHAST_SHOOT just makes a small sound. While GHAST_SHRIEK should make the sound when it shoots.
     
  5. Offline

    r0306

    V10lator
    bartboy8
    I've tried both sounds. Shriek sounds like a low growl and shoot makes a thumping sound. Neither of them fits into the sound I need. I'm trying to get the sound a ghast makes when it's hurt (the high pitched screech) but I haven't found any way to do this unless I packet send the ghast and the damage packet. However, this forces the player to see the ghast. Is there any way to play the screeching sound by packet sending or if not, changing the pitch of the shirek declaring a certain data type?

    Looking at this: https://github.com/Bukkit/CraftBukk...va/net/minecraft/server/EntityGhast.java#L189, it looks like there is something with the sound. Perhaps I can use that?
     
  6. you can spawn a ghast behint the player and do the sound then
     
  7. Offline

    r0306

    ferrybig
    Hmm. You mean spawn it, do the hurt effect, then despawn it all in one tick? I'll try that. :D

    ferrybig
    Awesome. I got the sound to play without the mob. Here's how I did it:

    Code:
            int id = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Plugin.getPlugin(), new Runnable()
            {
     
                @Override
                public void run()
                {
                    for (Player p : Bukkit.getServer().getOnlinePlayers())
                    {
                    ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(getMobSpawnPacket(player.getLocation())); //send the entity packet to create an entity at the player's location
                    ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(getMobStatus()); //send damage packet - plays the sound
                    ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(getEntityDestroyPacket()); //destroy the entity right after spawning it. sound will still play
     
                    }
     
                }
             
            }, 50L, 50L);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  8. Offline

    Beans

    so why wont it work when i do player.getWorld().playEffect(player.getLocation(), Effect.GHAST_SHOOT, 0);?
    and i did the code above, but its giving me erros on plugin.getPlugin() onc ((CraftPlayer)player) and on the getMobSpawnPacket and the other getMobStatus and getEntityDestroyPacket?
    can some one still help? or did API change on 1.3?
     
Thread Status:
Not open for further replies.

Share This Page