etelan

Untitled

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