Advertisement
Guest User

test.lua

a guest
Oct 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. os.loadAPI("/egps.lua")
  2. egps.startGPS()
  3. egps.setLocationFromGPS()
  4.  
  5. function get_hive(h)
  6.   check_fuel()
  7.   goto_location(h)
  8.   process_hive()
  9.   dropoff_stuff()  
  10. end
  11.  
  12.  
  13. function dropoff_stuff()
  14.   goto_location(dropoff)
  15.   if sanity_check() == false then
  16.     print("Error at dropoff chest")
  17.     error()
  18.   end
  19.  
  20.   for i = 1,15 do
  21.     turtle.select(i)
  22.     if turtle.getItemCount(i) then
  23.       turtle.drop()
  24.     end
  25.   end
  26.   goto_location(fuel)        
  27. end
  28.  
  29. function process_hive()
  30.   local b = true
  31.   local count = 0
  32.   turtle.select(1)
  33.   repeat
  34.     b = turtle.suck()
  35.     if b then count = count + 1
  36.     end
  37.   until b == false
  38.  
  39.   for i = 1,count do
  40.     turtle.select(i)
  41.     local data = turtle.getItemDetail(i)
  42.     if string.find(data.name, "princess") then
  43.       turtle.drop()
  44.     elseif string.find(data.name, "drone") then
  45.       turtle.drop(1)
  46.     end
  47.   end
  48. end
  49.  
  50.  
  51. function check_fuel()
  52.   if goto_location(fuel) == false then
  53.     print("Unable to move to fuel dump.")
  54.     error()
  55.   end
  56.   if sanity_check() == false then
  57.     print("Unable to confirm at fuel dump.")
  58.     error()
  59.   end  
  60.  
  61.   if turtle.getItemCount(16) < 20 then
  62.     turtle.select(16)
  63.     turtle.suck(20)
  64.   end
  65.  
  66.   if turtle.getFuelLevel() < 1000 then
  67.     turtle.select(16)
  68.     turtle.refuel(20)
  69.   end
  70. end
  71.  
  72.  
  73. function goto_location(d)
  74.   -- print(d[1], d[2], d[3], d[4])
  75.   egps.moveTo(d[1],d[2],d[3],d[4])
  76. end
  77.  
  78. function sanity_check()
  79.   local success,data = turtle.inspect()
  80.   if success then
  81.     if string.find(data.name, "apiary") then
  82.       return true
  83.     elseif string.find(data.name, "alveary") then
  84.       return true
  85.     elseif string.find(data.name, "iron_chest") then
  86.       return true
  87.     end    
  88.   end  
  89.   return false
  90. end
  91.  
  92. -- Hive definitions
  93. --
  94. -- Directions:
  95. -- North = 0
  96. -- West  = 1
  97. -- South = 2
  98. -- East  = 3
  99. --
  100. -- Fourth entry for each is direction
  101.  
  102. dropoff={127,64,341,1}
  103. fuel={127,64,345,1}
  104. alv1={130,64,343,3}
  105. hive1={133,64,347,2}
  106. hive2={138,64,347,2}
  107. hive3={143,64,351,3}
  108. hive4={143,64,355,2}
  109. hive5={134,64,358,1}
  110. hive6={120,64,357,2}
  111. danger={158,65,395,3}
  112.  
  113. --------------------------------
  114. -- Main program
  115. --------------------------------
  116.  
  117. while true do
  118.   get_hive(alv1)
  119.   get_hive(hive1)
  120.   get_hive(hive2)
  121.   get_hive(hive3)
  122.   get_hive(hive4)
  123.   get_hive(hive5)
  124.   get_hive(hive6)
  125.   get_hive(danger)
  126.   sleep(60)
  127. end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement