Advertisement
SirSheepe

Locating

May 16th, 2023 (edited)
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local player = peripheral.find("playerDetector")
  2. local chat = peripheral.find("chatBox")
  3.  
  4. function binarySearch(a, b)
  5.     if b - a == 1 then
  6.         local players = player.getPlayersInCubic(a, a, a)
  7.  
  8.         if #players == 0 then
  9.             return b, player.getPlayersInCubic(b, b, b)
  10.         else
  11.             return a, players
  12.         end
  13.     end
  14.  
  15.     local m = math.ceil((a + b) / 2)
  16.     local count = #player.getPlayersInCubic(m, m, m)
  17.  
  18.     if count == 0 then
  19.         return binarySearch(m, b)
  20.     else
  21.         return binarySearch(a, m)
  22.     end
  23. end
  24.  
  25. function binarySearchX(a, b, yz, p)
  26.     if b - a == 1 then
  27.         return player.isPlayerInCubic(a, yz, yz, p) and a or b
  28.     end
  29.  
  30.     local m = math.ceil((a + b) / 2)
  31.  
  32.     if player.isPlayerInCubic(m, yz, yz, p) then
  33.         return binarySearchX(a, m, yz, p)
  34.     else
  35.         return binarySearchX(m, b, yz, p)
  36.     end
  37. end
  38.  
  39. function binarySearchY(a, b, x, yz, p)
  40.     if b - a == 1 then
  41.         return player.isPlayerInCubic(x, a, yz, p) and a or b
  42.     end
  43.  
  44.     local m = math.ceil((a + b) / 2)
  45.  
  46.     if player.isPlayerInCubic(x, m, yz, p) then
  47.         return binarySearchY(a, m, x, yz, p)
  48.     else
  49.         return binarySearchY(m, b, x, yz, p)
  50.     end
  51. end
  52.  
  53. function binarySearchZ(a, b, x, y, p)
  54.     if b - a == 1 then
  55.         return player.isPlayerInCubic(x, y, a, p) and a or b
  56.     end
  57.  
  58.     local m = math.ceil((a + b) / 2)
  59.  
  60.     if player.isPlayerInCubic(x, y, m, p) then
  61.         return binarySearchZ(a, m, x, y, p)
  62.     else
  63.         return binarySearchZ(m, b, x, y, p)
  64.     end
  65. end
  66.  
  67. while true do
  68.     -- local br = 1
  69.     -- while #player.getPlayersInCubic(br, br, br) == 0 do
  70.     --  br = br * 2
  71.  
  72.     --  if br == 256 then
  73.     --      break
  74.     --  end
  75.     -- end
  76.  
  77.     end
  78. end
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement