Advertisement
derkoch

AE Observer for CC

Apr 23rd, 2014
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. -- time waiting after each check
  2. local timeout = 30
  3. local terminalside = "back"
  4.  
  5. -- name of item, itemid, itemmetavalue (0 for items without metadata), qty to keep in system
  6. local observerlist = {
  7.     { name = "Pulverized Obsidian", id = 20264, metadata = 3, maxqty = 360},
  8.     { name = "Glass", id = 20, metadata = 0, maxqty = 128},
  9.     { name = "Invar Ingot", id = 20264, metadata = 71, maxqty = 32},
  10.     { name = "Graphite Bar", id = 18006, metadata = 2, maxqty = 64}
  11. }
  12.  
  13. -- Iterates through items in observerlist and checks if the current quantity
  14. -- in the ae is lower than the quantity you wish to have, if this is the case
  15. -- the computer crafts the difference of items.
  16. function checkItems()
  17.     for k,item in pairs(observerlist) do
  18.         currentqty = peripheral.call(terminalside, "countOfItemType", item.id, item.metadata)
  19.         if currentqty < item.maxqty then
  20.             print("need to craft " .. (item.maxqty - currentqty) .. " " .. item.name .. "(" .. item.id ..":"..item.metadata..")")
  21.             craftItem(item.id, item.metadata, item.maxqty - currentqty)
  22.         end
  23.     end
  24. end
  25.  
  26. -- Crafts Items
  27. function craftItem(itemid, itemmeta, itemqty)
  28.     item = {id = itemid, dmg = itemmeta, qty = itemqty}
  29.     peripheral.call(terminalside, "requestCrafting", item)
  30. end
  31.  
  32. while true do
  33.     checkItems()
  34.     os.sleep(timeout)
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement