Guest User

Untitled

a guest
Dec 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.87 KB | None | 0 0
  1. --Start networking
  2. rednet.open('right')
  3.  
  4. local currentSlot = 1
  5.  
  6. --Start location of turtle is its coordinates
  7. local myX = 0
  8. local myY = 0
  9. local myZ = 0
  10.  
  11. --Start look direction - forward
  12. local spinningVector = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} }
  13. local currentSpinningVector = 1
  14.  
  15. --ID server computer
  16. local serverId = 0
  17.  
  18. --Current mission
  19. local myMission = {x1 = 0, y1 = 0, z1 = 0, x2 = 0, y2 = 0, z2 = 0}
  20.  
  21. --Height to fly
  22. local flyingHeight = 90
  23.  
  24. --Stop mission or not
  25. local stopMission = false
  26.  
  27. --Get arguments from message
  28. local function parseArgs(message)
  29. local args = {}
  30. for arg in string.gmatch(message, '<(%S+)>') do
  31. table.insert(args, arg)
  32. end
  33. return args
  34. end
  35.  
  36. -- Helper functions
  37. local function alwaysTrue()
  38. return true
  39. end
  40. local function alwaysFalse()
  41. return false
  42. end
  43.  
  44. --Turn turtle (left or right)
  45. local function rotate(direction)
  46.  
  47. if (direction == 'right') then
  48. turtle.turnRight()
  49. currentSpinningVector = currentSpinningVector + 1
  50. else
  51. turtle.turnLeft()
  52. currentSpinningVector = currentSpinningVector - 1
  53. end
  54.  
  55. if (currentSpinningVector < 1) then
  56. currentSpinningVector = 4
  57. end
  58.  
  59. if (currentSpinningVector > 4) then
  60. currentSpinningVector = 1
  61. end
  62.  
  63. end
  64.  
  65.  
  66. --Face turtle north in local coordinates
  67. local function faceNorth()
  68. while (currentSpinningVector ~= 1) do
  69. rotate('left')
  70. end
  71. end
  72.  
  73. local function changePosition(direction)
  74. if (direction == 'down') then
  75. myZ = myZ - 1
  76. end
  77.  
  78. if (direction == 'up') then
  79. myZ = myZ + 1
  80. end
  81.  
  82. if (direction == 'forward') then
  83.  
  84. vec = spinningVector[currentSpinningVector]
  85. myX = myX + vec[1]
  86. myY = myY + vec[2]
  87.  
  88. end
  89.  
  90. if (direction == 'back') then
  91.  
  92. vec = spinningVector[currentSpinningVector]
  93. myX = myX - vec[1]
  94. myY = myY - vec[2]
  95.  
  96. end
  97. end
  98.  
  99. --Move turtle one step in any direction
  100. --If isSoft, will return false on facing something
  101. local function stepUp(direction, isSoft)
  102.  
  103. --Detect and move functions
  104. local moveF = turtle.forward
  105. local detectF = turtle.detect
  106. local digF = turtle.dig
  107.  
  108. if (direction == 'down') then
  109. moveF = turtle.down
  110. detectF = turtle.detectDown
  111. digF = turtle.digDown
  112. end
  113. if (direction == 'up') then
  114. moveF = turtle.up
  115. detectF = turtle.detectUp
  116. digF = turtle.digUp
  117. end
  118. if (direction == 'back') then
  119. moveF = turtle.back
  120. detectF = alwaysFalse
  121. digF = alwaysTrue
  122. end
  123.  
  124.  
  125.  
  126. while (detectF()) do
  127. if (isSoft) then
  128. return false
  129. end
  130. if (not digF()) then
  131. print('Cant dig!')
  132. error()
  133. end
  134. end
  135.  
  136. if (not moveF()) then
  137.  
  138. if (turtle.getFuelLevel() <= 0) then
  139. print('Refueling...')
  140. turtle.select(1)
  141. if (not turtle.refuel(1)) then
  142. print('Out of fuel.')
  143. return false
  144. end
  145. turtle.select(currentSlot)
  146. end
  147.  
  148. if (not moveF()) then
  149. print('Cant move on! Trying to move later...')
  150.  
  151. for i=0, 40 do
  152. os.sleep(3)
  153.  
  154. if (moveF()) then
  155. break
  156. end
  157.  
  158. if (i >= 39) then
  159. print('No more attempts. Im stuck.')
  160. return false
  161. end
  162. end
  163.  
  164. end
  165. end
  166.  
  167. --Change position
  168. changePosition(direction)
  169.  
  170. return true
  171. end
  172.  
  173. local function myPos()
  174. write('X = ')
  175. write(myX)
  176. write('; Y = ')
  177. write(myY)
  178. write('; Z = ')
  179. print(myZ)
  180. end
  181.  
  182. local function gpsLocate()
  183. local location = {0,0,0}
  184. myX, myY, myZ = gps.locate(5, false)
  185. if (myX == nil or myY == nil or myZ == nil) then
  186. print('Cant reach GPS')
  187. return false
  188. end
  189.  
  190. return true
  191. end
  192.  
  193.  
  194. --Try to purge inventory
  195. local function unload()
  196. print('Trying to unload')
  197.  
  198. local chestFound = false
  199.  
  200. --Function to drop items
  201. local dropF = turtle.drop
  202.  
  203. --Find chest
  204.  
  205. --Try in front
  206. for i=1, 4 do
  207. if (turtle.detect()) then
  208. chestFound = true
  209. break
  210. end
  211. rotate('left')
  212. end
  213.  
  214. if (not chestFound) then
  215. --Try up
  216. if (turtle.detectUp()) then
  217. chestFound = true
  218. dropF = turtle.dropUp
  219. end
  220. end
  221. if (not chestFound) then
  222. --Try down
  223. if (turtle.detectDown()) then
  224. chestFound = true
  225. dropF = turtle.dropDown
  226. end
  227. end
  228. if (not chestFound) then
  229. print('No chest around')
  230. return false
  231. end
  232.  
  233. local totalUnloaded = 0
  234. for i=2, 16 do
  235. local thisCount = turtle.getItemCount(i);
  236. if (thisCount > 0) then
  237. totalUnloaded = totalUnloaded + thisCount
  238. turtle.select(i)
  239. dropF()
  240. end
  241. end
  242.  
  243. --Done.
  244. print('Unloaded ' .. totalUnloaded .. ' items.')
  245.  
  246. return true
  247. end
  248.  
  249.  
  250.  
  251.  
  252. --Refuel
  253. local function refuelFromChest()
  254. print('Trying to refuel')
  255.  
  256. local chestFound = false
  257.  
  258. --Function to drop items
  259. local suckF = turtle.suck
  260. local dropF = turtle.drop
  261.  
  262. --Find chest
  263.  
  264. --Try in front
  265. for i=1, 4 do
  266. if (turtle.detect()) then
  267. chestFound = true
  268. break
  269. end
  270. rotate('left')
  271. end
  272.  
  273. if (not chestFound) then
  274. --Try up
  275. if (turtle.detectUp()) then
  276. chestFound = true
  277. suckF = turtle.suckUp
  278. dropF = turtle.dropUp
  279. end
  280. end
  281. if (not chestFound) then
  282. --Try down
  283. if (turtle.detectDown()) then
  284. chestFound = true
  285. suckF = turtle.suchDown
  286. dropF = turtle.dropDown
  287. end
  288. end
  289. if (not chestFound) then
  290. print('No chest around')
  291. return false
  292. end
  293.  
  294. turtle.select(1)
  295. dropF()
  296. while ( (turtle.getItemSpace(1) > 4) and (suckF())) do
  297. write('.')
  298. end
  299.  
  300. --Drop unnecessary
  301. if (turtle.getItemSpace(2)) then
  302. turtle.select(2)
  303. if (turtle.compareTo(1)) then
  304. dropF()
  305. end
  306. end
  307.  
  308.  
  309. --Done.
  310. print('Refueled.')
  311.  
  312. return true
  313. end
  314.  
  315.  
  316.  
  317.  
  318.  
  319. --Calibrate turtle coordinates
  320. --Find exit
  321. local function findWayOut()
  322. for i=0, 5 do
  323. if (not turtle.detect()) then
  324. return;
  325. end
  326. turtle.turnLeft()
  327. end
  328. end
  329.  
  330. local function calibrate()
  331. findWayOut()
  332.  
  333. --Crawl out of cage
  334. if (not stepUp('forward', true)) then
  335. print('Error while calibrating. Cant be miner.')
  336. error()
  337. end
  338.  
  339. --Zero position
  340. if (not gpsLocate()) then
  341. error()
  342. end
  343.  
  344. local zeroX = myX
  345. local zeroY = myY
  346. local zeroZ = myZ
  347.  
  348. if (not stepUp('forward', true)) then
  349. print('Error while calibrating. Cant be miner.')
  350. error()
  351. end
  352.  
  353. --Y+1 position
  354. gpsLocate()
  355. local yX = myX
  356. local yY = myY
  357. local yZ = myZ
  358.  
  359. if (not stepUp('back', true)) then
  360. print('Error while calibrating. Cant be miner.')
  361. error()
  362. end
  363.  
  364. rotate('right')
  365. if (not stepUp('forward', true)) then
  366. print('Error while calibrating. Cant be miner.')
  367. error()
  368. end
  369.  
  370. --X+1 position
  371. gpsLocate()
  372. local xX = myX
  373. local xY = myY
  374. local xZ = myZ
  375.  
  376. rotate('left')
  377. rotate('left')
  378. if (not stepUp('forward', true)) then
  379. print('Error while calibrating. Cant be miner.')
  380. error()
  381. end
  382. rotate('right')
  383.  
  384. if (not stepUp('back', true)) then
  385. print('Error while calibrating. Cant be miner.')
  386. error()
  387. end
  388.  
  389. --Calculate vectors now
  390.  
  391. --Vector forward and back
  392. local fV = {0, 0}
  393. if (yX - zeroX > 0) then
  394. fV[1] = 1
  395. end
  396. if (yX - zeroX < 0) then
  397. fV[1] = -1
  398. end
  399. if (yY - zeroY > 0) then
  400. fV[2] = 1
  401. end
  402. if (yY - zeroY < 0) then
  403. fV[2] = -1
  404. end
  405.  
  406. spinningVector[1][1] = fV[1]
  407. spinningVector[1][2] = fV[2]
  408.  
  409. spinningVector[3][1] = 0-fV[1]
  410. spinningVector[3][2] = 0-fV[2]
  411.  
  412. --Vector right and left
  413. local rV = {0, 0}
  414. if (xX - zeroX > 0) then
  415. rV[1] = 1
  416. end
  417. if (xX - zeroX < 0) then
  418. rV[1] = -1
  419. end
  420. if (xY - zeroY > 0) then
  421. rV[2] = 1
  422. end
  423. if (xY - zeroY < 0) then
  424. rV[2] = -1
  425. end
  426.  
  427. spinningVector[2][1] = rV[1]
  428. spinningVector[2][2] = rV[2]
  429.  
  430. spinningVector[4][1] = 0-rV[1]
  431. spinningVector[4][2] = 0-rV[2]
  432.  
  433.  
  434. --Debug
  435. --print('zero: ' .. zeroX .. ', ' .. zeroY .. ', ' .. zeroZ)
  436. --print('y+ : ' .. yX .. ', ' .. yY .. ', ' .. yZ)
  437. --print('x+ : ' .. xX .. ', ' .. xY .. ', ' .. xZ)
  438. --print('z+ : ' .. zX .. ', ' .. zY .. ', ' .. zZ)
  439. --for i=1, 4 do
  440. -- write(spinningVector[i][1])
  441. -- print(', ' .. spinningVector[i][2])
  442. -- print('')
  443. --end
  444. --error()
  445.  
  446. --Final position
  447. gpsLocate()
  448. end
  449.  
  450. -- Send message via rednet
  451. local function sendMessage(id, message)
  452. rednet.send(id, message)
  453. end
  454.  
  455. --Rotate 180 degrees
  456. local function rotate180()
  457. rotate('right')
  458. rotate('right')
  459. end
  460.  
  461. -- Introduce turtle in network
  462. local function introduce()
  463. local message = 'turtle <hello> <' .. myX .. '> <' .. myY .. '> <' .. myZ .. '>'
  464.  
  465. write('Introducing myself: ')
  466. print(message)
  467.  
  468. rednet.broadcast(message)
  469. end
  470.  
  471. local function turnToVector(x, y)
  472. --Find right vector
  473. local targetId = 0
  474. for targetId,vector in pairs(spinningVector) do
  475. if (vector[1] == x and vector[2] == y) then
  476. break
  477. end
  478. end
  479.  
  480. local dir = 'right'
  481. if ( (currentSpinningVector - targetId) % 4 == 1) then
  482. dir = 'left'
  483. end
  484.  
  485. while (spinningVector[currentSpinningVector][1] ~= x or
  486. spinningVector[currentSpinningVector][2] ~= y) do
  487. rotate(dir)
  488. end
  489. end
  490.  
  491. --Try to make step in any direction
  492. local function vectorStep(x, y, z, isSoft)
  493.  
  494.  
  495. if (x == 0 and y == 0 and z == 0) then
  496. return true
  497. end
  498.  
  499. local stepAmount = -1
  500. local vector = {0, 0}
  501.  
  502. --Try to move along Y
  503. if (y ~= 0) then
  504. vector = {0, -1}
  505. if (y < 0) then
  506. vector = {0, 1}
  507. stepAmount = 1
  508. end
  509. turnToVector(vector[1], vector[2])
  510.  
  511. if (stepUp('forward', isSoft)) then
  512. y = y + stepAmount
  513. return x,y,z
  514. end
  515. end
  516.  
  517. --Try to move along X
  518. if (x ~= 0) then
  519. stepAmount = -1
  520. vector = {-1, 0}
  521. if (x < 0) then
  522. vector = {1, 0}
  523. stepAmount = 1
  524. end
  525. turnToVector(vector[1], vector[2])
  526.  
  527. if (stepUp('forward', isSoft)) then
  528. x = x + stepAmount
  529. return x,y,z
  530. end
  531. end
  532.  
  533. --Try to move along Z
  534. if (z ~= 0) then
  535. stepAmount = -1
  536. local zDir = 'down'
  537. if (z < 0) then
  538. zDir = 'up'
  539. stepAmount = 1
  540. end
  541.  
  542. if (stepUp(zDir, isSoft)) then
  543. z = z + stepAmount
  544. return x,y,z
  545. end
  546. end
  547.  
  548. --Too bad, nothig help.
  549. return x,y,z
  550. end
  551.  
  552. --Try to reach point without destroying anything
  553. local function moveTo(x, y, z)
  554. --Calculate distance
  555. local dX = myX - x
  556. local dY = myY - y
  557. local dZ = myZ - z
  558.  
  559. local newX
  560. local newY
  561. local newZ
  562.  
  563. while (dX ~= 0 or dY ~= 0 or dZ ~= 0) do
  564. newX,newY,newZ = vectorStep(dX, dY, dZ, true)
  565.  
  566. if (newX == dX and newY == dY and newZ == dZ) then
  567. newX,newY,newZ = vectorStep(dX, dY, dZ, false)
  568. end
  569. if (newX == dX and newY == dY and newZ == dZ) then
  570. return false
  571. end
  572.  
  573. dX = newX
  574. dY = newY
  575. dZ = newZ
  576. end
  577.  
  578. --Arrived!
  579.  
  580. --Face north
  581. --faceNorth()
  582.  
  583. print('Moved to finish. My position: ')
  584. myPos()
  585.  
  586. return true
  587. end
  588.  
  589. -- Dir through to point
  590. local function digTo(x, y, z)
  591.  
  592. --Calculate distance
  593. local dX = x - myX
  594. local dY = y - myY
  595. local dZ = z - myZ
  596.  
  597.  
  598. local vector = {0, 0}
  599.  
  600. --Move along Y
  601. if (dY ~= 0) then
  602. vector = {0, 1}
  603. if (dY < 0) then
  604. vector = {0, -1}
  605. dY = math.abs(dY)
  606. end
  607. turnToVector(vector[1], vector[2])
  608.  
  609. for i=1, dY do
  610. if (not stepUp('forward', false)) then
  611. return false
  612. end
  613. end
  614. end
  615.  
  616. --Move along X
  617. if (dX ~= 0) then
  618. vector = {1, 0}
  619. if (dX < 0) then
  620. dX = math.abs(dX)
  621. vector = {-1, 0}
  622. end
  623. turnToVector(vector[1], vector[2])
  624.  
  625. for i=1, dX do
  626. if (not stepUp('forward', false)) then
  627. return false
  628. end
  629. end
  630. end
  631.  
  632. --Move along Z
  633. if (dZ ~= 0) then
  634. local zDir = 'up'
  635. if (dZ < 0) then
  636. dZ = math.abs(dZ)
  637. zDir = 'down'
  638. end
  639.  
  640.  
  641. for i=1, dZ do
  642. if (not stepUp(zDir, false)) then
  643. return false
  644. end
  645. end
  646. end
  647.  
  648. --Arrived!
  649.  
  650. --Face north
  651. --faceNorth()
  652.  
  653. --print('Digged to finish. My position: ')
  654. --myPos()
  655.  
  656. return true
  657. end
  658.  
  659.  
  660. --Get turtles global fuel level
  661. function fuelLevel()
  662. return turtle.getItemCount(1)
  663. end
  664.  
  665.  
  666. --Get on flying height to move long distances
  667. local function toFlyingHeight()
  668. print('Getting on flying height ' .. flyingHeight)
  669. if (not moveTo(myX, myY, flyingHeight)) then
  670. print('Cant get on flying height!')
  671. error()
  672. end
  673. end
  674.  
  675. local function outputMission()
  676. print('From: ' .. myMission.x1 .. ', ' .. myMission.y1 .. ', ' .. myMission.z1)
  677. print('To: ' .. myMission.x2 .. ', ' .. myMission.y2 .. ', ' .. myMission.z2)
  678. print('Home: ' .. myMission.homeX .. ', ' .. myMission.homeY .. ', ' .. myMission.homeZ)
  679. print('Start fuel: ' .. myMission.totalFuel)
  680. end
  681.  
  682. --Return home
  683. local function goHome()
  684. stopMission = false
  685.  
  686. print('Going home: ' .. myMission.homeX .. ', ' .. myMission.homeY .. ', ' .. myMission.homeZ)
  687.  
  688. --Get no flying height
  689. toFlyingHeight()
  690.  
  691. --Move to landing point
  692. if (not moveTo(myMission.homeX, myMission.homeY, flyingHeight)) then
  693. print('Cant reach home landing point!')
  694. error()
  695. end
  696.  
  697. print('Landing...')
  698. --Land
  699. if (not moveTo(myMission.homeX, myMission.homeY, myMission.homeZ)) then
  700. print('Cant land!')
  701. error()
  702. end
  703.  
  704. print('Asking home')
  705. --We are home, ask get in
  706. sendMessage(serverId, 'turtle <wanthome>')
  707.  
  708. return true
  709. end
  710.  
  711.  
  712. --Do our mission.
  713. local function doMission()
  714.  
  715. print('Doing mission!')
  716. outputMission()
  717.  
  718. --Get on flying height
  719. toFlyingHeight()
  720.  
  721.  
  722. --Calculate start and end point
  723. local sX = myMission.x1
  724. local sY = myMission.y1
  725. local sZ = myMission.z1
  726.  
  727. local eX = myMission.x2
  728. local eY = myMission.y2
  729. local eZ = myMission.z2
  730.  
  731. if (sZ < eZ) then
  732. local t
  733. t = eZ
  734. eZ = sZ
  735. sZ = t
  736. end
  737. if (sX > eX) then
  738. local t
  739. t = eX
  740. eX = sX
  741. sX = t
  742. end
  743. if (sY > eY) then
  744. local t
  745. t = eY
  746. eY = sY
  747. sY = t
  748. end
  749.  
  750. --Go to start point
  751. print('Going to start point of mining: ' .. sX .. ', ' .. sY .. ', ' .. sZ)
  752. if (not moveTo(sX, sY, sZ)) then
  753. print('Cant reach start point!')
  754. error()
  755. end
  756.  
  757. --We are on start position.
  758.  
  759. local totalLevels = math.abs(eZ - sZ)-1
  760. outputMission()
  761. print('Total levels: ' .. totalLevels)
  762.  
  763. for iZ=0, totalLevels do
  764. if (stopMission) then
  765. break
  766. end
  767.  
  768. z = sZ - iZ
  769. print('Z-level: ' .. iZ .. ' / ' .. totalLevels )
  770.  
  771. if (not digTo(myX, myY, z)) then
  772. print('Cant reach start point of Z-level!')
  773. error()
  774. end
  775.  
  776.  
  777. local reverse = false
  778. if (myX == eX) then
  779. reverse = true
  780. end
  781.  
  782. for x = sX, eX do
  783. if (stopMission) then
  784. break
  785. end
  786.  
  787. if (reverse) then
  788. x = eX - (x-sX)
  789. end
  790.  
  791.  
  792. --Dig along Y
  793. if (not digTo(x, myY, myZ)) then
  794. print('Cant reach start point of row!')
  795. error()
  796. end
  797. --On start pos
  798.  
  799. local toY = eY
  800. if (myY == eY) then
  801. toY = sY
  802. end
  803.  
  804. --Dig
  805. if (not digTo(myX, toY, myZ)) then
  806. print('Cant dig row!')
  807. error()
  808. end
  809.  
  810. end
  811. end
  812.  
  813.  
  814.  
  815.  
  816.  
  817. --Mission is over, go home
  818. goHome()
  819. end
  820.  
  821. print('Calibrating...')
  822. calibrate()
  823. write('I am on position: ')
  824. myPos()
  825. introduce()
  826.  
  827. term.clear()
  828. print('Awaiting orders. Press Q to terminate client.')
  829.  
  830. while true do
  831.  
  832. --Recieve event
  833. local event, id, message = os.pullEvent()
  834.  
  835. --Rednet signal
  836. if (event == "rednet_message") then
  837.  
  838. --print(message)
  839.  
  840. --Command from server
  841. local pos = string.find(message, "command")
  842.  
  843. if ((pos ~= nil) and (pos == 1)) then
  844. local args = parseArgs(message)
  845.  
  846. command = args[1]
  847.  
  848. --Asked for states
  849. if (command == 'states') then
  850.  
  851. --The one who asked for states is server
  852. serverId = id
  853.  
  854. --Fuel
  855. local fuel = fuelLevel()
  856.  
  857. --Loaded slots
  858. local loadedSlots = 0
  859. for i=2, 16 do
  860. if (turtle.getItemCount(i) > 0) then
  861. loadedSlots = loadedSlots + 1
  862. end
  863. end
  864.  
  865. --Send back message
  866. local states = "turtle <states> <" .. tostring(fuel) .. '> <' .. tostring(loadedSlots) .. '>'
  867.  
  868. print('Sending ' .. states .. ' to ' .. tostring(id))
  869.  
  870. sendMessage(id, states)
  871. end
  872.  
  873. --Move to
  874. if (command == 'move') then
  875. local toX = tonumber(args[2])
  876. local toY = tonumber(args[3])
  877. local toZ = tonumber(args[4])
  878. local response = args[5]
  879.  
  880. myPos()
  881. print('Moving to ' .. toX .. ', ' .. toY .. ', ' .. toZ)
  882.  
  883. moveTo(toX, toY, toZ)
  884.  
  885. --Send back report
  886. if (response ~= nil) then
  887. sendMessage(id, 'turtle <' .. response .. '> <' .. myX .. '> <' .. myY .. '> <' .. myZ .. '>')
  888. end
  889. end
  890.  
  891. --Reintroduce
  892. if (command == 'reintroduce') then
  893. introduce()
  894. serverId = id
  895. print('Reintroduced.')
  896. end
  897.  
  898. --Get mission
  899. if (command == 'mission') then
  900. myMission.x1 = tonumber(args[2])
  901. myMission.y1 = tonumber(args[3])
  902. myMission.z1 = tonumber(args[4])
  903. myMission.x2 = tonumber(args[5])
  904. myMission.y2 = tonumber(args[6])
  905. myMission.z2 = tonumber(args[7])
  906. local response = args[8]
  907.  
  908. write('Got new mission: ')
  909. write(myMission.x1)
  910. write(', ')
  911. write(myMission.y1)
  912. write(', ')
  913. write(myMission.z1)
  914. write(' - ')
  915. write(myMission.x2)
  916. write(', ')
  917. write(myMission.y2)
  918. write(', ')
  919. write(myMission.z2)
  920. --error()
  921.  
  922. --Send back report
  923. if (response ~= nil) then
  924. sendMessage(id, 'turtle <' .. response .. '>')
  925. end
  926. end
  927.  
  928. --We are telled to do out mission by ourselves.
  929. if (command == 'domission') then
  930.  
  931. --Init mission
  932.  
  933. --Current position is our home.
  934. myMission.homeX = args[2]
  935. myMission.homeY = args[3]
  936. myMission.homeZ = args[4]
  937.  
  938. --Start fuel level
  939. myMission.totalFuel = fuelLevel()
  940.  
  941.  
  942. --Do mission.
  943. doMission()
  944. end
  945.  
  946. --Unload
  947. if (command == 'unload') then
  948. unload()
  949. local response = args[2]
  950. --Send back report
  951. if (response ~= nil) then
  952. sendMessage(id, 'turtle <' .. response .. '>')
  953. end
  954. end
  955.  
  956. --Refuel
  957. if (command == 'refuel') then
  958. refuelFromChest()
  959. local response = args[2]
  960. --Send back report
  961. if (response ~= nil) then
  962. sendMessage(id, 'turtle <' .. response .. '>')
  963. end
  964. end
  965. end
  966. end
  967.  
  968.  
  969. --Exit
  970. if (event == "char" and id == "q") then
  971. break
  972. end
  973.  
  974.  
  975. end
  976.  
  977. sendMessage(serverId, 'turtle <quit>')
  978. print('Miner stopped.')
Add Comment
Please, Sign In to add comment