Advertisement
Bjornir90

Rc_pcside

Dec 8th, 2012
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.25 KB | None | 0 0
  1. os.loadAPI("octree")
  2.  
  3. local mapTree = octree.new()
  4. local termX, termY = term.getSize()
  5.  
  6.  
  7. local function clear()
  8. term.clear()
  9. term.setCursorPos(1, 1)
  10. end
  11.  
  12.  
  13.  
  14. local function rednetCheck(side)
  15.  local idReceiver, msg = rednet.receive()
  16.  if msg == "<success:"..side..">" then
  17.   return "true"
  18.  else
  19.   return "false"
  20.  end
  21. end
  22.  
  23.  
  24. local function drawBox(x, y, a, b, colorL)
  25. paintutils.drawLine(x, y, a, y, colorL) --draw the top line
  26. paintutils.drawLine(x, y, x, b, colorL) --draw the left line
  27. paintutils.drawLine(a, y, a, b, colorL) --draw the right line
  28. paintutils.drawLine(x, b, a, b, colorL) --draw the bottom line
  29. end
  30.  
  31. local function drawGUI()
  32. local x, y = term.getSize()
  33.  drawBox(41, 1, x, y, colors.blue)
  34. end
  35.  
  36. local function drawTurtle(x, y, orientation)
  37.  if orientation == "right" then
  38.   tW = ">"
  39.  elseif orientation == "left" then
  40.   tW = "<"
  41.  elseif orientation == "up" then
  42.   tW = "^"
  43.  elseif orientation == "down" then
  44.   tW = "v"
  45.  end
  46.  term.setCursorPos(x, y)
  47.  term.setTextColor(colors.red)
  48.  write(tW)
  49.  term.setTextColor(colors.white)
  50. end
  51.  
  52. local function drawMap(xPos, yPos, z, orientation)
  53.  local x = xPos-19
  54.  local y = yPos-termY/2
  55.  for a=1, termY do
  56.   for b=1, 40 do
  57.    local currentBlock = mapTree:get(b+x, y+a, z)
  58.    if currentBlock == nil then
  59.     paintutils.drawPixel(b+x, y+a, colors.grey)
  60.    elseif currentBlock == 1 then
  61.     paintutils.drawPixel(b+x, y+a, colors.green)
  62.    elseif currentBlock == 0 then
  63.     paintutils.drawPixel(b+x, a+y, colors.white)
  64.    end
  65.   end
  66.  end
  67.  drawTurtle(xPos, yPos, orientation)
  68. end
  69.  
  70. local function receiveMap()
  71.  local id, mapS = rednet.receive()
  72.  local mapT = textutils.unserialize(mapS)
  73.  local x, y, z, orientation, block = mapT[1], mapT[2], mapT[3], mapT[4], mapT[5]
  74.  mapTree:set(x, y, z, block)
  75. end
  76.  
  77. local function ping()
  78. write("ID of the turtle :")
  79. local idTurtle = tonumber(read())
  80. clear()
  81. rednet.send(idTurtle, "#/ping#")
  82. local id, msg = rednet.receive(5)
  83.  if msg == "<ping>" then
  84.   print("The turtle has respond")
  85.   sleep(1)
  86.   return "true"
  87.  else
  88.   print("Error : the turtle doesn't respond")
  89.   return "false"
  90.  end
  91. end
  92.  
  93. clear()
  94. ping()
  95. clear()
  96.  
  97. print("Enter command")
  98. while true do
  99. local key, keycode = os.pullEvent("key")
  100. if keycode == 200 then
  101.  rednet.send(idTurtle, "#/forward#")
  102.   if rednetCheck(forward) then
  103.   print("Success")
  104.  else
  105.   print("Fail")
  106.  end
  107. elseif keycode == 205 then
  108.  rednet.send(idTurtle, "#/right#")
  109. elseif keycode == 203 then
  110.  rednet.send(idTurtle, "#/left#")
  111. elseif keycode == 208 then
  112.  rednet.send(idTurtle, "#/back#")
  113.  if rednetCheck(back) then
  114.   print("Success")
  115.  else
  116.   print("Fail")
  117.  end
  118. elseif keycode == 57 then
  119.  rednet.send(idTurtle, "#/dig#")
  120. elseif keycode == 42 then
  121.  rednet.send(idTurtle, "#/up#")
  122.   if rednetCheck(up) then
  123.   print("Success")
  124.  else
  125.   print("Fail")
  126.  end
  127. elseif keycode == 29 then
  128.  rednet.send(idTurtle, "#/down#")
  129.   if rednetCheck(down) then
  130.   print("Success")
  131.  else
  132.   print("Fail")
  133.  end
  134. elseif keycode == 28 then
  135.  rednet.send(idTurtle, "#/select#")
  136.  write("Enter the number of the slot :")
  137.  numberSlot = read()
  138.  clear()
  139.  rednet.send(idTurtle, numberSlot)
  140. elseif keycode == 14 then
  141.  break
  142. end
  143. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement