etelan

robotFetcher.lua

Jan 11th, 2021 (edited)
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function proxyFor(name, required)
  2.   local address = component and component.list(name)()
  3.   if not address and required then
  4.     error("missing component '" .. name .. "'")
  5.   end
  6.   return address and component.proxy(address) or nil
  7. end
  8.  
  9. local component = require "component"
  10. local robot = component.robot
  11. local grabber = component.inventory_controller
  12. local network = require("internet")
  13. local os = require "os"
  14. local robotAPI = require "robot"
  15.  
  16.  
  17.  
  18. local function moveCoord(x,y,z)
  19.  
  20.  
  21.   -- X (go forwards)
  22.   for i=1,x,1 do
  23.     robot.move(3)
  24.   end
  25.  
  26.   -- Z (go left)
  27.   robot.turn(false)
  28.  
  29.   for i=0,z,1 do
  30.     robot.move(3)
  31.   end
  32.  
  33.   robot.turn(true)
  34.  
  35.   -- Y (go down)
  36.   for i=1,y,1 do
  37.     robot.move(0)
  38.   end
  39.  
  40. end
  41.  
  42. -- Return
  43. local function returnCoord(x,y,z)
  44.  
  45.   -- Y (go up)
  46.   for i=1,y,1 do
  47.     robot.move(1)
  48.   end
  49.  
  50.   -- Z (go right)
  51.   robot.turn(true)
  52.  
  53.   for i=0,z,1 do
  54.     robot.move(3)
  55.   end
  56.  
  57.   robot.turn(false)
  58.  
  59.   -- X (go back)
  60.   robot.turn(true)
  61.   robot.turn(true)
  62.   for i=1,x,1 do
  63.     robot.move(3)
  64.   end
  65.   robot.turn(false)
  66.   robot.turn(false)
  67.  
  68.  
  69. end
  70.  
  71. -- Go to Name
  72. local function moveName(word)
  73.   local tempArray = foodcords[word]
  74.  
  75.   local workedx = tempArray[1]
  76.   local workedy = tempArray[2]
  77.   local workedz = tempArray[3]
  78.  
  79.   workedx = workedx - -243
  80.   workedy = workedy - 49
  81.   workedz = workedz - 184
  82.  
  83.   workedy = workedy * -1
  84.   workedz = workedz * -1
  85.  
  86.   moveCoord(workedx, workedy, workedz)
  87. end
  88.  
  89. -- Return Back Name
  90. local function returnName(word)
  91.   local tempArray = foodcords[word]
  92.  
  93.   local workedx = tempArray[1]
  94.   local workedy = tempArray[2]
  95.   local workedz = tempArray[3]
  96.  
  97.   workedx = workedx - -243
  98.   workedy = workedy - 49
  99.   workedz = workedz - 184
  100.  
  101.   workedy = workedy * -1
  102.   workedz = workedz * -1
  103.  
  104.   returnCoord(workedx, workedy, workedz)
  105. end
  106.  
  107. -- Take Amount
  108. local function transferAmount(amount)
  109.  
  110.   slots = math.ceil(amount/64)
  111.  
  112.   robot.turn(true)
  113.   robot.turn(true)
  114.  
  115.   --Pull the stuff
  116.   for i=1,slots,1 do
  117.    
  118.     if amount >= 64 then
  119.       taking = 64
  120.     else
  121.       taking = amount
  122.     end
  123.  
  124.     robot.select(i)
  125.     grabber.suckFromSlot(3,1, taking)
  126.    
  127.     amount = amount - taking    
  128.  
  129.   end
  130.  
  131.   robot.turn(false)
  132.   robot.turn(false)
  133. end
  134.  
  135. local function dumpInv(faction)
  136.  
  137.   robot.turn(false)
  138.  
  139.   if faction == "megacorp" then
  140.     robotAPI.forward()
  141.     robotAPI.forward()
  142.     robotAPI.forward()
  143.     robot.turn(false)
  144.   end
  145.  
  146.   if faction == "shadow" then
  147.     robotAPI.forward()
  148.     robotAPI.forward()
  149.     robotAPI.forward()
  150.     robotAPI.forward()
  151.     robot.turn(false)
  152.   end
  153.  
  154.   if faction == "domebois" then
  155.     robotAPI.forward()
  156.     robotAPI.forward()
  157.     robot.turn(false)
  158.   end
  159.  
  160.   if faction == "lee" then
  161.     robotAPI.forward()
  162.     robotAPI.forward()
  163.     robotAPI.forward()
  164.     robotAPI.forward()
  165.     robotAPI.forward()
  166.     robot.turn(false)
  167.   end
  168.  
  169.   for i=1,32,1 do
  170.     robot.select(i)
  171.     grabber.dropIntoSlot(3, i)
  172.   end
  173.  
  174.   if faction == "megacorp" then
  175.     robot.turn(false)
  176.     robotAPI.forward()
  177.     robotAPI.forward()
  178.     robotAPI.forward()
  179.     robot.turn(false)
  180.   end
  181.  
  182.   if faction == "domebois" then
  183.     robot.turn(false)
  184.     robotAPI.forward()
  185.     robotAPI.forward()
  186.     robot.turn(false)
  187.   end
  188.  
  189.   if faction == "shadow" then
  190.     robot.turn(false)
  191.     robotAPI.forward()
  192.     robotAPI.forward()
  193.     robotAPI.forward()
  194.     robotAPI.forward()
  195.     robot.turn(false)
  196.   end
  197.  
  198.   if faction == "lee" then
  199.     robot.turn(false)
  200.     robotAPI.forward()
  201.     robotAPI.forward()
  202.     robotAPI.forward()
  203.     robotAPI.forward()
  204.     robotAPI.forward()
  205.     robot.turn(false)
  206.   end
  207.  
  208. end
  209.  
  210. local function internetRequest()
  211.  
  212.   -- Local Variables
  213.   local stringSend = "http://86.7.146.45:4920/lastRequest"
  214.   local a = network.request(stringSend)
  215.  
  216.   for request in a do
  217.  
  218.     if string.len(request) < 5 then
  219.       return false, false, false
  220.     else
  221.    
  222.  
  223.  
  224.     local requestArray = {}
  225.  
  226.     count = 0
  227.     for i in string.gmatch(request, '([^,]+)') do
  228.  
  229.         if count == 2 or count == 3 then
  230.         requestArray[count] = i:match("%d+")
  231.         end
  232.  
  233.         if count == 1 or count == 0 then
  234.             requestArray[count] = i
  235.         end
  236.         count = count + 1
  237.  
  238.     end
  239.  
  240.     local faction = requestArray[0]
  241.     local item = requestArray[1]
  242.     local amount = requestArray[3]
  243.  
  244.     faction = string.match(faction, "%a+")
  245.     item = string.match(item, "%a+")
  246.     amount = tonumber(amount)
  247.  
  248.     print(faction)
  249.     print(item)
  250.     print(amount)
  251.  
  252.     return faction, item, amount
  253.   end
  254.   end
  255. end
  256.  
  257. local function delRequest()
  258.   local delete = network.request("http://86.7.146.45:4920/deleteRequest")
  259. end
  260.  
  261. foodcords = {}
  262.  
  263. foodcords["potato"] = {-229, 48, 174}
  264. foodcords["blackberry"] = {-209, 48, 164}
  265. foodcords["cantaloupe"] = {-189, 48, 164}
  266. foodcords["ginger"] = {-179, 48, 154}
  267. foodcords["blueberry"] = {-199, 48, 164}
  268. foodcords["garlic"] = {-189, 48, 144}
  269. foodcords["corn"] = {-209, 48, 134}
  270. foodcords["eggplant"] = {-189, 48, 134}
  271. foodcords["cranberry"] = {-189, 48, 154}
  272. foodcords["kiwi"] = {-179, 48, 164}
  273. foodcords["broccoli"] = {-219, 48, 154}
  274. foodcords["bean"] = {-239, 48, 174}
  275. foodcords["bambooshoot"] = {-239, 48, 154}
  276. foodcords["beet"] = {-229, 48, 154}
  277. foodcords["brusselsprout"] = {-229, 48, 164}
  278. foodcords["cauliflower"] = {-209, 48, 154}
  279. foodcords["cotton"] = {-199, 48, 134}
  280. foodcords["grape"] = {-179, 48, 144}
  281. foodcords["leek"] = {-219, 48, 154}
  282. foodcords["lettuce"] = {-219, 48, 154}
  283. foodcords["mustards"] = {-219, 48, 154}
  284. foodcords["candleberry"] = {-219, 48, 154}
  285. foodcords["coffee"] = {-219, 48, 134}
  286. foodcords["oats"] = {-219, 48, 154}
  287. foodcords["okra"] = {-219, 48, 154}
  288. foodcords["onion"] = {-219, 48, 154}
  289. foodcords["parsnip"] = {-219, 48, 154}
  290. foodcords["peanut"] = {-219, 48, 154}
  291. foodcords["peas"] = {-219, 48, 154}
  292. foodcords["pineapple"] = {-219, 48, 154}
  293. foodcords["radish"] = {-219, 48, 154}
  294. foodcords["raspberry"] = {-219, 48, 154}
  295. foodcords["rhubarb"] = {-219, 48, 154}
  296. foodcords["rice"] = {-219, 48, 154}
  297. foodcords["rutabaga"] = {-219, 48, 154}
  298. foodcords["rye"] = {-219, 48, 154}
  299. foodcords["scallion"] = {-219, 48, 154}
  300. foodcords["seaweed"] = {-219, 48, 154}
  301. foodcords["sesames"] = {-219, 48, 154}
  302. foodcords["soybean"] = {-219, 48, 154}
  303. foodcords["spiceleaf"] = {-219, 48, 154}
  304. foodcords["spinach"] = {-219, 48, 154}
  305. foodcords["strawberry"] = {-219, 48, 154}
  306. foodcords["sweetpotato"] = {-219, 48, 154}
  307. foodcords["tea"] = {-219, 48, 154}
  308. foodcords["tomato"] = {-219, 48, 154}
  309. foodcords["turnip"] = {-219, 48, 154}
  310. foodcords["waterchestnut"] = {-219, 48, 154}
  311. foodcords["whushroom"] = {-219, 48, 154}
  312. foodcords["wintersquash"] = {-219, 48, 154}
  313. foodcords["zucchini"] = {-219, 48, 154}
  314. foodcords["cabbage"] = {-219, 48, 154}
  315. foodcords["cactusfruit"] = {-219, 48, 144}
  316. foodcords["chilipepper"] = {-229, 48, 134}
  317. foodcords["artichoke"] = {-239, 48, 134}
  318. foodcords["barley"] = {-239, 48, 164}
  319. foodcords["asparagus"] = {-239, 48, 145}
  320. foodcords["bellpepper"] = {-229, 48, 144}
  321. foodcords["celery"] = {-209, 48, 144}
  322. foodcords["cucumber"] = {-199, 48, 144}
  323. foodcords["curryleaf"] = {-199, 48, 154}
  324.  
  325. while true do
  326.   local faction, item, amount = internetRequest()
  327.  
  328.   print("after internet")
  329.  
  330.   if faction ~= false then
  331.     print("good")
  332.     moveName(item)
  333.     transferAmount(amount )
  334.     returnName(item)
  335.     dumpInv(faction)
  336.     delRequest()
  337.   else
  338.     print("bad")
  339.   end
  340.    
  341.   os.sleep(2)
  342.   os.sleep(2)
  343. end
Add Comment
Please, Sign In to add comment