Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Example location
- var x=8.5;
- var y=5;
- var z=14.5;
- //Compass refresh delay, 0 is every tick.
- //Be careful, it will send a lots of packet to client.
- //Not recommended above 10
- var ti=0;
- function timer(e){
- if(e.id == 61){
- //Record current player location
- var px = e.player.getX();
- var py = e.player.getY();
- var pz = e.player.getZ();
- //Calculate the difference in plane angle between two points
- var ts = Math.atan2((x-px),(z-pz))*(180/Math.PI);
- //Get the current orientation of the player
- var tr = e.player.getRotation();
- //Calculate the angular difference toward the bottom
- var tp = (tr>0?tr-360:tr) + (ts<0?ts+360:ts);
- if(tp<-180){
- tp = tp+360;
- }else if(tp>180){
- tp = tp-360;
- }
- //Building compass line text
- var tc = "§r[";
- for(var i = -10;i<10;i++){
- if(i==0) tc = tc + "§a|";
- if(((i==-10||i==9) && Math.abs(tp)>105) || (tp>((-i-1)*10-5) && tp<((-i+1)*10-5))){
- tc = tc + "§e-";
- }else{
- tc = tc + "§7-";
- }
- }
- //End the build and calculate the distance between the two points in the three-dimensional space and round up
- tc = tc + "§r] " + Math.ceil(Math.sqrt(Math.abs((x-px)*(x-px)+(y-py)*(y-py)+(z-pz)*(z-pz)))) + "m";
- //Output compass line text
- e.API.executeCommand(e.player.world, "/title " + e.player.getDisplayName() + " actionbar {\"text\":\"" + tc + "\"}");
- }
- }
- function keyPressed(e){
- //When player click "~" key
- if(e.key==41){
- //If it have been started
- if(e.player.timers.has(61)){
- //Stop to send and clear it
- e.player.timers.reset(61);
- e.player.timers.stop(61);
- e.API.executeCommand(e.player.world, "/title " + e.player.getDisplayName() + " actionbar {\"text\":\"\"}");
- }else{
- //Start to send
- e.player.timers.forceStart(61,ti,true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement