Advertisement
Alakazard12

Turtle Client

Nov 16th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. server = 10
  2.  
  3. function sep(list, by)
  4.     local newlist = {}
  5.     while true do
  6.         local on = nil
  7.         local done = false
  8.         for i = 1, #list do
  9.             if done == false then
  10.                 if string.sub(list, i, i) == by then
  11.                     on = i
  12.                     done = true
  13.                 end
  14.             end
  15.         end
  16.         if on then
  17.             table.insert(newlist, string.sub(list, 1, on - 1))
  18.             list = string.sub(list, on + 1)
  19.         else
  20.             break
  21.         end
  22.     end
  23.     table.insert(newlist, list)
  24.     return newlist
  25. end
  26.  
  27. function clear()
  28.     term.clear()
  29.     term.setCursorPos(1, 1)
  30.     term.setTextColor(1)
  31. end
  32.  
  33. function ports()
  34.     rednet.open("back")
  35.     rednet.open("top")
  36.     rednet.open("front")
  37.     rednet.open("bottom")
  38.     rednet.open("left")
  39.     rednet.open("right")
  40. end
  41.  
  42. function dp()
  43.     print("Doing: dump")
  44.     for t = 5, 16 do
  45.         turtle.select(t)
  46.         for i = 1, 4 do
  47.             local cm = turtle.compareTo(i)
  48.             if cm == true then
  49.                 turtle.drop(turtle.getItemCount(t))
  50.             end
  51.         end
  52.     end
  53.     rednet.send(server, textutils.serialize({"derp"}))
  54. end
  55.  
  56. function rec()
  57.     local idr, msgr, elr = nil
  58.     function lop()
  59.         local id, msg = rednet.receive()
  60.         if id == server then
  61.             msg = textutils.unserialize(msg)
  62.             idr = id
  63.             msgr = msg
  64.         else
  65.             lop()
  66.         end
  67.     end
  68.     lop()
  69.     repeat sleep(0) until idr and msgr
  70.     return idr, msgr
  71. end
  72.  
  73. function main()
  74.     clear()
  75.     ports()
  76.     rednet.send(server, textutils.serialize({true}))
  77.     print("Running turtle on "..tostring(os.getComputerID()))
  78.     function lolz()
  79.         local id, msg = rec()
  80.         for i,v in pairs(turtle) do
  81.             if tostring(i) == msg[1] then
  82.                 print("Doing: "..tostring(i))
  83.                 local p1, p2, p3, p4 = v(msg[2], msg[3])
  84.                 rednet.send(server, textutils.serialize({p1, p2, p3, p4}))
  85.             end
  86.         end
  87.         if msg[1] == "dp" then
  88.             dp()
  89.         end
  90.         lolz()
  91.     end
  92.     lolz()
  93. end
  94.  
  95. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement