Is there a way to play a sound (5-20 sec long) for all Players nearby while its location changes? The playSound method takes just a Location parameter, I found no way to access something like a SoundManager to change a playing Sound's Location. Maybe somebody has an idea for a workaround? The sound should be attached to a player/horse while it's moving, if that makes it easier. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Hmmm, but it'd still sound strange if the brain locates the sound via stereo right of you while the player is on your left already. Also, how would you change the pitch dynamically?
You can set the location of the sound, to be heard by an individual player through the command player.playSound(name, x, y, z) If it were me, id use a for loop to change the location of the sound, so in psuedocode: for x in range 10{ x = x + 5 //CHANGE THESE TO WHAT YOU WANT z = z + 5 wait 0.5 seconds player.playSound(name, x, y, z) } Obviously this isn't in fluent java, but hey, that's something you can do as I'm not the best bukkit/java programmer out there, I just get a good idea of the flow of how things should work rn edit: Didn't realise you wanted it to follow a horse or something, but I guess now what you would do is try to get the location of the entity. Firstly, I guess you are spawning it in yourself and know a way of identifying it, so you would probably get the location of THE ENTITY through, I guess a command similar to getEntityLiving().getLocation() for horselocation in range 10{ wait 0.5seconds x = somehow getting horses location y = ^ z = ^ list horselocation = x, y, z player.playSound(name, horselocation); } As you can guess, I'm not great, but If you know the individual commands I'm sure you'd now have an idea of how to find it!
@D00py No, there is no way to change an already loaded sound. You can however create multiple continuous sounds at the entities current location. (I.E, break 1 sound that is 10 seconds long into 10 files that are one second long, and play each one with a delay of a second at that entities current location.) Nope. You should delay what you're doing. Waiting would stop the thread. Create a final instance of the horse, and use Horse.getLocation() to return it's updated location. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
First, I want the sound to be heard by all players nearby as I said, and so I'have to call playSound on the world, not the player(just btw FYI). Second, as i said, I have a sound of a length of more than 5 seconds, so if I'd "playSonged" it again and again, it would just restart. One approach would be dynamically or over-time changing some values, as I proposed the Location and you suggested the pitch. By choosing pitch, it would go like e.g. pitch is 1, after player went 1 block pitch is 0.7, 2 blocks 0.5 and so on. Great idea! I just hope there won't be breaks in between the sound fragments, I'll try that out later/tomorrow for sure. Thanks dude!
If there are, create fade-outs and fade-ins to the sound files. This will create a smoother transition between sounds.
@ShowbizLocket61 Not really. Since fade-out happens 25 blocks away from a location, you can spawn 9 sounds, each with a distance of 25 to achieve this effect while not being inefficient.
@Zombie_Striker Yes, that's just a variation. Still inefficient when you consider the probable number of blocks on any given world's surface.
@ShowbizLocket61 How so? However he triggers the sound to play, he will be able to at least get the location of the player when the sound is first played. Even if the player can travel five blocks a second and the sound that will play will last for ten seconds, the player would still be in range to hear the sounds, regardless of direction. As for efficiency, all this would do is send nine packets to the player telling them to play a sound at nine specific locations. This is not take up a lot of memory processing time.
@Zombie_Striker Not just nine, all locations on the world surface, spaced out 25 blocks in between, since just spawning 9 would not take into account teleportation.
@ShowbizLocket61 But the sounds he want are caused by a horse (most likely, it's custom galloping sounds), so teleportation does not matter.