View difference between Paste ID: SwhweXJE and sY3R8EJ7
SHOW: | | - or go back to the newest paste.
1-
//假设的目标坐标
1+
//Example location
2
var x=8.5;
3
var y=5;
4
var z=14.5;
5
6-
//指引条刷新延时,0为实时
6+
//Compass refresh delay, 0 is every tick.
7-
//注意: 启动时会大量发送信息包,请斟酌设置
7+
//Be careful, it will send a lots of packet to client.
8-
//不建议高于10,否则体验较差
8+
//Not recommended above 10
9
var ti=0;
10
11
function timer(e){
12
    if(e.id == 61){
13-
        //记录当前玩家坐标
13+
        //Record current player location
14
        var px = e.player.getX();
15
        var py = e.player.getY();
16
        var pz = e.player.getZ();
17-
        //计算两点的平面角度差
17+
        //Calculate the difference in plane angle between two points
18
        var ts = Math.atan2((x-px),(z-pz))*(180/Math.PI);
19-
        //获取玩家当前朝向角度
19+
        //Get the current orientation of the player
20
        var tr = e.player.getRotation();
21-
        //计算朝向下的角度差
21+
        //Calculate the angular difference toward the bottom
22
        var tp = (tr>0?tr-360:tr) + (ts<0?ts+360:ts);
23
        if(tp<-180){
24
            tp = tp+360;
25
        }else if(tp>180){
26
            tp = tp-360;
27
        }
28-
        //构建指引条文本
28+
        //Building compass line text
29
        var tc = "§r[";
30
        for(var i = -10;i<10;i++){
31
            if(i==0) tc = tc + "§a|";
32
            if(((i==-10||i==9) && Math.abs(tp)>105) || (tp>((-i-1)*10-5) && tp<((-i+1)*10-5))){
33
                tc = tc + "§e-";
34
            }else{
35
                tc = tc + "§7-";
36
            }
37
        }
38-
        //结束构建并计算三维空间下两点距离并向上取整
38+
        //End the build and calculate the distance between the two points in the three-dimensional space and round up
39
        tc = tc + "§r] " + Math.ceil(Math.sqrt(Math.abs((x-px)*(x-px)+(y-py)*(y-py)+(z-pz)*(z-pz)))) + "m";
40-
        //输出指引条
40+
        //Output compass line text
41
        e.API.executeCommand(e.player.world, "/title " + e.player.getDisplayName() + " actionbar {\"text\":\"" + tc + "\"}");
42
    }
43
}
44
45
function keyPressed(e){
46-
    //当玩家单击~键运行
46+
    //When player click "~" key
47
    if(e.key==41){
48-
        //如果已启动指引条
48+
        //If it have been started
49
        if(e.player.timers.has(61)){
50-
            //停止指引条并清空信息
50+
            //Stop to send and clear it
51
            e.player.timers.reset(61);
52
            e.player.timers.stop(61);
53
            e.API.executeCommand(e.player.world, "/title " + e.player.getDisplayName() + " actionbar {\"text\":\"\"}");
54
        }else{
55-
            //启动指引条
55+
            //Start to send
56
            e.player.timers.forceStart(61,ti,true);
57
        }
58
    }
59
}