Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program uses a table provided by another
- --program that is saved to a common disk drive used
- --by the 2 computers. use pastebin code ctaTjUpj
- --to retrieve the table provided program
- crafting = {}
- ---------------------------------------------------
- -- assigns the name or side for the 3 needed peri-
- -- pherals for this program; a monitor, a disk
- -- drive, and an Applied Energistics ME system
- -- you can assign their network name or a side
- -- example apiName.setPeripheral("top","
- -- right","back")
- -- example2 apiName.setPeripheral("monitor_2",
- -- "disk_1","appeng_me_tilecontroller_3"
- function setPeripheral(monitor, disk, ME)
- mon = peripheral.wrap(monitor)
- disk = peripheral.wrap(disk)
- app = peripheral.wrap(ME)
- end -- set Peripheral
- ---------------------------------------------------
- ---------------------------------------------------
- function RoundNumber(num,idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult +.05) / mult
- end --
- ---------------------------------------------------
- ---------------------------------------------------
- -- collects the table of items to track from the
- -- disk drive. call this function after the
- -- setPeripheral function. And place it somewhere
- -- in your main loop. It does not have to be in
- -- every pass as it can slow your program, but it
- -- should be run every few seconds
- -- example apiName.collecTable()
- function collectTable()
- if fs.exists("disk/supplies") then
- fyle = fs.open("disk/supplies","r")
- items = textutils.unserialize(fyle.readAll())
- fyle.close()
- else
- term.clear()
- term.setCursorPos(12,8)
- term.write("Missing Esential File")
- sleep(2)
- collectTable()
- end -- if fs.exists
- for name,data in pairs(items) do
- if crafting[name] == nil then
- crafting[name] = false
- end
- end
- end -- collectTable()
- ---------------------------------------------------
- ---------------------------------------------------
- -- assigns a color to your list
- -- mainColor is the color than your item names will
- -- be
- -- secondColor is the color the item name will be
- -- while it's count is below the number you assign
- -- to keep in your ME in the other program
- -- countColor is the color that the number of each
- -- item will be displayed in
- -- dustColor is the color that the number of each
- -- items subItem will be displayed in
- -- example (apiName.assignColors(colors.blue,
- -- colors.cyan,colors.green,colors.purple)
- function assignColors(mainColor,secondColor,countColor,dustColor)
- defColor = mainColor
- craftColor = secondColor
- invColor = countColor
- subColor = dustColor
- end -- assignColors
- ---------------------------------------------------
- ---------------------------------------------------
- -- Draw the headline at the top of the monitor
- -- run this only once
- function headLine()
- mon.clear()
- mon.setTextColor(colors.orange)
- local w,h = mon.getSize()
- p = w/4
- mon.setCursorPos((2*p - string.len("Item Name"))/2+1,1)
- mon.write("Item Name")
- mon.setCursorPos((p-string.len("Count"))/2+(2*p)+1,1)
- mon.write("Count")
- mon.setCursorPos((p-string.len("Dust"))/2+(3*p)+1,1)
- mon.write("Dust")
- end -- headline()
- ---------------------------------------------------
- ---------------------------------------------------
- function useData()
- local currentColor
- for name,date in pairs(items) do
- local contained = app.countOfItemType(items[name]["id"],items[name]["damage"])
- line = items[name]["line"] + 2
- target = tonumber(items[name]["target"])
- lastCount = tonumber(items[name]["lastCount"])
- if items[name]["target"] ~= 0 then
- diff = contained - items[name]["target"]
- if diff < 0 and target > lastCount then
- if crafting[name] == false then
- ident = tonumber(items[name]["id"])
- dam = tonumber(items[name]["damage"])
- needed = math.abs(diff)
- itemStack = {id = ident, dmg = dam, qty = needed}
- app.requestCrafting(itemStack)
- crafting[name] = true
- print("Crafting "..needed.." "..items[name]["Name"])
- end -- if
- elseif contained >= target then
- crafting[name] = false
- end -- if
- else
- diff = 1
- end -- if
- if crafting[name] == true then
- currentColor = craftColor
- else
- currentColor = defColor
- end
- if items[name]["subID"] ~= "nil" then
- subItem = app.countOfItemType(items[name]["subID"],items[name]["subDamage"])
- else
- subItem = nil
- end
- fillLine(name,currentColor,contained,diff,subItem,line)
- items[name]["lastCount"] = contained
- end -- for name,data
- end -- useData()
- ---------------------------------------------------
- ---------------------------------------------------
- function fillLine(iName,iColor,iCount,difference,iSubItem,iLine)
- mon.setTextColor(iColor)
- mon.setCursorPos(1,iLine)
- mon.write(" ")
- mon.setCursorPos(1,iLine)
- mon.write(iName)
- if iCount >=0 then
- mon.setTextColor(defColor)
- else
- mon.setTextColor(colors.red)
- end
- if iCount > 1000000 then
- iCount = RoundNumber(iCount/1000000,2).."M"
- elseif iCount > 1000 then
- iCount = RoundNumber(iCount/1000,2).."K"
- end
- mon.setTextColor(invColor)
- mon.setCursorPos((p-string.len("iCount"))/2+(2*p)+1,iLine)
- mon.write(tostring(iCount))
- if iSubItem ~= nil then
- mon.setTextColor(subColor)
- if iSubItem >1000000 then
- iSubItem = RoundNumber(iSubItem/1000000,2).."M"
- elseif iSubItem >1000 then
- iSubItem = RoundNumber(iSubItem/1000,2).."K"
- end
- mon.setTextColor(subColor)
- mon.setCursorPos((p-string.len("iSubItem"))/2+(3*p)+2,iLine)
- mon.write(tostring(iSubItem))
- end
- end -- fillLine()
- ---------------------------------------------------
- setPeripheral("monitor_31","drive_9","appeng_me_tilecontroller_2")
- assignColors(colors.blue,colors.cyan,colors.green,colors.purple)
- headLine()
- collectTable()
- while true do
- collectTable()
- for t = 1,20 do
- useData()
- end
- end
Add Comment
Please, Sign In to add comment