Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local component = require("component")
- local term = require("term")
- local event = require("event")
- local keyboard = require("keyboard")
- local det,mat = robot.detect()
- local detDn,matDn = robot.detectDown()
- local detUp,matUp = robot.detectUp()
- local getSelect = robot.select()
- function randTurn ()
- print("turning")
- if math.random(0,1)==0 then
- robot.turnRight()
- else
- robot.turnLeft()
- end
- end
- function checkGravity ()
- detDn,matDn = robot.detectDown()
- while detDn==false or matDn=="entity" do
- detDn,matDn = robot.detectDown()
- if matDn=="entity" then
- getSelect = robot.select()
- robot.select(16)
- component.inventory_controller.equip()
- while matDn=="entity" do
- robot.swingDown()
- detDn,matDn = robot.detectDown()
- end
- component.inventory_controller.equip()
- robot.select(getSelect)
- end
- robot.down()
- --detDn,matDn = robot.detectDown()
- end
- --check for entity below robot here?
- end
- function checkSteps ()
- getSelect = robot.select()
- robot.select(10)
- while robot.compare()==true do
- detUp,matUp = robot.detectUp()
- while matUp=="entity" do
- detUp,matUp = robot.detectUp()
- if matUp=="entity" then
- getSelect = robot.select()
- robot.select(16)
- component.inventory_controller.equip()
- while matUp=="entity" do
- robot.swingUp()
- detUp,matUp = robot.detectUp()
- end
- component.inventory_controller.equip()
- robot.select(getSelect)
- end
- end
- robot.up()
- robot.forward()
- --det,mat = robot.detect()
- end
- robot.select(getSelect)
- end
- function checkObstacle ()
- det,mat = robot.detect()
- getSelect = robot.select()
- if det==true then
- --if object detected in front of
- print("obstacle")
- if mat=="entity" then
- --attack goes here
- print("attacking")
- getSelect = robot.select()
- robot.select(16)
- component.inventory_controller.equip()
- while mat=="entity" do
- robot.swing()
- det,mat = robot.detect()
- end
- component.inventory_controller.equip()
- robot.select(getSelect)
- else
- --put in checks for mining or other actions here
- end
- robot.select(getSelect)
- end
- end
- function checkRedLine ()
- getSelect = robot.select()
- robot.select(11)
- if robot.compareDown()==true then
- --if on top of barrier line
- print("red line")
- robot.turnAround()
- --robot.select(11)
- while robot.compareDown()== true do
- checkObstacle()
- robot.forward()
- --checkGravity()
- checkSteps()
- end
- end
- robot.select(getSelect)
- end
- function randFwd (n)
- getSelect = robot.select()
- det,mat = robot.detect()
- --detDn,matDn = robot.detectDown()
- robot.select(11) -- red wool block
- while n>0 and det==false and robot.compareDown()==false do
- print(n .. " ")
- robot.forward()
- checkGravity()
- det,mat = robot.detect()
- n=n-1
- end
- checkSteps()
- checkGravity()
- robot.select(getSelect)
- end
- while true do
- os.sleep(.1)
- if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
- os.exit()
- end
- randFwd(math.random(1,12))
- checkGravity()
- checkObstacle()
- checkRedLine()
- randTurn()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement