Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //假设的目标坐标
- var x=8.5;
- var y=5;
- var z=14.5;
- //指引条刷新延时,0为实时
- //注意: 启动时会大量发送信息包,请斟酌设置
- //不建议高于10,否则体验较差
- var ti=0;
- function timer(e){
- if(e.id == 61){
- //记录当前玩家坐标
- var px = e.player.getX();
- var py = e.player.getY();
- var pz = e.player.getZ();
- //计算两点的平面角度差
- var ts = Math.atan2((x-px),(z-pz))*(180/Math.PI);
- //获取玩家当前朝向角度
- var tr = e.player.getRotation();
- //计算朝向下的角度差
- 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;
- }
- //构建指引条文本
- 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-";
- }
- }
- //结束构建并计算三维空间下两点距离并向上取整
- tc = tc + "§r] " + Math.ceil(Math.sqrt(Math.abs((x-px)*(x-px)+(y-py)*(y-py)+(z-pz)*(z-pz)))) + "m";
- //输出指引条
- e.API.executeCommand(e.player.world, "/title " + e.player.getDisplayName() + " actionbar {\"text\":\"" + tc + "\"}");
- }
- }
- function keyPressed(e){
- //当玩家单击~键运行
- if(e.key==41){
- //如果已启动指引条
- if(e.player.timers.has(61)){
- //停止指引条并清空信息
- e.player.timers.reset(61);
- e.player.timers.stop(61);
- e.API.executeCommand(e.player.world, "/title " + e.player.getDisplayName() + " actionbar {\"text\":\"\"}");
- }else{
- //启动指引条
- e.player.timers.forceStart(61,ti,true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement