Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- isFirst = true
- colors = {
- 2,
- 4,
- 8,
- 16,
- 32,
- 64,
- 256,
- 512,
- 1024,
- 4096,
- 8192}
- function getItems(invName)
- --print("Reading "..invName)
- inv = peripheral.wrap(invName)
- if(inv.getInventorySize()) then
- invSize = inv.getInventorySize()
- contents = {}
- i = 1
- while i<=invSize do
- if inv.getStackInSlot(i) then
- thisStack = inv.getStackInSlot(i)
- thisName = thisStack["name"]
- if contents[thisName] then
- contents[thisName] = tonumber(contents[thisName])+tonumber(thisStack["qty"])
- else
- contents[thisName] = tonumber(thisStack["qty"])
- end
- end
- i=i+1
- end
- return contents
- else
- return false
- end
- end
- function getTrade(tradeName)
- --print("Reading "..tradeName)
- trader = peripheral.wrap(tradeName)
- trade = {}
- trade["want"] = {}
- trade["offer"] = {}
- --Ensure it exists
- if(trader.getInventorySize()) then
- want = trader.getStackInSlot(1)
- if(want) then
- trade["want"]["name"] = want["name"]
- trade["want"]["qty"] = want["qty"]
- else
- trade["want"]["name"] = "-----"
- trade["want"]["qty"] = 0
- end
- offer = trader.getStackInSlot(2)
- if(offer) then
- trade["offer"]["name"] = offer["name"]
- trade["offer"]["qty"] = offer["qty"]
- else
- trade["offer"]["name"] = "-----"
- trade["offer"]["qty"] = 0
- end
- end
- return trade
- end
- function monSetCol(col)
- x,y = mon.getCursorPos()
- mon.setCursorPos(col*35+1,y)
- end
- function monInc()
- x,y = mon.getCursorPos()
- mon.setCursorPos(1,y+1)
- end
- while true do
- local invs = {}
- local trades = {}
- local i = 1
- local j = 1
- --Get inventories and trade o mats and monitor
- for k,v in pairs(peripheral.getNames()) do
- if string.match(v,'iron') then
- invs[i] = v
- i = i+1
- end
- if string.match(v,'container') then
- invs[i] = v
- i = i+1
- end
- if string.match(v,'ender_chest') then
- invs[i] = v
- i = i+1
- end
- if string.match(v,'trade') then
- trades[j] = v
- j = j+1
- end
- if string.match(v,'monitor') then
- mon = peripheral.wrap(v)
- mon.setTextScale(1)
- mon.setCursorPos(1,1)
- if(isFirst) then
- mon.setBackgroundColor(32768)
- mon.clear()
- isFirst = false
- end
- end
- end
- table.sort(invs)
- table.sort(trades)
- data = {}
- --Combine into mega table
- for k,v in pairs(invs) do
- data[k] = {}
- data[k]["inv"] = v
- //Get pairs of Trade-O-Mats now
- data[k]["trade1"] = trades[k]
- data[k]["trade2"] = trades[k+9]
- end
- col = 0
- dispString = {}
- for k,v in pairs(data) do
- inv = v["inv"]
- trade1Name = v["trade1"]
- trade2Name = v["trade2"]
- items = getItems(inv)
- trade1 = getTrade(trade1Name)
- trade2 = getTrade(trade2Name)
- if(items) then
- if(trade1) then
- wantStock = 0
- offerStock = 0
- for i,j in pairs(items) do
- if trade1["offer"]["name"] == i then
- offerStock = j
- end
- if trade1["want"]["name"] == i then
- wantStock = j
- end
- end
- wantName = string.gsub(string.gsub(string.gsub(string.gsub(trade1["want"]["name"],'item.',''),'.name',''),'tile.',''),'extrautils:','')
- offerName = string.gsub(string.gsub(string.gsub(string.gsub(trade1["offer"]["name"],'item.',''),'.name',''),'tile.',''),'extrautils:','')
- color = colors[k%11+1]
- mon.setBackgroundColor(32768)
- mon.clearLine()
- mon.setTextColor(color) --Black
- monSetCol(0)
- mon.write("["..k.."]")
- if(trade1["offer"]["name"] == "Empty") then
- mon.setBackgroundColor(16384)
- mon.setTextColor(1) --White
- end
- if(offerStock <= 0) then
- mon.setBackgroundColor(16384) --Red
- mon.setTextColor(1) --White
- offerStock = "EMPTY!"
- end
- mon.write(" Offer: "..string.sub(offerName,1,18).." x"..trade1["offer"]["qty"])
- monSetCol(1)
- mon.setBackgroundColor(32768)
- mon.setTextColor(color) --Black
- mon.write('Want: '..string.sub(wantName,1,18).." x"..trade1["want"]["qty"])
- monSetCol(2)
- mon.setBackgroundColor(32768)
- mon.setTextColor(color) --Black
- monInc()
- else
- if(trade2) then
- wantStock = 0
- offerStock = 0
- for i,j in pairs(items) do
- if trade2["offer"]["name"] == i then
- offerStock = j
- end
- if trade2["want"]["name"] == i then
- wantStock = j
- end
- end
- wantName = string.gsub(string.gsub(string.gsub(string.gsub(trade2["want"]["name"],'item.',''),'.name',''),'tile.',''),'extrautils:','')
- offerName = string.gsub(string.gsub(string.gsub(string.gsub(trade2["offer"]["name"],'item.',''),'.name',''),'tile.',''),'extrautils:','')
- color = colors[k%11+1]
- mon.setBackgroundColor(32768)
- mon.clearLine()
- mon.setTextColor(color) --Black
- monSetCol(0)
- mon.write("["..k+9.."]")
- if(trade2["offer"]["name"] == "Empty") then
- mon.setBackgroundColor(16384)
- mon.setTextColor(1) --White
- end
- if(offerStock <= 0) then
- mon.setBackgroundColor(16384) --Red
- mon.setTextColor(1) --White
- offerStock = "EMPTY!"
- end
- mon.write(" Offer: "..string.sub(offerName,1,18).." x"..trade2["offer"]["qty"])
- monSetCol(1)
- mon.setBackgroundColor(32768)
- mon.setTextColor(color) --Black
- mon.write('Want: '..string.sub(wantName,1,18).." x"..trade2["want"]["qty"])
- monSetCol(2)
- mon.setBackgroundColor(32768)
- mon.setTextColor(color) --Black
- monInc()
- end
- end
- end
- print('Resting . . .')
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement