Advertisement
SolidSnake96AS

CropCollector V2

Aug 30th, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. local i,j,h,w,command,percentual
  2. local arg={...}
  3.  
  4. command=arg[1]
  5. w=tonumber(arg[2])
  6. h=tonumber(arg[3])
  7.  
  8. local function pUsages()
  9.   print("Usages:")
  10.   print("CC collect <width> <height>")
  11.   print("CC make <width> <height>")
  12.   print("CC place <width> <height>")
  13.   print("CC help")
  14. end
  15.  
  16. local function pHelp()
  17.     local event,key
  18.     print("CropCollector help:")
  19.     print("Arguments:")
  20.     print(" collect: The turtle will collect the wheat of the farm then it will replace the seeds")
  21.     print(" make: The turtle will create a farm with the given width and height")
  22.     print(" place: The turtle will place the seeds in the farm")
  23.    
  24.     print("\nPress any key to continue...")
  25.     event,key=os.pullEvent("key")
  26.     term.clear()
  27.     term.setCursorPos(1,1)
  28.  
  29.     print("To use this program place the turtle in the upper left corner (facing the wheat), then place 2 chests to the sides of the turtle. (the 2 chests can be double)")
  30.     print("In the left chest there will be the seeds.")
  31.     print("The right chest is used to drop the seeds and the wheat.")
  32.    
  33.     print("\nPress any key to continue...")
  34.     event,key=os.pullEvent("key")
  35.     term.clear()
  36.     term.setCursorPos(1,1)
  37.    
  38.     print("Be sure to have enough seeds on the left chest before you run the program")
  39.     print("")
  40.    
  41.     print("Press any key to continue...")
  42.     event,key=os.pullEvent("key")
  43.     term.clear()
  44.     term.setCursorPos(1,1)
  45.    
  46.     print("EXAMPLE:")
  47.     print("")
  48.     print("C=chest")
  49.     print("S=seed chest ")
  50.     print("W=wheat")
  51.     print("T=turtle")
  52.     print("")
  53.     print("S")
  54.     print("TWWWWW")
  55.     print("CWWWWW")
  56.     print(" WWWWW")
  57. end
  58.  
  59. local function forward()
  60.   while (true)
  61.   do
  62.     if (turtle.forward())
  63.     then
  64.       break
  65.     end
  66.   end
  67. end
  68.  
  69. local function back()
  70.   while (true)
  71.   do
  72.     if (turtle.back())
  73.     then
  74.       break
  75.     end
  76.   end
  77. end
  78.  
  79. local function up()
  80.   while (true)
  81.   do
  82.     if (turtle.up())
  83.     then
  84.       break
  85.     end
  86.   end
  87. end
  88.  
  89. local function down()
  90.   while (true)
  91.   do
  92.     if (turtle.down())
  93.     then
  94.       break
  95.     end
  96.   end
  97. end
  98.  
  99. local function dropAll()
  100.   local slot
  101.  
  102.   print("Dropping item...")
  103.  
  104.   for slot=1,16
  105.   do
  106.     turtle.select(slot)
  107.     turtle.drop()
  108.   end
  109. end
  110.  
  111. local function pickUp()
  112.   local slot
  113.  
  114.   slot=1
  115.   print("Taking seeds...")
  116.  
  117.   for slot=1,16
  118.   do
  119.     turtle.select(slot)
  120.     turtle.suck(64)
  121.   end
  122. end
  123.  
  124. local function select()
  125.   local slot
  126.  
  127.   for slot=1,16
  128.   do
  129.     if (turtle.getItemCount(slot)>0)
  130.     then
  131.       turtle.select(slot)
  132.       return
  133.     end
  134.   end
  135. end
  136.  
  137. -----------------------------------------------------
  138.  
  139. if (command=="help")
  140. then
  141.   pHelp()
  142.   return
  143. end
  144.  
  145. if (#arg~=3)
  146. then
  147.   pUsages()
  148.   return
  149. elseif (command~="collect" and command~="make" and command~="place")
  150. then
  151.   pUsages()
  152.   return
  153. elseif (w<1 or h<1)
  154. then
  155.  print("The width and height must be greater than 0")
  156.  return
  157. end
  158.  
  159. term.clear()
  160. term.setCursorPos(1,1)
  161.  
  162. print("Starting...")
  163.  
  164. if (command=="collect")
  165. then
  166.   print("Prepare to collect "..tostring(w*h).." items")
  167. elseif (command=="place")
  168. then
  169.   print("Prepare to plant "..tostring(w*h).." seeds")
  170. elseif (command=="make")
  171. then
  172.   print("Prepare to make a "..tostring(w).."x"..tostring(h).." farm")
  173. end
  174. turtle.select(1)
  175.  
  176. if (command=="place")
  177. then
  178.   turtle.turnLeft()
  179.   pickUp()
  180.   turtle.turnRight()
  181. end
  182.  
  183. up()
  184. forward()
  185.  
  186. for i=1,h
  187. do
  188.   for j=1,w-1
  189.   do
  190.     if (command=="collect" or command=="make")
  191.     then
  192.       turtle.digDown()
  193.     elseif (command=="place")
  194.     then
  195.       select()
  196.       turtle.placeDown()
  197.     end
  198.     forward()
  199.   end
  200.  
  201.   print(tostring((i*w*100)/(w*h)).."% completed")-- w*h/i*w=100/x
  202.  
  203.   if (command=="collect" or command=="make")
  204.   then
  205.     turtle.digDown()
  206.   elseif (command=="place")
  207.   then
  208.     select()
  209.     turtle.placeDown()
  210.   end
  211.  
  212.   if (i%2==1)
  213.   then
  214.     turtle.turnRight()
  215.   else
  216.     turtle.turnLeft()
  217.   end
  218.  
  219.   forward()
  220.  
  221.   if (i<h-1)
  222.   then
  223.     if (command=="collect" or command=="make")
  224.     then
  225.       turtle.digDown()
  226.     elseif (command=="place")
  227.     then
  228.       select()
  229.       turtle.placeDown()
  230.     end
  231.   end
  232.  
  233.   if (i%2==1)
  234.   then
  235.     turtle.turnRight()
  236.   else
  237.     turtle.turnLeft()
  238.   end  
  239. end
  240.  
  241. print("Finished.")
  242.  
  243. if (h%2==1)
  244. then
  245.   for i=1,w
  246.   do
  247.     forward()
  248.   end
  249.  
  250.   turtle.turnRight()
  251. else
  252.   back()
  253.   turtle.turnLeft()
  254. end
  255.  
  256. for i=0,h-1
  257. do
  258.   forward()
  259. end
  260.  
  261. turtle.turnRight()
  262. down()
  263.  
  264. turtle.turnRight()
  265. dropAll()
  266. turtle.turnLeft()
  267. turtle.select(1)
  268.  
  269. if (command=="collect")
  270. then
  271.   shell.run("CC", "place "..tostring(w).." "..tostring(h))
  272. end
  273.  
  274. --script by SolidSnake96AS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement