Advertisement
Rain_Effect

Area Warning[1.12.2] v1.0

Sep 3rd, 2019
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Area data list
  2. var lpl = [
  3.     {
  4.         //Regional location (p1 must be smaller than p2)
  5.         p1:{x:0, y:0, z:0},
  6.         p2:{x:10, y:10, z:10},
  7.         //Enter
  8.         enterMsg:{
  9.             title: "Enter Danger Area",
  10.             subtitle: "Be careful",
  11.             actionbar: "Enter Area: Danger area",
  12.             message: "You have been enter danger area, be careful.",
  13.             notificationTitle: "Entering Danger Area",
  14.             notificationSubtitle: "Do you feel fear?"
  15.         },
  16.         //Leave
  17.         leaveMsg:{
  18.             title: "Leave Danger Area",
  19.             actionbar: "Leave Area: Danger area",
  20.             message: "You were leaving danger area.",
  21.             notificationTitle: "Leaving Danger Area"
  22.         }
  23.     }
  24. ];
  25.  
  26. //Clear data when player exit the game, so can log in and display again next time.
  27. function logout(e){
  28.     var pt = e.player.tempdata;
  29.     if(pt.has("lp")) pt.remove("lp");
  30. }
  31.  
  32. function tick(e){
  33.     var p = e.player;
  34.     var pt = p.tempdata;
  35.     if(!pt.has("lp")) pt.put("lp", new Array());
  36.     for(var i in lpl){
  37.         var msg = null;
  38.         var tc = pt.get("lp");
  39.         var tq = tc.indexOf(i);
  40.         if( (lpl[i].p1.x<p.x && p.x<lpl[i].p2.x) && (lpl[i].p1.y<p.y && p.y<lpl[i].p2.y) && (lpl[i].p1.z<p.z && p.z<lpl[i].p2.z) ){
  41.             if(tq==-1){
  42.                 var msg = lpl[i].enterMsg;
  43.                 tc.push(i);
  44.                 pt.put("lp", tc);
  45.                
  46.             }
  47.         }else{
  48.             if(tq!=-1){
  49.                 var msg = lpl[i].leaveMsg;
  50.                 tc.splice(tq,1);
  51.                 pt.put("lp", tc);
  52.             }
  53.         }
  54.         if(msg!=null){
  55.             if(msg.title!=null) {
  56.                 e.API.executeCommand(p.world, "/title " + p.displayName + " title {\"text\":\"" + msg.title + "\"}");
  57.                 e.API.executeCommand(p.world, "/title " + p.displayName + " subtitle {\"text\":\"" + ((msg.subtitle!=null)?msg.subtitle:"") + "\"}");
  58.             }
  59.             if(msg.actionbar!=null) e.API.executeCommand(p.world, "/title " + p.displayName + " actionbar {\"text\":\"" + msg.actionbar + "\"}");
  60.             if(msg.message!=null) p.message(msg.message);
  61.             if(msg.notificationTitle!=null) p.sendNotification(msg.notificationTitle, ((msg.notificationSubtitle!=null)?msg.notificationSubtitle:""), 2);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement