draddy

CC Feeder for emitList

Jan 11th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.00 KB | None | 0 0
  1. --emit List Feeder
  2. --written na Draddy
  3.  
  4. local chest
  5. local file = "disk/emitList"
  6. local userRead = {}
  7. local me
  8. local cItem = nil
  9. local sItem
  10.  
  11. function initPeripherals()
  12.     local per = peripheral.getNames()
  13.     for i=1,#per do
  14.         --Monitor
  15.         if peripheral.getType(per[i]) == "monitor" then
  16.             monitor = peripheral.wrap(per[i])
  17.         --Modem(s) 
  18.         elseif peripheral.getType(per[i]) == "modem" then
  19.             m = peripheral.wrap(per[i])
  20.             if m.isWireless() and useRemote then
  21.                 modem = peripheral.wrap(per[i])
  22.                 os.loadAPI("disk/wirelessSend.lua")
  23.             else
  24.                 cModem = peripheral.wrap(per[i])
  25.             end
  26.         --bundeld Redstone cable
  27.         elseif peripheral.getType(per[i]) == "ccmp:saved_multipart" then
  28.             cablePos = per[i]
  29.         --ME System
  30.         elseif string.find(peripheral.getType(per[i]), "appliedenergistics2:") then
  31.             me = peripheral.wrap(per[i])
  32.         --Chest
  33.         elseif string.find(peripheral.getType(per[i]), "chest") then
  34.             chest = peripheral.wrap(per[i])
  35.         end
  36.     end
  37. end
  38.  
  39.  
  40. --check for item in chest
  41. function checkChest()
  42.     if chest then cItem = chest.list() end
  43. end
  44.  
  45. --find item in me system
  46. function checkMe()
  47.     if cItem then sItem = me.findItem(cItem[1].name .."@" ..cItem[1].damage).getMetadata() end
  48. end
  49.  
  50. --ask User and return answer
  51. function getUserInput(ask)
  52.     print(ask)
  53.     answer = read()
  54.     return answer
  55. end
  56.  
  57. --main - User Interaction
  58. function main()
  59.     monitor.clear()
  60.     monitor.setCursorPos(1,2)
  61.     monitor.write("Put item in chest,")
  62.     monitor.setCursorPos(1,3)
  63.     monitor.write("and follow terminal")
  64.     while true do
  65.         userRead = {}
  66.         cItem ={}
  67.         checkChest()
  68.         term.clear()
  69.         term.setCursorPos(1,1)
  70.         if #cItem == 0 then
  71.             print("please put the Item you want to add in the Chest")
  72.         else
  73.             checkMe()
  74.             ask = "found item ".. sItem.displayName .. " in chest. Add to emitList? (y/n)"
  75.             ans = getUserInput(ask)
  76.             if string.upper(ans) == "YES" or string.upper(ans) == "Y" or string.upper(ans) == "JA" or string.upper(ans) == "J" then
  77.                 userRead.displayName = sItem.displayName
  78.                 userRead.name = sItem.name
  79.                 userRead.damage = sItem.damage
  80.                 --print (userRead.displayName.. " " ..userRead.name.. " " ..userRead.damage)
  81.                 ask = "please enter the lower item limit"
  82.                 ans = getUserInput(ask)
  83.                 if tonumber(ans) ~= nil then userRead.min = tonumber(ans) else print(ans .." is not a number, set to 0") userRead.min = 0 end
  84.                 --print (userRead.min)
  85.                 ask = "please enter the upper item limit"
  86.                 ans = getUserInput(ask)
  87.                 if tonumber(ans) ~= nil then userRead.max = tonumber(ans) else print(ans .." is not a number, set to 1000") userRead.max = 1000 end
  88.                 --print (userRead.max)
  89.                 ask = "emit signal if (a)bove oder (b)elow limit?"
  90.                 ans = getUserInput(ask)
  91.                 if string.upper(ans) == "B" then userRead.emit = "low" elseif string.upper(ans) == "A" then userRead.emit = "high" else userRead.emit = "low" end
  92.                 --print (userRead.emit)
  93.                 ask = "what signal color?"
  94.                 ans = getUserInput(ask)
  95.                 userRead.color = ans
  96.                 --print (userRead.color)
  97.                 userRead.initEmit = false              
  98.             end
  99.             rs.setOutput("bottom", true)
  100.         end
  101.         --print(userRead.displayName ..", "..userRead.name ..", "..userRead.damage ..", "..userRead.min ..", "..userRead.max ..", "..userRead.emit ..", "..userRead.color)
  102.         ask = "write to file? (y/n)"
  103.         ans = getUserInput(ask)
  104.         if string.upper(ans) == "YES" or string.upper(ans) == "Y" or string.upper(ans) == "JA" or string.upper(ans) == "J" then
  105.             fw = fs.open(file, "a")
  106.             fw.writeLine("{displayName = "..textutils.serialise(userRead.displayName) .. ", name = " ..textutils.serialise(userRead.name) .. ", damage = " ..textutils.serialise(tostring(userRead.damage)) .. ", min = " ..textutils.serialise(userRead.min) .. ", max = " ..textutils.serialise(userRead.max) .. ", emit = " ..textutils.serialise(userRead.emit) .. ", color = " ..textutils.serialise(userRead.color) .. ", initEmit = " ..textutils.serialise(userRead.initEmit) .."}")
  107.             fw.close()
  108.         end
  109.         sleep(10)
  110.         rs.setOutput("bottom", false)
  111.     end
  112. end
  113. initPeripherals()
  114. main()
Advertisement
Add Comment
Please, Sign In to add comment