Advertisement
Guest User

Untitled

a guest
Aug 26th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.83 KB | None | 0 0
  1. local robot = require("robot")
  2. local component = require("component")
  3. local term = require("term")
  4. local event = require("event")
  5. local keyboard = require("keyboard")
  6.  
  7. local det,mat = robot.detect()
  8. local detDn,matDn = robot.detectDown()
  9. local detUp,matUp = robot.detectUp()
  10. local getSelect = robot.select()
  11.  
  12.  
  13.  
  14. function randTurn ()
  15.     print("turning")
  16.     if math.random(0,1)==0 then
  17.         robot.turnRight()
  18.     else
  19.         robot.turnLeft()
  20.     end
  21. end
  22.  
  23. function checkGravity ()
  24.     detDn,matDn = robot.detectDown()
  25.     while detDn==false or matDn=="entity" do
  26.         detDn,matDn = robot.detectDown()
  27.         if matDn=="entity" then
  28.             getSelect = robot.select()
  29.             robot.select(16)
  30.             component.inventory_controller.equip()
  31.                 while matDn=="entity" do
  32.                     robot.swingDown()
  33.                     detDn,matDn = robot.detectDown()
  34.                 end
  35.             component.inventory_controller.equip()
  36.             robot.select(getSelect)        
  37.         end
  38.         robot.down()
  39.         --detDn,matDn = robot.detectDown()
  40.     end
  41.     --check for entity below robot here?
  42. end
  43.  
  44. function checkSteps ()
  45.     getSelect = robot.select()
  46.     robot.select(10)
  47.     while robot.compare()==true do
  48.    
  49.         detUp,matUp = robot.detectUp()
  50.         while matUp=="entity" do
  51.             detUp,matUp = robot.detectUp()
  52.             if matUp=="entity" then
  53.                 getSelect = robot.select()
  54.                 robot.select(16)
  55.                 component.inventory_controller.equip()
  56.                     while matUp=="entity" do
  57.                         robot.swingUp()
  58.                         detUp,matUp = robot.detectUp()
  59.                     end
  60.                 component.inventory_controller.equip()
  61.                 robot.select(getSelect)        
  62.             end    
  63.         end
  64.         robot.up()
  65.         robot.forward()
  66.         --det,mat = robot.detect()
  67.     end
  68.     robot.select(getSelect)
  69. end
  70.  
  71. function checkObstacle ()
  72.     det,mat = robot.detect()
  73.     getSelect = robot.select()
  74.     if det==true then
  75.         --if object detected in front of
  76.         print("obstacle")
  77.         if mat=="entity" then
  78.             --attack goes here
  79.             print("attacking")
  80.             getSelect = robot.select()
  81.             robot.select(16)
  82.             component.inventory_controller.equip()
  83.                 while mat=="entity" do
  84.                     robot.swing()
  85.                     det,mat = robot.detect()
  86.                 end
  87.             component.inventory_controller.equip()
  88.             robot.select(getSelect)
  89.         else
  90.             --put in checks for mining or other actions here
  91.         end
  92.     robot.select(getSelect)
  93.     end
  94. end
  95.  
  96. function checkRedLine ()
  97.     getSelect = robot.select()
  98.     robot.select(11)
  99.     if robot.compareDown()==true then
  100.         --if on top of barrier line
  101.         print("red line")
  102.         robot.turnAround()
  103.         --robot.select(11)
  104.         while robot.compareDown()== true do
  105.             checkObstacle()
  106.             robot.forward()
  107.             --checkGravity()
  108.             checkSteps()
  109.         end
  110.     end
  111.     robot.select(getSelect)
  112. end
  113.  
  114. function randFwd (n)
  115.     getSelect = robot.select()
  116.     det,mat = robot.detect()
  117.     --detDn,matDn = robot.detectDown()
  118.     robot.select(11) -- red wool block
  119.     while n>0 and det==false and robot.compareDown()==false do
  120.         print(n .. " ")
  121.         robot.forward()
  122.         checkGravity()
  123.         det,mat = robot.detect()
  124.         n=n-1
  125.     end
  126.     checkSteps()
  127.     checkGravity()
  128.     robot.select(getSelect)
  129. end
  130.  
  131.  
  132. while true do
  133.     os.sleep(.1)
  134.     if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
  135.         os.exit()
  136.     end
  137.     randFwd(math.random(1,12))
  138.     checkGravity()
  139.     checkObstacle()
  140.     checkRedLine()
  141.     randTurn()
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement