Hello, I am making a plugin so that when a player comes close to a player they will hear a dog bark. How would i get the near by players location and if they are within a set amount it will play a sound?
@killerzz1 PlayerMoveEvent is called when a player is moving. you can get the location the player is moving to and you can get a list of all online players of the class Bukkit or of the Serverobject. Then you loop through all online players and check if their current location is in bounds with the player who moved. if there is a player in bounds, play the sound at his location. so far everything clear?
Lets say e.getPlayer() = pl, and you loop through all the players in the server except pl.Thats called loop Do what he said, then find the code for example: if(pl.getLocation().distanceSquared(loop.getLocation)<=radius*radius) { (bark) }
@Rambokatt @killerzz1 Well sure, PlayerMoveEvent is fired every time any player moved, but with the correct checks it wont laag. it is simply creating a few rectangles (done in less than 1 millisecond) and checking their borders (maximum 2 milliseconds). This wont cause laags. and only if the second check where you check the borders is true, you will do something. so up to this point it will cause like at a full bad luck maybe 5 milliseconds "laag". You won't die from that. And when you execute your code, it has to be done anyways, so there is no way to get arround that except for threading, scheduling or multiple processes.