Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Edit This\/
- local Items = {{"minecraft:stone","Stone",5,2,true}} --ID/Tag,Label,AmountPerSale,Cost,Selling(true/false)
- local BankNet_En = false
- local BankKey = 0001
- --DONT TOUCH
- 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 Version = "1.2.0"
- local Storage = {}
- --Change to sides of computer for chests
- local PayChest = peripheral.wrap("top")
- local StoreChest = peripheral.wrap("bottom")
- --Your Name
- local Owner = "Marlin"
- --Company
- local Company = "WST"
- --DONT TOUCH ANYTHING BEYOND THIS
- local function start()
- for i = 1, #Items do
- local Amount = 0
- for slot, item in pairs(StoreChest.list()) do
- if item.name == Items[i][1] then Amount = Amount + item.count end
- end
- if Amount >= Items[i][3] then Storage[i] = true else Storage[i] = false end
- end
- if Receipt.CheckPrinter() == false then error("printer error") end
- Menu()
- Options()
- 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
- if (Pay + Cash) <= Target then Pay = Pay + Cash TransferItem(slot,"PayChest",1) end
- until (Pay + Cash) > Target
- end
- if Pay == Target then Pass = true end
- return Pass
- end
- local function FindStoredItem(Name,amount)
- local F = 0
- for slot, item in pairs(StoreChest.list()) do
- if item.name == Name and F ~= amount then
- if item.count >= amount then
- F = amount
- TransferItem(slot,"StoreChest",F)
- else
- end
- end
- end
- end
- function TransferItem(slot,from,amount)
- if from == "PayChest" then
- PayChest.pushItems(peripheral.getName(StoreChest),slot,amount)
- else
- StoreChest.pushItems(peripheral.getName(PayChest),slot,amount)
- end
- end
- local function PurchaseLoad(item,price,amount)
- local Total = price + (price * GovEc.GetTax("sales"))
- if CountCash(Total) == true then
- print("Correct Amount")
- if TakePayment(Total) == true then
- FindStoredItem(item,amount)
- Receipt.PrintReceipt(Company,"Commercial Purchase","Purchase Receipt","n",{{item,amount,price}})
- end
- end
- end
- function Buy(I)
- print("loading...")
- if Items[I][5] == true then
- if BankNet_En == true then
- print("1 - Cash, 2 - Debit")
- local a, b
- repeat
- a, b = os.pullEvent("key")
- until b == keys.one or b == keys.two
- if b == keys.one then PurchaseLoad(Items[I][1],Items[I][4],Items[I][3]) elseif b == keys.two then if BankNet.charge(BankKey,Items[I][4])[1] == true then FindStoredItem(Items[I][1],Items[I][3]) Receipt.PrintReceipt(Company,"Commercial Purchase","Purchase Receipt","n",{{Items[I][2],Items[I][3],Items[I][4]}}) end end
- else
- PurchaseLoad(Items[I][1],Items[I][4],Items[I][3])
- end
- else
- error("Buying System not Implemented in Current Version, Contact Administrator for More Info")
- end
- end
- function Menu()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- print(Company.." Shop - "..Owner.." - V"..Version)
- end
- function Options()
- local n = 0
- local T = 1
- local a, b, c
- local Printed_Selling = {}
- local Printed_Buying = {}
- for i = 1, #Items do
- if Items[i][5] == true and Storage[i] == true then Printed_Selling[#Printed_Selling + 1] = {i,Items[i][2].." x"..Items[i][3].." - $"..(Items[i][4]+(Items[i][4]*GovEc.GetTax("sales")))} elseif Items[i][5] == true and Storage[i] == false then Printed_Selling[#Printed_Selling + 1] = {i,Items[i][2].." x"..Items[i][3].." - OUT OF STOCK"} end
- end
- local Gap = #Printed_Selling + 300
- print("==Selling==")
- repeat
- for i = 1, #Items do
- if i + 2 < Gap then term.setCursorPos(1,i + 2) else term.setCursorPos(1,i + 3) end
- term.clearLine()
- if T == i and i + 2 < Gap then term.write(">> "..Printed_Selling[i][2]) elseif i + 2 < Gap then term.write(Printed_Selling[i][2]) end
- end
- a, b, c = os.pullEvent("key")
- if b == keys.w and T > 1 then T = T - 1 end
- if b == keys.s and T < #Items then T = T + 1 end
- if b == keys.enter then n = T end
- until n ~= 0
- if Storage[n] == true then Buy(Printed_Selling[n][1]) end
- end
- while true do
- start()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement