Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Folder = "LandPlots"
- local w, h = term.getSize()
- local Plots = {}
- local TileColors = {colors.green,colors.red,colors.blue}
- local Payment = {{"currency:dollar_bill",1},{"currency:ten_dollar_bill",10},{"currency:twenty_dollar_bill",20},{"currency:fifty_dollar_bill",50},{"currency:hundred_dollar_bill",100}}
- local PayChest = peripheral.wrap("top")
- local StoreChest = peripheral.wrap("bottom")
- local Printer = peripheral.wrap("right")
- local TaxRate = 0.01
- local Plot_Prices = {200,400,600}
- local function Start()
- if Printer.getPaperLevel() > 0 then Map() else error("low supplies, contact administrator") end
- end
- local function PrintReceipt(Pl,Cost)
- local Layout = {"Proof of Purchase",os.date(),"Deed to the chunk of "..Plots[Pl][1].." "..Plots[Pl][2],"Paid $"..Cost,"//Do not give away//","please keep in safe spot","Government issued Receipt"}
- Printer.newPage()
- for i = 1, #Layout do
- Printer.write(Layout[i])
- end
- Printer.setPageTitle("Deed for Plot #"..Pl)
- Printer.endPage()
- end
- local function GetPlots()
- local plots = fs.list(Folder)
- for i = 1, #plots do
- local file = fs.open(fs.combine(Folder,plots[i]),"r")
- Plots[i] = textutils.unserialize(file.readAll())--chunkx,chunky,owner,mapx,mapy,type
- file.close()
- end
- end
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function CurrencyCheck(name)
- local Worth = 0
- for i = 1, #Payment do
- if name == Payment[i][1] then Worth = Payment[i][2] end
- end
- return Worth
- end
- local function CountCash(Target)
- local Pay = 0
- for slot, item in pairs(PayChest.list()) do
- Pay = Pay + (CurrencyCheck(item.name) * item.count)
- end
- Pass = false
- if Pay >= Target then Pass = true end
- return Pass
- end
- local function TakePayment(Target)
- local Pay = 0
- Pass = false
- for slot, item in pairs(PayChest.list()) do
- local Cash = CurrencyCheck(item.name)
- repeat
- TransferItem(slot,1)
- if (Pay + Cash) <= Target then Pay = Pay + Cash end
- until (Pay + Cash) > Target
- end
- if Pay == Target then Pass = true end
- return Pass
- end
- function TransferItem(slot,amount)
- PayChest.pushItems(peripheral.getName(StoreChest),slot,amount)
- end
- local function PurchaseLoad(Pl,price)
- if CountCash(price) == true then
- print("Correct Amount")
- if TakePayment(price) == true then
- print("printing receipt, please take with you")
- PrintReceipt(Pl,price)
- os.sleep(3)
- UpdatePlot(Pl)
- end
- end
- end
- local function UpdatePlot(Pl)
- local Data = Plots[Pl]
- Data[3] = 2
- local plots = fs.list(Folder)
- local file = fs.open(fs.combine(Folder,plots[i]),"w")
- file.write(textutils.serialize(Data))
- file.close()
- os.reboot()
- end
- local function PurchaseMenu(Pl)
- Clear()
- local Cost = Plot_Prices[Plots[Pl][6]] + (Plot_Prices[Plots[Pl][6]] * TaxRate)
- print("Chunk x"..Plots[Pl][1].." y"..Plots[Pl][2])
- print("price $"..Plot_Prices[Plots[Pl][6]])
- print("taxes $"..Plot_Prices[Plots[Pl][6]]*TaxRate)
- print("total $"..Cost)
- print("y/n")
- print("y purchase")
- print("n cancel")
- local e, k
- repeat
- e, k = os.pullEvent("key")
- until k == keys.y or k == keys.n
- if k == keys.y then
- PurchaseLoad(Pl,Cost)
- else
- Map()
- end
- end
- function Map()
- GetPlots()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- Clear()
- print("chunks for Sale")
- for i = 1, #Plots do
- paintutils.drawPixel(Plots[i][4],Plots[i][5],TileColors[Plots[i][3]])
- end
- term.setBackgroundColor(colors.black)
- local e, a, x, y
- repeat
- e, a, x, y = os.pullEvent("mouse_click")
- until e == "mouse_click"
- local I
- for i = 1, #Plots do
- if x == Plots[i][4] and y == Plots[i][5] and Plots[i][3] == 1 then
- I = i
- end
- end
- if I ~= nil then PurchaseMenu(I) else Map() end
- end
- Start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement