Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- uu = 0
- pipe = peripheral.wrap("bottom")
- mon = peripheral.wrap("top")
- mon.setTextScale(0.5)
- gx, gy = mon.getSize()
- mon.clear()
- bank = "bank"
- users = {}
- users = {["Count"] = 0}
- firstRun = 0
- minUser = "NONE"
- minUserMoney = 0
- auszahlen = 0
- einzahlen = 0
- ueberweisen = 0
- state = "NONE"
- sx = 0
- sy = 0
- tag = {"EINZAHLEN","AUSZAHLEN","UEBERWEISEN"}
- calc = 0
- function save(tab)
- f = fs.open(bank,"w")
- f.write(textutils.serialize(tab))
- f.close()
- end
- function load()
- f = fs.open(bank,"r")
- tab = f.readAll()
- f.close()
- return textutils.unserialize(tab)
- end
- if ( fs.exists("bank")) then
- users = load()
- else
- save(users)
- end
- function setUser(usr)
- users = load()
- math.randomseed(os.time())
- id = math.floor(math.random()*10) .. math.floor(math.random()*10) .. math.floor(math.random()*10) .. math.floor(math.random()*10) .. "-" .. math.floor(math.random()*10) .. math.floor(math.random()*10) .. math.floor(math.random()*10) .. math.floor(math.random()*10)
- c = 0
- if (users.Count ~= 0) then
- for v, k in pairs(users) do
- if (v ~= "Count") then
- if (v == usr) then
- c= c + 1
- end
- end
- end
- else
- end
- if usr ~= "NONE" then
- if (c == 0) then
- if disk.isPresent("front") then
- f = fs.open("disk/ID","w")
- f.write(id)
- f.close()
- end
- users[usr] = {}
- users[usr]["Money"] = 0
- users[usr]["ID"] = id
- users.Count = users.Count + 1
- save(users)
- cbut(2,gy," ")
- cbut(2,gy,"User wurde erstellt")
- sleep(2)
- else
- end
- end
- save(users)
- return users
- end
- function getUser()
- cbut(2,gy," ")
- cbut(2,gy,"Warten auf User")
- if disk.isPresent("front") then
- disk.eject("front")
- end
- evt,side = os.pullEvent("disk")
- minUser = disk.getLabel("front")
- gusr = disk.getLabel("front")
- if gusr == nil then
- disk.eject("front")
- shell.run("reboot")
- end
- users = setUser(gusr)
- save(users)
- f = fs.open("disk/ID","r")
- id = f.readAll()
- f.close()
- if (id == nil or users[minUser].ID == nil) then
- minUser = "NONE"
- else
- if (id ~= users[minUser].ID) then
- cbut(2,gy," ")
- cbut(2,gy,"Falsche ID: " .. minUser)
- minUser = "NONE"
- sleep(2)
- cbut(2,gy," ")
- else
- cbut(2,gy," ")
- cbut(2,gy,"User wurde geladen")
- sleep(2)
- minUser = gusr
- minUserMoney = users[minUser].Money
- end
- end
- disk.eject("front")
- if minUser == nil then
- minUser = "NONE"
- end
- return minUser
- end
- uID = 0
- new = 0
- function getUU()
- pipe.getAvailableItems()
- evt , items = os.pullEvent("available_items_return")
- count = 0
- for v, k in pairs(items) do
- name = pipe.getItemName(k[1])
- if name == "UU-Matter" then
- uID = k[1]
- count = count + k[2]
- end
- end
- return count
- end
- function cbut(cx,cy,text)
- mon.setCursorPos(cx,cy)
- mon.write(text)
- end
- function uu_bank()
- mon.clear()
- cbut(2,2," ")
- cbut(2,2,"UU-Matter in Bank: " .. getUU())
- end
- function addMoney()
- money = {}
- money["Max"] = 0
- repeat
- old = getUU()
- uu_bank()
- cbut(2,5," ")
- cbut(2,5,"USER: " .. minUser)
- cbut(2,6," ")
- cbut(2,6,"UU-Matter USER: " .. string.format("%d",minUserMoney))
- cbut(2,8," ")
- cbut(2,8,tag[1] .. " <<")
- cbut(2,10," ")
- cbut(2,10,"R [" )
- cbut(8,10,string.format("%d",money["Max"]) )
- cbut(19,10,"] OK")
- evt,a,b,c = os.pullEvent("monitor_touch")
- uu = getUU()
- calc = uu - old
- if calc ~= 0 then
- money["Max"] = money["Max"] + calc
- end
- if b == 22 or b == 23 and c == 10 then
- users[minUser]["Money"] = users[minUser]["Money"] + money["Max"]
- term.setCursorPos(1,5)
- minUserMoney = users[minUser]["Money"]
- save(users)
- calc = 0
- einzahlen = 0
- state = "NONE"
- end
- cbut(2,gy-1,"X:" .. string.format("%d", b))
- cbut(8,gy-1,"Y:" .. string.format("%d", c))
- until (not(einzahlen > 0))
- end
- function bank_activate()
- if state == "NONE" then
- cbut(2,8," ")
- cbut(2,8,"EINZAHLEN")
- cbut(20,8," ")
- cbut(20,8,"AUSZAHLEN")
- cbut(40,8," ")
- cbut(40,8,"UEBERWEISEN")
- elseif state == "+" then
- cbut(2,8," ")
- cbut(2,8,tag[1] .. " <<")
- cbut(2,10," ")
- cbut(2,10,"R [" )
- cbut(8,10,string.format("%d",calc) )
- cbut(19,10,"] OK")
- elseif state == "-" then
- cbut(20,8," ")
- cbut(20,8,tag[2] .. " <<")
- cbut(2,10," ")
- cbut(2,10,"<51 [" )
- cbut(8,10,string.format("%d",calc) )
- cbut(19,10,"] 15>")
- elseif state == ">>" then
- cbut(40,8," ")
- cbut(40,8,tag[3] .. " <<")
- cbut(2,10," ")
- cbut(2,10,"<51 [" )
- cbut(8,10,string.format("%d",calc) )
- cbut(19,10,"] 15>")
- cbut(2,gy,"Noch gesperrt")
- end
- cbut(gx-7,1,"LOGOUT")
- end
- while true do
- term.setCursorPos(1,1)
- print("###>INIT USERS<###")
- print("###" .. textutils.serialize(users) .. "###")
- print("###<INIT USERS>###")
- term.setCursorPos(1,6)
- uu_bank()
- uu = getUU()
- cbut(2,5," ")
- cbut(2,5,"USER: " .. minUser)
- cbut(2,6," ")
- cbut(2,6,"UU-Matter USER: " .. string.format("%d",minUserMoney))
- cbut(2,gy-1,"X:" .. string.format("%d", sx))
- cbut(8,gy-1,"Y:" .. string.format("%d", sy))
- if minUser == "NONE" or uu < 1 then
- cbut(2,gy-2," ")
- cbut(2,gy-2,"Bank Deaktiviert")
- else
- cbut(2,gy-2," ")
- cbut(2,gy-2,"Bank Aktiviert ")
- bank_activate()
- end
- if minUser == "NONE" then
- minUser = getUser()
- else
- cbut(2,gy," ")
- end
- if (disk.isPresent("front")) then
- disk.eject("front")
- end
- if (firstRun ~= 0) then
- evt ,a,b,c = os.pullEvent()
- if (evt == disk) then
- disk.eject("front")
- end
- if evt == "monitor_touch" then
- sx = b
- sy = c
- if minUser ~= "NONE" then
- print(minUser)
- term.setCursorPos(1,7)
- if b >= gx-7 and b < gx and c == 1 then
- cbut(2,gy," ")
- cbut(2,gy,minUser .. " hat sich ausgelogt")
- minUser = "NONE"
- minUserMoney = 0
- elseif (b >= 2 and b < 2+ string.len(tag[1]) and c == 8 and state == "NONE") then
- state = "+"
- einzahlen = 1
- addMoney()
- elseif (b >= 20 and b < 20+ string.len(tag[2]) and c == 8 and state == "NONE") then
- state = "-"
- elseif (b >= 40 and b < 40+ string.len(tag[3]) and c == 8 and state == "NONE") then
- state = ">>"
- elseif (b>= 2+ string.len(tag[1])+1 and b< 2+ string.len(tag[1])+3 and c == 8 and state == "+") then
- state = "NONE"
- elseif (b>= 20+ string.len(tag[2])+1 and b< 20+ string.len(tag[2])+3 and c == 8 and state == "-") then
- state = "NONE"
- elseif (b>= 40+ string.len(tag[3])+1 and b< 40+ string.len(tag[3])+3 and c == 8 and state == ">>") then
- state = "NONE"
- elseif (b == 2 and c == 10 and state ~= "NONE") then
- if (state == "-" or state == ">>" ) then
- calc = 0
- print("MIN")
- end
- elseif (b == 3 and c == 10 and state ~= "NONE") then
- if (state == "-" or state == ">>") then
- calc = calc - 5
- if calc < 0 then
- calc = 0
- end
- print("-5 ")
- end
- elseif (b == 4 and c == 10 and state ~= "NONE") then
- if (state == "-" or state == ">>") then
- calc = calc - 1
- if calc < 0 then
- calc = 0
- end
- print("-1 ")
- end
- elseif (b == 21 and c == 10 and state ~= "NONE") then
- if (state == "-" or state == ">>") then
- calc = calc + 1
- if calc > minUserMoney and (state == "-" or state == ">>") then
- calc = minUserMoney
- end
- print("+1 ")
- end
- elseif (b == 22 and c == 10 and state ~= "NONE") then
- if (state == "-" or state == ">>") then
- calc = calc + 5
- if calc > minUserMoney then
- calc = minUserMoney
- end
- print("+5 ")
- end
- elseif (b == 23 and c == 10 and state ~= "NONE") then
- if (state == "-" or state == ">>") then
- calc = minUserMoney
- print("MAX")
- end
- elseif (b >= 6 and b <= 19 and c == 10) then
- if (state == "-" ) then
- print(uID)
- pipe.makeRequest(uID,calc)
- minUserMoney = minUserMoney - calc
- users[minUser]["Money"] = users[minUser]["Money"] - calc
- save(users)
- calc = 0
- state = "NONE"
- elseif (state == "-" ) then
- cbut(2,gy,"Noch gesperrt")
- calc = 0
- state = "NONE"
- end
- end
- end
- end
- end
- firstRun = 1
- end
Add Comment
Please, Sign In to add comment