Advertisement
Nokiyen

event2

May 2nd, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. --[[
  2. ***********
  3. * event
  4. *
  5. **********
  6. ]]
  7.  
  8.  
  9.  
  10. -- get arguments.
  11.  
  12. --define functions.
  13. function dig(dir)
  14.  
  15. local currentDig = turtle.dig
  16. local currentDetect = turtle.detect
  17. if dir == 'up' then
  18. currentDig = turtle.digUp
  19. currentDetect = turtle.detectUp
  20. elseif dir == 'down' then
  21. currentDig = turtle.digDown
  22. currentDetect = turtle.detectDown
  23. end
  24.  
  25. local times = 0
  26. while currentDetect() do
  27. currentDig()
  28. times = times + 1
  29. if times == 15 then
  30. print("cant' dig!")
  31. exit() -- dare to cause error.
  32. break
  33. end
  34. sleep(1)
  35. end
  36.  
  37. end
  38.  
  39. function move(dir)
  40.  
  41. local currentAttack = turtle.attack
  42. local currentMove = turtle.forward
  43. if dir == 'up' then
  44. currentAttack = turtle.attackUp
  45. currentMove = turtle.up
  46. elseif dir == 'down' then
  47. currentAttack = turtle.attackDown
  48. currentMove = turtle.down
  49. end
  50.  
  51. local times = 0
  52. while currentMove() == false do
  53. currentAttack()
  54. times = times + 1
  55. if times == 30 then
  56. print("Can't move!")
  57. exit() -- dare to cause error.
  58. end
  59. end
  60.  
  61. end
  62.  
  63. function digSt(dist)
  64. for i=1, dist, 1 do
  65. dig('up')
  66. dig('down')
  67.  
  68. turtle.turnLeft()
  69. dig('front')
  70. turtle.turnRight()
  71. turtle.turnRight()
  72. dig('front')
  73.  
  74. turtle.turnLeft()
  75. dig('front')
  76. move('front')
  77. end
  78. end
  79.  
  80. function digE(dir, dist)
  81. for i=1, dist, 1 do
  82. dig('front')
  83. turtle.turnLeft()
  84. dig('front')
  85. turtle.turnLeft()
  86. dig('front')
  87. turtle.turnLeft()
  88. dig('front')
  89. turtle.turnLeft()
  90.  
  91. dig(dir)
  92. move(dir)
  93. end
  94. end
  95.  
  96. function dropStone()
  97. for i=2, 16, 1 do
  98. turtle.select(i)
  99. if turtle.compareTo(1) then
  100. turtle.drop()
  101. end
  102. end
  103. end
  104.  
  105. digSt(100)
  106. digE('up', 50)
  107. dropStone()
  108.  
  109. shell.run("quarry", "-dim", "5", "5", "3", "-invert", "true")
  110.  
  111. digE('down', 50)
  112. digSt(100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement