Advertisement
sci4me

Auto Requesting System

Oct 17th, 2014
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. --CONFIG
  2. local Items = {
  3.     ["ME_Basic_Processor"] = {
  4.         ["id"] = 4362,
  5.         ["dmg"] = 18,
  6.         ["name"] = "ME Basic Processor"
  7.     },
  8.     ["ME_Advanced_Processor"] = {
  9.         ["id"] = 4362,
  10.         ["dmg"] = 19,
  11.         ["name"] = "ME Advanced Processor"
  12.     },
  13.     ["Silicon"] = {
  14.         ["id"] = 4362,
  15.         ["dmg"] = 13,
  16.         ["name"] = "Silicon"
  17.     }
  18. }
  19.  
  20. local keep = {
  21.     {
  22.         ["Item"] = Items["ME_Basic_Processor"],
  23.         ["Minimum"] = 10000
  24.     },
  25.     {
  26.         ["Item"] = Items["ME_Advanced_Processor"],
  27.         ["Minimum"] = 10000
  28.     },
  29.     {
  30.         ["Item"] = Items["Silicon"],
  31.         ["Minimum"] = 10000
  32.     }
  33. }
  34.  
  35. local side = "back"
  36.  
  37. --END CONFIG
  38. local per = peripheral.wrap(side)
  39.  
  40. local function stack(item, qty)
  41.     return {
  42.         ["id"] = item.id,
  43.         ["dmg"] = item.dmg,
  44.         ["qty"] = qty
  45.     }
  46. end
  47.  
  48. local function hasEnough(keep)
  49.     local count = per.countOfItemType(keep.Item.id, keep.Item.dmg)
  50.     return count >= keep.Minimum
  51. end
  52.  
  53. local function requestEnough(keep)
  54.     local count = per.countOfItemType(keep.Item.id, keep.Item.dmg)
  55.     local request = keep.Minimum - count + 64
  56.     print("Requesting " .. tostring(request) .. " " .. keep.Item.name)
  57.     per.requestCrafting(stack(keep.Item, request))
  58.     keep.Waiting = true
  59. end
  60.  
  61. local timer = 0
  62.  
  63. while true do
  64.     for i = 1, #keep do
  65.         local k = keep[i]
  66.         if not k.Waiting then
  67.             if not hasEnough(k) then
  68.                 requestEnough(k)
  69.             end
  70.         else
  71.             if hasEnough(k) then
  72.                 k.Waiting = false
  73.             end
  74.         end
  75.     end
  76.  
  77.     sleep(10)
  78.     timer = timer + 1
  79.  
  80.     if timer == 30 then
  81.         os.reboot() -- reset the system every 5 minutes. lazy fix to a shitty problem...
  82.     end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement