Advertisement
natie3

Turtle elevator

Oct 13th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. radar = peripheral.wrap("bottom")
  2. on = {}
  3.  
  4. function add(number)
  5.   -- print("add: " .. number)
  6.   local cur = redstone.getBundledOutput("right")
  7.   if not colors.test(cur, number) then
  8.     redstone.setBundledOutput("right", cur + number)
  9.   end
  10.  
  11.   on["" .. number] = 5
  12. end
  13.  
  14. function remove(number)
  15.   local cur = redstone.getBundledOutput("right")
  16.   if colors.test(cur, number) then
  17.     redstone.setBundledOutput("right", cur - number)
  18.   end
  19. end
  20.  
  21. function within(value, first, second)
  22.   return first <= value and value <= second
  23. end
  24.  
  25. function check()
  26.   for k, v in pairs(on) do
  27.     -- print(k .. ": " .. v)
  28.     if v == 0 then
  29.       remove(tonumber(k))
  30.     else
  31.       on[k] = on[k] - 1
  32.     end
  33.   end
  34. end
  35.  
  36. while true do
  37.   players = radar.getPlayers()
  38.   for index, player in pairs(players) do
  39.     -- print(player.x)
  40.     -- print(player.y)
  41.     -- print(player.z)
  42.     if within(player.x, -1, 0) and within(player.y, 4, 7) and player.z == 0 then
  43.       add(1)
  44.     end
  45.     if within(player.x, -1, 0) and within(player.y, 15, 18) and player.z == 0 then
  46.       add(2)
  47.     end
  48.     if within(player.x, -1, 0) and within(player.y, 26, 29) and player.z == 0 then
  49.       add(4)
  50.     end
  51.     if within(player.x, -1, 0) and within(player.y, 37, 40) and player.z == 0 then
  52.       add(8)
  53.     end
  54.     if within(player.x, -1, 0) and within(player.y, 48, 51) and player.z == 0 then
  55.       add(16)
  56.     end
  57.     if within(player.x, -1, 0) and within(player.y, 59, 62) and player.z == 0 then
  58.       add(64)
  59.     end
  60.     if within(player.x, -1, 0) and within(player.y, 70, 73) and player.z == 0 then
  61.       add(128)
  62.     end
  63.   end
  64.   os.sleep(0.1)
  65.   check()
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement