Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Workshop main Computer
- --Variables
- os.loadAPI("button")
- os.loadAPI("button2")
- local screen = peripheral.wrap("monitor_1")
- local MonitorKeyboard = peripheral.wrap("monitor_0")
- local sensor = peripheral.wrap("left")
- local AE = peripheral.wrap("back")
- local ChestPrice = peripheral.wrap("chest_0")
- local ChestInput = peripheral.wrap("right")
- local xSize,ySize = screen.getSize()
- local ItemPrice = {}
- local FluidPrice = {}
- local Alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
- local file = fs.open("Price","r")
- ItemPrice = textutils.unserialize(file.readAll())
- local MetaResearch = ""
- local IDResearch = ""
- local page = 1
- local pages = 0
- local Search = ""
- local Data = {}
- local t ={}
- --MainProgramm
- MonitorKeyboard.clear()
- screen.clear()
- AffichageMonitorItem()
- function addItemPrice()
- term.clear()
- print("Please insert an item into the first slot of the chest")
- while ChestInput.getStackInSlot(1) ~= nil do
- print("Begin Analyzing")
- for k,v in pairs(ChestInput.getStackInSlot(1)) do
- if k == "name" then
- t["Name"] = v
- end
- if k == "dmg" then
- t["Dmg"] = v
- end
- if k == "id" then
- t["Id"] = v
- end
- end
- print(" Now please enter the price :")
- t["Price"] = read()
- table.insert(ItemPrice,t)
- print("Work done.")
- AffichageComputer()
- break
- end
- end
- function AffichageComputer()
- for i = 1,3 do
- paintutils.drawLine(1,i,51,i,Color)
- paintutils.drawLine(1,27-i,51,27-i,Color)
- end
- for i = 1,4 do
- paintutils.drawLine(i,1,i,17,Color)
- paintutils.drawLine(51-i,1,51-i,17,Color)
- end
- term.setCursorPos(5,4)
- for i = 1,#CustomerName do
- if i > 6 then
- break
- break
- end
- paintutils.drawImage(paintutils.loadImage(string.sub(CustomerName,i,i)))
- term.setCursorPos(3+term.getCursorPos()[1],3+term.getCursorPos()[2])
- end
- term.setCursorPos(20,24)
- print("> ")
- end
- function AffichageMonitorKeyboard()
- MonitorKeyboard.clear()
- button2.clearTable()
- local CurrentLetter = 0
- local countRow = 1
- local Col = 2
- local Row = 8
- for CurrentLetter = 1,#Alphabet do
- Row = 4+(CountRow)
- button2.setTable(Alphabet[CurrentLetter],Press,Alphabet[CurrentLetter],Col,Col+17,Row,Row)
- if Col == 21 then
- Col = 2
- countRow = countRow+2
- else
- Col = Col+4
- end
- end
- button2.setTable("Space",Press," ",21,29,19,19,)
- button2.setTable("<",Press,"<",31,38,19,19)
- button2.setTable("Switch to Id",AffichageMonitorIdResearch,"",21,38,26,26)
- button2.setTable("Research",Research,(Search,"Name"),21,38,22,22)
- button.sreen()
- end
- function Research(Search,type)
- if type == "Name" then
- for i = 1,#ItemPrice do
- if not string.find(ItemPrice[i]["Name"],Search) == nil then
- table.insert(Data[i],ItemPrice[i]["Name"])
- end
- end
- else
- for i = 1,#ItemPrice do
- if ItemPrice[i]["Id"] == Search[1] and ItemPrice[i]["Dmg"] == Search[2] then
- table.insert(Data[i],ItemPrice[i]["Name"])
- end
- end
- end
- AffichageMonitorItem()
- end
- function Press(char)
- if char == "<" then
- Search = string.gsub(Search,-1,1)
- else
- Search = Search..char
- end
- AffichageMonitorKeyboard()
- end
- function AffichageMonitorItem(o)
- if o == nil then
- screen.clear()
- button.clearTable()
- local CurrentItem = 0
- local countRow = 1
- local Col = 2
- local Row = 12
- local nbItemPerPage = 8
- pages = math.ceil(#ItemPrice/nbItemPerPage)
- for CurrentItem = 1,#ItemPrice do
- if CurrentItem > nbItemPerPage*(page - 1) and CurrentItem < nbItemPerPage*page+1 then
- Row = 4+(CountRow)
- button.setTable(ItemPrice[CurrentItem]["Name"],BuyItem,ItemPrice[CurrentItem]["Name"],Col, Col+17 , Row, Row)
- if Col == 21 then
- Col = 2
- countRow = countRow + 2
- else
- Col = Col+19
- end
- end
- end
- button.label(15,3,"Page "..tostring(page).." on "..tostring(pages))
- button.setTable("Buy Liquids",AffichageMonitorLiquid,"",21,38,19,19)
- button.setTable("Next Page", nextPage, "", 21, 38, 1, 1)
- button.setTable("Prev Page", prevPage, "", 2, 19, 1, 1)
- button.sreen()
- elseif string.find(o,%a) ~= nil then
- screen.clear()
- button.clearTable()
- local CurrentItem = 0
- local countRow = 1
- local Col = 2
- local Row = 12
- local nbItemPerPage = 8
- pages = math.ceil(#Data/nbItemPerPage)
- for CurrentItem = 1,#Data do
- if CurrentItem > nbItemPerPage*(page - 1) and CurrentItem < nbItemPerPage*page+1 then
- Row = 4+(CountRow)
- button.setTable(Data[CurrentItem]["Name"],BuyItem,Data[CurrentItem]["Name"],Col, Col+17 , Row, Row)
- if Col == 21 then
- Col = 2
- countRow = countRow + 2
- else
- Col = Col+19
- end
- end
- end
- button.label(15,3,"Page "..tostring(page).." on "..tostring(pages))
- button.setTable("Buy Liquids",AffichageMonitorLiquid,"",21,38,19,19)
- button.setTable("Next Page", nextPage, "", 21, 38, 1, 1)
- button.setTable("Prev Page", prevPage, "", 2, 19, 1, 1)
- button.sreen()
- else
- Data = o
- screen.clear()
- button.clearTable()
- local CurrentItem = 0
- local countRow = 1
- local Col = 2
- local Row = 12
- local nbItemPerPage = 8
- pages = math.ceil(#Data/nbItemPerPage)
- for CurrentItem = 1,#Data do
- for i = 1,#ItemPrice do
- if tonumber
- if CurrentItem > nbItemPerPage*(page - 1) and CurrentItem < nbItemPerPage*page+1 then
- Row = 4+(CountRow)
- button.setTable(,BuyItem,,Col, Col+17 , Row, Row)
- if Col == 21 then
- Col = 2
- countRow = countRow + 2
- end
- end
- function AffichageMonitorIdResearch()
- MonitorKeyboard.clear()
- button2.clear()
- local CurrentNumber = 0
- local CurrentRow = 1
- local Row = 4
- local Col = 4
- for i =1,9 do
- Row = 4+(CountRow)
- button2.setTable(tostring(i),PressNumber,tostring(i),Col,Col+6,Row,Row)
- if Col == 12 then
- Col = 4
- countRow = countRow+4
- else
- Col = Col+4
- end
- end
- button2.setTable("<",Press,"<",2,15,24,24)
- button2.setTable("Switch to Name",AffichageMonitorKeyboard,"",17,38,24,24)
- button2.setTable("Research",Research,({IDResearch,MeataResearch},"ID"),2,38,26,26)
- button2.setTable("Id",SwitchIdMeta,"Id",21, 38, 1, 1)
- button2.setTable("Metadata",SwitchIdMeta,"Metadata",2, 19, 1, 1)
- button2.label(3,19,tostring(IDResearch))
- button2.label(8,19,tostring(MetaResearch))
- if idMeta ~= nil then
- button2["Id"]["active"] = false
- button2["Metadata"]["active"] = false
- button2["idMeta"]["active"] = true
- end
- button2.screen()
- end
- function PressNumber(num)
- if button2["Id"]["active"] == true then
- if num == "<" then
- IDResearch = string.gsub(IDResearch,-1,1)
- else
- IDResearch = IDResearch..num
- end
- else
- if num == "<" then
- MetaResearch = string.gsub(MetaResearch,-1,1)
- else
- MetaResearch = MetaResearch..num
- end
- end
- end
- function SwitchIdMeta(o)
- IdMeta = o
- AffichageMonitorIdResearch()
- end
- function BuyItem(name)
- screen.clear()
- Item = name
- AffichageMonitorItem2(name)
- end
- function getPrice(name)
- for i = 1, #ItemPrice do
- if ItemPrice[i]["Name"] == name then
- return ItemPrice[i]["Price"]
- end
- end
- end
- function AffichageMonitorItem2(name)
- button.label(7,1,"Combien de "..name.." souhaitez-vous acheter ?")
- button.setTable("+1", addItem, 1, 8, 18, 6,6)
- button.setTable("+10", addItem, 10, 20, 30, 6, 6)
- button.setTable("+64", addItem, 64, 32, 42, 6, 6)
- button.setTable("-1", addItem, -1, 8, 18, 8, 8)
- button.setTable("-10", addItem, -10, 20, 30, 8, 8)
- button.setTable("-64", addItem, -64, 32, 42, 8 ,8)
- button.setTable("LE MAX !", addItem, 512-ItemRequested, 8, 42, 10, 10)
- button.setTable("Execute Item Request", Transaction,getPrice(name), 8, 42, 16, 18)
- button.label(7,20,"Cela vous coutera"..getPrice(name).." diamonds.")
- button.label(7, 4, "Pour l'instant vous désirez" ..tostring(ItemRequested).." "..name.." .")
- end
- function addItem(num)
- ItemRequested = ItemRequested+num
- if ItemRequested < 0 then
- ItemRequested = 0
- end
- if ItelRequested > 512 then
- ItemRequested = 512
- end
- sreen.clear()
- AffichageMonitorItem2(Item)
- end
- function nextPage()
- if page+1 <= pages then
- page = page+1
- end
- AffichageMonitorItem()
- end
- function prevPage()
- if page-1 >= 1 then
- page = page-1
- end
- AffichageMonitorItem()
- end
- function getClick()
- event, side, x,y = os.pullEvent()
- if event == "monitor_touch" and side == "montitor_0" then
- button.checkxy(x,y)
- end
- end
- function getClickBis()
- event, side, x,y = os.pullEvent()
- if event == "monitor_touch" and side == "monitor_1" then
- button2.checkxy(x,y)
- end
- end
- function Openfile(mode)
- file.close()
- file = fs.open("Price",mode)
- end
- while true do
- parallel.waitForAny(getClick,getClickBis,AffichageComputer)
- end
Advertisement
Add Comment
Please, Sign In to add comment