Wouter0100

Untitled

Aug 26th, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. local bridge = peripheral.wrap("left")
  2. local items = bridge.listItems();
  3.  
  4. craft = {}
  5. craft[265] = 500
  6. craft[266] = 250
  7.  
  8. crafting = {}
  9.  
  10. function checkCraft()
  11.     while true do
  12.         for key,value in pairs(craft) do
  13.             local craftCount = 0
  14.  
  15.             if crafting[key] == nil then
  16.  
  17.                 if items[key] == nil then
  18.                     craftCount = value
  19.                 elseif items[key] < value then
  20.                     craftCount = value - items[key]
  21.                 end
  22.  
  23.                 if craftCount > 0 then
  24.                     print("Craft " .. tostring(craftCount) .. " from itemid " .. key)
  25.                     bridge.craft(key, craftCount)
  26.  
  27.                     crafting[key] = craftCount
  28.                 end
  29.             end
  30.         end
  31.  
  32.         os.sleep(60)
  33.     end
  34. end
  35.  
  36. function listenComplete()
  37.     while true do
  38.         print("Listening to events")
  39.  
  40.         local event, key = os.pullEvent("craftingComplete")
  41.        
  42.         print("Received craftingComplete event for item " .. event.itemCrafted)
  43.  
  44.         if crafting[event.itemCrafted] ~= nil then
  45.             crafting[event.itemCrafted] = nil
  46.  
  47.             print("Removed from crafting table")
  48.         end
  49.     end
  50. end
  51.  
  52. parallel.waitForAll(checkCraft, listenComplete)
Advertisement
Add Comment
Please, Sign In to add comment