Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this is a vending system for shops
- --Client settings
- local Shopping_Mode = "Dispenser"--Dispenser mode only allows up to 3 different Product types, Digi mode is more expensive but allows for almost infinite Product types
- Products_Name = {}
- Products_Tag = {}
- Products_Price = {}
- SalesTax = 0.02
- --System Var
- CompanyName = "example"
- TerminalExitCode = "0000"
- local w, h = term.getSize()
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function CenterText(y,text)
- local x = math.floor((w - string.len(text)) /2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write(text)
- end
- local function Setup()
- settings.load(".settings")
- Shopping_Mode = settings.get("ShopMode")
- Products_Name = {settings.get("ShopProducts_Name")}
- Products_Tag = {settings.get("ShopProducts_Tag")}
- Products_Price = {settings.get("ShopProducts_Price")}
- TerminalExitCode = settings.get("exitCode")
- CompanyName = settings.get("CompanyName")
- end
- function PurchaseRequest(CardData,item)
- local Details = {CardData}
- local TransferDetails
- local ClientID = Details[1]
- local ClientProtocol = Details[2]
- local Costs = Products_Price[item] * -1
- TransferDetails = {Costs,Products_Name[item],"Banking"}
- rednet.send(ClientID,TransferDetails,ClientProtocol)
- local Response
- repeat
- Response = {rednet.recieve(ClientProtocol)}
- until Response[1] == ClientID and (Response[2] == "Accepted" or Response[2] == "Declined") == true
- if Response[2] == true then
- return(true)
- else
- return(false)
- end
- end
- function DispenseProduct(item)
- if Shopping_Mode == "Dispenser" then
- if item == 1 then redstone.setOutput("top",true) redstone.setOutput("top",false) end
- if item == 2 then redstone.setOutput("right",true) redstone.setOutput("right",false) end
- if item == 3 then redstone.setOutput("bottom",true) redstone.setOutput("bottom",false) end
- elseif Shopping_Mode == "Digi" then
- end
- Display_MMenu()
- end
- function Display_MMenu()
- Clear()
- CenterText(1,"===Shopping=Terminal===")
- CenterText(2,"Provided by "..CompanyName)
- CenterText(4,"--Products--")
- local Column = 1
- local Width = w/3
- for i = 1, #Products_Name do
- term.setCursorPos(Column*Width,i+4)
- term.write(i..">"..Products_Name[i].." $"..Products_Price[i])
- end
- Interaction_MMenu()
- end
- local function TransferCredit(item)
- local GovCredits = Products_Price[item] * SalesTax
- local OwnerCredits = Products_Price[item] - GovCredits
- local GovFile = fs.open(".Gov_24124","a")
- local TotalGov = GovFile.readLine()
- TotalGov = TotalGov + GovCredits
- GovFile.Clear()
- GovFile.writeLine(TotalGov)
- GovFile.writeLine(os.date())
- GovFile.close()
- local OwnerFile = fs.open("OwnerFile","a")
- local OwnerTotal = OwnerFile.readLine()
- OwnerFile.clear()
- OwnerFile.writeLine(OwnerTotal)
- OwnerFile.writeLine(os.date())
- OwnerFile.close()
- end
- function Display_PurchaseMenu(item)
- Clear()
- CenterText(3,"Purchasing "..Products_Name[item])
- CenterText(4,"$"..Products_Price[item])
- CenterText(5,"y/n")
- local event
- repeat
- event = {os.pullEvent("key")}
- until event[2] == keys.y or event[2] == keys.n
- if event[2] == keys.n then
- Display_MMenu()
- else
- Clear()
- CenterText(h/2,"Please Swipe Card")
- repeat
- event = {os.pullEvent()}
- until (event[1] == "key" and event[2] == keys.c) == true or (event[1] == "mag_swipe") == true
- if event[1] == "key" and event[2] == keys.c then
- else
- if PurchaseRequest(event[4],Products_Price[item]) == true then
- TransferCredit(item)
- DispenseProduct(item)
- else
- Display_MMenu()
- end
- end
- end
- end
- function OwnerCollectMenu()
- Clear()
- local TotalProfits
- local file = fs.open("OwnerFile","a")
- TotalProfits = file.readLine()
- print("Profits = $"..TotalProfits)
- print("Please Swipe Card to Collect")
- local event
- repeat
- event = {os.pullEvent("mag_swipe")}
- until event[1] == "mag_swipe"
- if PurchaseRequest(event[4],Products_Price[item]) == true then
- file.clear()
- file.writeLine(0)
- file.writeLine(os.date())
- file.close()
- AdminMenu()
- end
- end
- function AdminMenu()
- Clear()
- print("=======ADMINMENU========")
- print("--Options--")
- print("> 1 Collect Profits")
- print("> 2 Edit Products - WIP")
- print("> 3 exit")
- local event
- repeat
- event = {os.pullEvent("key")}
- until event[2] == keys.one or event[2] == keys.two or event[2] == keys.three
- if event[2] == keys.one then
- OwnerCollectMenu()
- elseif event[2] == keys.two then
- ProductEdit()
- elseif event[2] == keys.three then
- Display_MMenu()
- end
- end
- function Interaction_MMenu()
- local event
- local input
- repeat
- input = read()
- event = {os.pullEvent("mouse_click")}
- until event[3] > w-4 and event[4] > h - 4 or input == TerminalExitCode
- if input == TerminalExitCode then
- AdminMenu()
- elseif input > 0 and input < #Products_Name+1 then
- Display_PurchaseMenu(input)
- else
- Display_MMenu()
- end
- end
- Setup()
- Display_MMenu()
Add Comment
Please, Sign In to add comment