Advertisement
natie3

MazeControl

Nov 30th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. radar = peripheral.wrap("bottom")
  2. chat = peripheral.wrap("right")
  3. modem = peripheral.wrap("top")
  4. modem.open(11)
  5.  
  6. mapping = {}
  7. mapping[1] = "0 0 0 0 0 8 12 0 12 0 12 0 12"
  8. mapping[2] = "0 20 30 42 33 34 18 34 33 42 30 20 0"
  9. mapping[3] = "0 20 30 46 33 34 18 34 33 46 30 20 0"
  10. mapping[4] = "58 24 34 100 26 82 47 4 25 82 37 94 16"
  11. mapping[5] = "0 0 0 0 0 0 0 0 0 0 0 0"
  12.  
  13. state = 1
  14.  
  15. function set(num)
  16.   modem.transmit(10,11, mapping[num])
  17.   state = num
  18. end
  19.  
  20. function build(num, value)
  21.   result = ""
  22.   for i = 1, 13 do
  23.     result = result .. ((num == i and value) or "0")
  24.     if i ~= 13 then
  25.       result = result .. " "
  26.    end
  27.   end
  28.  
  29.   return result
  30. end
  31.  
  32. function det(x, z)
  33.   res = {}
  34.   res["row"] = math.ceil((z - 20) / -7)
  35.   res["col"] = math.ceil((x + 10)  / 7)
  36.  
  37.   return res
  38. end
  39.  
  40. function check(row1, col1, row2, col2)
  41.   first = false
  42.   second = false
  43.   players = radar.getPlayers()
  44.   for index, player in pairs(players) do
  45.     pos = det(player.x, player.z)
  46.     print(pos.row)
  47.     print(pos.col)
  48.     if pos.row == row1 and pos.col == col1 then
  49.       first = true
  50.     end
  51.     if pos.row == row2 and pos.col == col2 then
  52.       second = true
  53.     end
  54.   end
  55.  
  56.   return first and second
  57. end
  58.  
  59. set(state)
  60. os.startTimer(2)
  61.  
  62. while true do
  63.   e, v1, v2, v3, v4 = os.pullEvent()
  64.   if e == "timer" then
  65.     if state == 1 and check(4,4,4,4) then
  66.       set(2)
  67.     elseif state == 2 and check(2, 3, 6, 3) then
  68.       set(3)
  69.       modem.transmit(15,11, "222")
  70.       os.sleep(8)
  71.       set(4)
  72.     elseif state == 4 and check(4,5,5,5) then
  73.       set(5)
  74.     end
  75.  
  76.     os.startTimer(2)
  77.   elseif e == "command" then
  78.     if v2[1] == "set" then
  79.       modem.transmit(10,11, build(tonumber(v2[2]), v2[3]))
  80.     elseif v2[1] == "select" then
  81.       modem.transmit(10,11, mapping[tonumber(v2[2])])  
  82.     elseif v2[1] == "tell" then
  83.       print(check(1,1,1,1))
  84.     end
  85.   end
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement