SHARE
TWEET

xd

a guest Feb 14th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. event onLoad(){
  2.     database.execute("CREATE TABLE IF NOT EXISTS yRegions(
  3.         Id VARCHAR(5) PRIMARY KEY,
  4.         Name VARCHAR(255) NOT NULL,
  5.         Node1 VARCHAR(255),
  6.         Node2 VARCHAR(255)
  7.     );");
  8. }
  9.  
  10. event onInterval(0.5){
  11.     foreach(player in server.players){
  12.         if(regionPlayerEnter(player, "region") == true){
  13.             player.message("You entered in 'region' region!");
  14.         }
  15.         else if(regionPlayerLeave(player, "region") == true){
  16.             player.message("You leaved the 'region' region!", "red");
  17.         }
  18.     }
  19. }
  20.  
  21. command cregion(arg){
  22.     permission = "regions.create";
  23.     execute(){
  24.         if(isSet(arg)){
  25.             x = database.execute("SELECT * FROM yRegions WHERE Name = '" + arg + "'");
  26.             if(x.count == 0){
  27.                 database.execute("INSERT INTO yRegions (Id, Name) VALUES ('480" + random.int(1, 99) + "', '" + arg + "')");
  28.                 player.message("You have been created '" + arg + "' region!");
  29.             }
  30.             else{
  31.                 player.message("That region already exists!", "red");
  32.             }
  33.         }
  34.         else{
  35.             player.message("You need to say an region name!", "red");
  36.         }
  37.     }
  38. }
  39.  
  40. command node(arg, arg1){
  41.     permission = "region.nodes";
  42.     execute(){
  43.         if(isSet(arg) and isSet(arg1)){
  44.             x = database.execute("SELECT * FROM yRegions WHERE Name = '" + arg + "'");
  45.             if(x.count > 0){
  46.                 region = arg;
  47.                 nodeNumber = toNumber(arg1);
  48.                 if(nodeNumber == 1){
  49.                     database.execute("UPDATE yRegions SET Node1 = '" + player.position.x + ", " + player.position.y + ", " + player.position.z + "' WHERE Name = '" + region + "'");
  50.                     player.message("You have been seted Node1 in '" + region + "' region!");
  51.                 }
  52.                 if(nodeNumber == 2){
  53.                     database.execute("UPDATE yRegions SET Node2 = '" + player.position.x + ", " + player.position.y + ", " + player.position.z + "' WHERE Name = '" + region + "'");
  54.                     player.message("You have been seted Node2 in '" + region + "' region!");
  55.                 }
  56.                 else{
  57.                     player.message("You need to say a Node Number (1-2)", "red");
  58.                 }
  59.             }
  60.             else{
  61.                 player.message("Can't find that region!", "red");
  62.             }
  63.         }
  64.         else{
  65.             player.message("You need to say an region and node number", "red");
  66.         }
  67.     }
  68. }
  69.  
  70. function regionPlayerEnter(player, region){
  71.     if(inRegion(player, region) == true){
  72.         if(player.getData("region") == null){
  73.             player.setData("region", region);
  74.             return true;
  75.         }
  76.     }
  77. }
  78.  
  79. function regionPlayerLeave(player, region){
  80.     if(inRegion(player, region) == false){
  81.         if(player.getData("region") == region){
  82.             player.setData("region", null);
  83.             return true;
  84.         }
  85.     }
  86. }
  87.  
  88. //Put that function in your script
  89. function inRegion(player, region){
  90.     x = database.execute("SELECT * FROM yRegions WHERE Name = '" + region + "'");
  91.     if(x.count > 0){
  92.         x = x[0];
  93.         node1 = x[2];
  94.         node1 = node1.split(",");
  95.         node2 = x[3];
  96.         node2 = node2.split(",");
  97.        
  98.         nX = toNumber(node1[0]);
  99.         nY = toNumber(node1[1]);
  100.         nZ = toNumber(node1[2]);
  101.         n2X = toNumber(node2[0]);
  102.         n2Y = toNumber(node2[1]);
  103.         n2Z = toNumber(node2[2]);
  104.        
  105.         x1 = null;
  106.         x2 = null;
  107.         z1 = null;
  108.         z2 = null;
  109.         y1 = null;
  110.         y2 = null;
  111.        
  112.         if(nX < n2X){
  113.             x1 = nX;
  114.             x2 = n2X;
  115.         }
  116.         if(nX > n2X){
  117.             x1 = n2X;
  118.             x2 = nX;
  119.         }
  120.         if(nY < n2Y){
  121.             y1 = nY;
  122.             y2 = n2Y;
  123.         }
  124.         if(nY > n2Y){
  125.             y1 = n2Y;
  126.             y2 = nY;
  127.         }
  128.         if(nZ < n2Z){
  129.             z1 = nZ;
  130.             z2 = n2Z;
  131.         }
  132.         if(nZ > n2Z){
  133.             z1 = n2Z;
  134.             z2 = nZ;
  135.         }
  136.        
  137.         pos = player.position;
  138.         if(pos.x > x1 and pos.x < x2 and pos.y > y1 and pos.y < y2 and pos.z > z1 and pos.z < z2){
  139.             return true;
  140.         }
  141.         else{
  142.             return false;
  143.         }
  144.     }
  145.     else{
  146.         return false;
  147.     }
  148. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top