Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --VARIABILI
- local lbl = "BN Credit"
- local tabr = {}
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function pinErrato()
- clear()
- print("Errore di verifica del PIN")
- print("")
- print("Premere un tasto per uscire")
- os.pullEvent("key")
- os.reboot()
- end
- function cartaNonValida()
- clear()
- print("Carta non valida o corrotta.")
- print("")
- print("Premere un tasto per uscire")
- os.pullEvent("key")
- os.reboot()
- end
- function cartaVuota()
- clear()
- print("Carta smagnetizzata o vuota.")
- print("")
- print("Premere un tasto per uscire")
- os.pullEvent("key")
- os.reboot()
- end
- m = peripheral.wrap("right") --magcard
- clear()
- print("RGBAR Oy - Distributore di Creosoto")
- print("")
- print("Inserire la carta")
- m.setInsertCardLight(true)
- za,rawcarta = os.pullEvent("mag_swipe")
- m.setInsertCardLight(false)
- if rawcarta == nil then
- cartaVuota()
- end
- tab = textutils.unserialize(rawcarta)
- if type(tab) ~= "table" then
- cartaNonValida()
- end
- if tab.t ~= "cc" then
- cartaNonValida()
- end
- if tab.e ~= "BN" then
- cartaNonValida()
- end
- credito = tonumber(tab.v)
- while true do
- print("La carta ha una disponibilità di "..credito.." IC.")
- print("")
- print("Per favore scegliere un'opzione utilizzando i tasti numerici e confermare con ENTER:")
- print("")
- print("[1] Erogare 1 vagone di creosoto - 5 IC")
- print("[2] Annullare il pagamento")
- num=tonumber(read())
- if num == 1 then
- prelievo=2
- if prelievo > credito then
- clear()
- print("Disponibilità insufficiente")
- sleep(5)
- os.reboot()
- end
- clear()
- print("Inserire nuovamente la carta per confermare il pagamento")
- tabr.t = tab.t
- tabr.e = tab.e
- tabr.p = tab.p
- tabr.v = tostring(credito - prelievo)
- ncr = textutils.serialize(tabr)
- m.setInsertCardLight(true)
- m.beginWrite(ncr,lbl)
- os.pullEvent("mag_write_done")
- m.setInsertCardLight(false)
- clear()
- print("Pompa creosoto attivata")
- print("")
- redstone.setOutput("bottom", true)
- sleep(0.25)
- redstone.setOutput("bottom", false)
- sleep(0.25)
- redstone.setOutput("bottom", true)
- sleep(0.25)
- redstone.setOutput("bottom", false)
- sleep(0.25)
- redstone.setOutput("bottom", true)
- sleep(0.25)
- redstone.setOutput("bottom", false)
- sleep(0.25)
- redstone.setOutput("bottom", true)
- sleep(0.25)
- redstone.setOutput("bottom", false)
- sleep(0.25)
- redstone.setOutput("bottom", true)
- sleep(0.25)
- redstone.setOutput("bottom", false)
- sleep(0.25)
- print("")
- print("Grazie!")
- sleep(5)
- os.reboot()
- elseif num == 2 then clear() break end
- end
- clear()
- print("Attendere")
- sleep(1)
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment