SHOW:
|
|
- or go back to the newest paste.
1 | local col = 0 | |
2 | ||
3 | function getItems(invName) | |
4 | --print('Checking '..invName) | |
5 | inv = peripheral.wrap(invName) | |
6 | ||
7 | if(inv.getInventorySize()) then | |
8 | invSize = inv.getInventorySize() | |
9 | contents = {} | |
10 | ||
11 | i = 1 | |
12 | while i<=invSize do | |
13 | if inv.getStackInSlot(i) then | |
14 | thisStack = inv.getStackInSlot(i) | |
15 | thisName = thisStack["name"] | |
16 | if contents[thisName] then | |
17 | - | print(contents[thisName]["qty"]) |
17 | + | print("thisName:"..thisName) |
18 | print("contents:"..contents[thisName]) | |
19 | contents[thisName] = tonumber(contents[thisName]["qty"])+tonumber(thisStack["qty"]) | |
20 | else | |
21 | contents[thisName] = tonumber(thisStack["qty"]) | |
22 | end | |
23 | end | |
24 | i=i+1 | |
25 | end | |
26 | ||
27 | return contents | |
28 | else | |
29 | return false | |
30 | end | |
31 | end | |
32 | ||
33 | function getTrade(tradeName) | |
34 | trade = priperhal.wrap(tradeName) | |
35 | trade = {} | |
36 | ||
37 | --Ensure it exists | |
38 | if(trade.getInventorySize()) then | |
39 | want = trade.getStackInSlot(1) | |
40 | trade["want"]["name"] = want["name"] | |
41 | trade["want"]["qty"] = want["qty"] | |
42 | ||
43 | offer = trade.getStackInSlot(2) | |
44 | trade["offer"]["name"] = offer["name"] | |
45 | trade["offer"]["qty"] = offer["qty"] | |
46 | end | |
47 | return trade | |
48 | end | |
49 | ||
50 | function drawTrade(id,trade,inv) | |
51 | ||
52 | ||
53 | end | |
54 | ||
55 | function monSetPos() | |
56 | x,y = mon.getCursorPos() | |
57 | if(y>37) then | |
58 | col= col+1 | |
59 | y=0 | |
60 | monInc() | |
61 | end | |
62 | end | |
63 | ||
64 | function monInc() | |
65 | x,y = mon.getCursorPos() | |
66 | mon.setCursorPos(col*18+1,y+1) | |
67 | end | |
68 | ||
69 | local invs = {} | |
70 | local trades = {} | |
71 | local i = 1 | |
72 | local j = 1 | |
73 | --Get inventories and trade o mats and monitor | |
74 | for k,v in pairs(peripheral.getNames()) do | |
75 | if string.match(v,'iron') then | |
76 | invs[i] = v | |
77 | i = i+1 | |
78 | end | |
79 | if string.match(v,'trade') then | |
80 | trades[j] = v | |
81 | j = j+1 | |
82 | end | |
83 | if string.match(v,'monitor') then | |
84 | mon = peripheral.wrap(v) | |
85 | mon.setTextScale(0.5) | |
86 | mon.setCursorPos(1,1) | |
87 | mon.clear() | |
88 | end | |
89 | end | |
90 | ||
91 | table.sort(invs) | |
92 | table.sort(trades) | |
93 | data = {} | |
94 | --Combine into mega table | |
95 | for k,v in pairs(invs) do | |
96 | data[k] = {} | |
97 | data[k]["inv"] = v | |
98 | data[k]["trade"] = trades[i] | |
99 | end | |
100 | ||
101 | col = 0 | |
102 | for k,v in pairs(data) do | |
103 | inv = v["inv"] | |
104 | trade = v["trade"] | |
105 | items = getItems(inv) | |
106 | if(items) then | |
107 | monSetPos() | |
108 | mon.write('Chest '..k) | |
109 | monInc() | |
110 | for i,j in pairs(items) do | |
111 | mon.write(i..' x'..j) | |
112 | monInc() | |
113 | end | |
114 | end | |
115 | end | |
116 | ||
117 | for k,v in pairs(trades) do | |
118 | monSetPos() | |
119 | mon.write(k..':'..v) | |
120 | monInc() | |
121 | end |