Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --TRANSCRIPTION TABLE
- convTab = {
- dye = {"Ink Sac","Rose Red","Cactus Green","Cocoa Beans","Lapis Lazuli","Purlple Dye","Cyan Dye","Light Gray Dye","Gray Dye","Pink Dye","Lime Dye","Dandelion Yellow","Light Blue Dye","Magenta Dye","Orange Dye","Bonemeal"},
- wool = {"White wool","Orange wool","Magenta wool","Light blue wool","Yellow wool","Light green wool","Pink wool","Gray wool","Light gray wool","Cyan wool","Purple wool","Brown wool","Green wool","Red wool","Black wool"},
- stone = {"Stone","Granite","Polished granite","Diorite","Polished diorite","Andesite","Polished andesite"},
- planks = {"Oak plank","Spruce plank","Birch plank","Jungle plank","Acacia plank","Dark oak plank"},
- log1 = {"Oak log","Spruce log","Birch log","Jungle log"},
- log2 = {"Acacia log","Dark oak log"},
- stained_hardened = {"White clay","Orange clay","Magenta clay","Light blue clay","Yellow clay","Light green clay","Pink clay","Gray clay","Light gray clay","Cyan clay","Purple clay","Brown clay","Green clay","Red clay","Black clay"}
- }
- modem = peripheral.wrap("right")
- modem.open(57)
- Chest = peripheral.wrap("InventoryInterface_31")
- Disp = peripheral.wrap("InventoryInterface_33")
- Storage = peripheral.wrap("InventoryInterface_34")
- maxLimit = 1024
- PagePlus = function()
- page = page + 1
- if page>LastPage then
- page = LastPage
- end
- end
- PageMoins = function()
- page = page - 1
- if page<1 then
- page = 1
- end
- end
- Count = function(mode,num)
- if mode == "+" then
- currCount = currCount + num
- if currCount > maxLimit then
- currCount = maxLimit
- elseif currCount > qtTab[product]["amount"] and isBuying then
- currCount = qtTab[product]["amount"]
- end
- elseif mode == "-" then
- currCount = currCount - num
- if currCount < 1 then
- currCount = 1
- end
- end
- end
- Cancel = function()
- PanelMode = true
- end
- Confirm = function()
- PanelMode = true
- monitor.clear()
- if isBuying then
- modem.transmit(57,1,textutils.serialize({qtTab[product]["raw"],currCount}))
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- monitor.setCursorPos(6,10)
- monitor.write("Pulled 0 "..product.." out of ".. currCount)
- while true do
- os.startTimer(2)
- event = os.pullEvent("timer")
- if event == "timer" then
- chest = {}
- count = 0
- for i = 1,Storage.getInventorySize() do
- temp = Storage.getItemInSlot(i)
- count = count + (temp.stackSize or 0)
- end
- monitor.setCursorPos(6,10)
- monitor.write("Pulled "..count.." "..product.." out of ".. currCount)
- if count == currCount then
- for i = 1,Storage.getInventorySize() do
- Storage.transferToII(Disp.uuid(),1,1,64)
- end
- os.reboot()
- end
- end
- end
- else
- Command = touch.new("back")
- Command:add("Cancel",nil,11,18,32,20,colors.red,colors.lime)
- Command:draw()
- local chest = {}
- while true do
- os.startTimer(2)
- event,p1 = Command:handleEvents(os.pullEvent())
- if event == "button_click" then
- break
- elseif event == "timer" then
- chest = {}
- for i = 1,Chest.getInventorySize() do
- temp = Chest.getItemInSlot(i)
- if temp["name"] then
- chest[temp.name:gsub("minecraft:","")..":"..temp.metadata] = (chest[temp.name:gsub("minecraft:","")..":"..temp.metadata] or 0) + temp.stackSize
- end
- end
- monitor.setBackgroundColor(colors.black)
- monitor.setCursorPos(12,10)
- if chest[qtTab[product]["raw"]] then
- monitor.write(chest[qtTab[product]["raw"]].." "..product.." out of ".. currCount)
- if chest[qtTab[product]["raw"]] >= currCount then
- amount = currCount
- for i = 1,Chest.getInventorySize() do
- data = Chest.getItemInSlot(i)
- if data.name:gsub("minecraft:","")..":"..data.metadata == qtTab[product]["raw"] then
- Chest.transferToII(Storage.uuid(),i,i,amount)
- amount = amount - data.stackSize
- if amount <= 0 then
- break
- end
- end
- end
- sleep(5)
- for i = 1,Chest.getInventorySize() do
- Chest.transferToII(Disp.uuid(),i,i,64)
- end
- os.reboot()
- end
- else
- monitor.write("0 "..product.." out of ".. currCount)
- end
- end
- end
- end
- end
- function split(str,pat)
- local t = {}
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function Panel()
- local s = false
- PanelMode = true
- product = ""
- qtTab = {}
- isBuying = true
- os.loadAPI("touch")
- monitor = peripheral.wrap("back")
- monitor.clear()
- xMin = {22,3}
- xMax = {37,18}
- yMin = {2,6,10,14}
- yMax = {4,8,12,16}
- modem.transmit(57,1,"Request")
- tableau = {}
- while true do
- event,side,_,chanBis,msg = os.pullEvent("modem_message")
- if chanBis == 1 then
- tab = textutils.unserialize(msg)
- if type(tab) == "table" then
- for k,v in pairs(tab) do
- fullName = split(k,":")
- for a,b in pairs(convTab) do
- if k:find(a) then
- metadata = tonumber(fullName[2])
- name = b[metadata+1]
- table.insert(tableau,name)
- qtTab[name] = {}
- qtTab[name]["amount"] = v
- qtTab[name]["raw"] = k
- s = true
- break
- end
- end
- if not s then
- name = fullName[1]
- name = name:gsub("^%l", string.upper)
- name = name:gsub("%_"," ")
- table.insert(tableau,name)
- qtTab[name] = {}
- qtTab[name]["amount"] = v
- qtTab[name]["raw"] = k
- end
- s = false
- end
- end
- break
- end
- sleep(1)
- end
- if tableau == nil then
- tableau = {}
- end
- lastNumber = 0
- page = 1
- screen = {}
- currCount = 1
- GUI = touch.new("back")
- GUI:add("-100",function() Count("-",100) end,2,12,7,14,colors.red,colors.lime)
- GUI:add("-10",function() Count("-",10) end,9,12,13,14,colors.red,colors.lime)
- GUI:add("-1",function() Count("-",1) end,15,12,19,14,colors.red,colors.lime)
- GUI:add("+1",function() Count("+",1) end,21,12,25,14,colors.red,colors.lime)
- GUI:add("+10",function() Count("+",10) end,27,12,31,14,colors.red,colors.lime)
- GUI:add("+100",function() Count("+",100) end,33,12,38,14,colors.red,colors.lime)
- GUI:add("Cancel",function() Cancel() end,7,23,18,25,colors.red,colors.lime)
- GUI:add("Confirm",function() Confirm() end,23,23,34,25,colors.red,colors.lime)
- labelSwitch = {
- " ",
- " Buy ",
- " ",
- label = "switch"
- }
- buyLabel = {
- " ",
- " Buy ",
- " "
- }
- sellLabel = {
- " ",
- " Sell ",
- " "
- }
- for i=1,(math.ceil(#tableau/8)) do
- screen[i] = touch.new("back")
- end
- LastPage = #screen
- if LastPage ~= 1 then
- for a=1,(LastPage-1) do
- for b=1,8 do
- xMinCord = xMin[b%2+1]
- xMaxCord = xMax[b%2+1]
- yMinCord = yMin[math.ceil(b/2)]
- yMaxCord = yMax[math.ceil(b/2)]
- screen[a]:add(tableau[(a-1)*8+b],nil,xMinCord,yMinCord,xMaxCord,yMaxCord,colors.red,colors.lime)
- end
- screen[a]:add(labelSwitch,0,11,18,32,20,colors.blue,colors.cyan)
- screen[a]:add("<<Page",function() PageMoins() end,6,23,17,25,colors.red,colors.lime)
- screen[a]:add("Page>>",function() PagePlus() end,22,23,33,25,colors.red,colors.lime)
- end
- end
- o = #tableau%8
- lastNumber = o%2
- screen[LastPage]:add(labelSwitch,0,11,18,32,20,colors.blue,colors.cyan)
- screen[LastPage]:add("<<Page",function() PageMoins() end,6,23,17,25,colors.red,colors.lime)
- screen[LastPage]:add("Page>>",function() PagePlus() end,22,23,33,25,colors.red,colors.lime)
- if o>1 then
- for i=1,(o-lastNumber) do
- xMinCord = xMin[i%2+1]
- xMaxCord = xMax[i%2+1]
- yMinCord = yMin[math.ceil(i/2)]
- yMaxCord = yMax[math.ceil(i/2)]
- screen[LastPage]:add(tableau[(LastPage-1)*8+i],nil,xMinCord,yMinCord,xMaxCord,yMaxCord,colors.red,colors.lime)
- end
- end
- if lastNumber == 1 then
- screen[LastPage]:add(tableau[#tableau],nil,13,yMin[math.ceil(o/2)],27,yMax[math.ceil(o/2)],colors.red,colors.lime)
- end
- while true do
- if PanelMode then
- screen[page]:draw()
- monitor.setCursorPos(15,22)
- monitor.setBackgroundColor(colors.black)
- monitor.write("Page "..page.." of "..LastPage)
- local event, p1,p2,p3,p4 = screen[page]:handleEvents(os.pullEvent())
- if event == "button_click" then
- if type(screen[page].buttonList[p1].func) == "function" then
- screen[page]:flash(p1,0.2)
- screen[page].buttonList[p1].func()
- elseif type(screen[page].buttonList[p1].func) == "number" then
- isBuying = not isBuying
- for i=1,LastPage do
- if isBuying then
- screen[i].buttonList["switch"].label = buyLabel
- else
- screen[i].buttonList["switch"].label = sellLabel
- end
- screen[i]:toggleButton("switch")
- end
- else
- product = p1
- screen[page]:flash(p1,0.5)
- PanelMode = false
- currCount = 1
- end
- end
- elseif not PanelMode then
- GUI:draw()
- monitor.setCursorPos(12,10)
- monitor.setBackgroundColor(colors.black)
- if isBuying then
- monitor.write("Buy "..currCount.." of "..qtTab[product]["amount"].." "..product)
- else
- monitor.write("Sell "..currCount.." "..product)
- end
- local event, p1,p2,p3,p4 = GUI:handleEvents(os.pullEvent())
- if event == "button_click" then
- if type(GUI.buttonList[p1].func) == "function" then
- GUI:flash(p1,0.3)
- GUI.buttonList[p1].func()
- end
- end
- end
- end
- end
- Panel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement