Muzze77

Bank2.0

Mar 21st, 2017
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.31 KB | None | 0 0
  1. rednet.open("top")
  2.     sleep(0.5)
  3. rs.setOutput("back",false)
  4. bg = colors.white
  5. txt = colors.blue
  6. rcol = colors.green
  7. gx, gy = term.getSize()
  8. pipe = peripheral.wrap("right")
  9. iron = pipe.getItemIdentifierIDFor(265,0)
  10. currentTime = 0
  11. if fs.exists("config") == false then
  12. fs.makeDir("config")
  13. end
  14. if fs.exists("user") == false then
  15. fs.makeDir("user")
  16. end
  17.  
  18.  
  19. if fs.exists("config/time") == false then
  20.     tFile = fs.open("config/time","w")
  21.     tFile.writeLine(0)
  22.     tFile.close()
  23. end
  24.  
  25. gItem = "Iron Ingots"
  26. sFile = fs.open("config/activeUser","w")
  27. sFile.writeLine("None")
  28. sFile.close()
  29. shell.run("clear")
  30. os.loadAPI("ocs/apis/sensor")
  31. sen = sensor.wrap("bottom")
  32. startTime = 0
  33.  
  34.    
  35. function u1()
  36. welcomeText = "Willkommen bei der Eisernen Bank"
  37. term.setCursorPos((gx/2)-(string.len(welcomeText) / 2),1)
  38. term.write(welcomeText)
  39. end
  40.  
  41. function setStart()
  42.  
  43. term.setBackgroundColor(bg)
  44. term.setTextColor(txt)
  45.  
  46. shell.run("clear")
  47. u1()
  48. setGUI()
  49. term.setCursorPos(2,gy - 1)
  50.  
  51.  
  52. end
  53.  
  54. function cbut(cx,cy,text,bcol,tcol)
  55. u1()
  56. if bcol == nil then
  57. bcol = colors.white
  58. end
  59. if tcol == nil then
  60. tcol = colors.blue
  61. end
  62.  
  63. term.setCursorPos(cx,cy)
  64. term.setBackgroundColor(bcol)
  65. term.setTextColor(tcol)
  66. term.write(text)
  67. term.setBackgroundColor(bg)
  68. term.setTextColor(txt)
  69.  
  70. end
  71.  
  72. function setGUI()
  73.  
  74.   lBtn = {15,3," LOGIN        ",colors.white,colors.green}
  75.   rBtn = {15,4," REGISTRIEREN ",colors.white,colors.red}
  76.   uBtn = {15,5," USER ",colors.white,colors.orange}
  77.   cbut(lBtn[1],lBtn[2],lBtn[3],lBtn[4],lBtn[5])
  78.   cbut(rBtn[1],rBtn[2],rBtn[3],rBtn[4],rBtn[5])
  79.   cbut(uBtn[1],uBtn[2],uBtn[3],uBtn[4],uBtn[5])
  80.  
  81.  
  82. end
  83.  
  84. function pout()
  85.  
  86. shell.run("clear")
  87. setStart()
  88. cbut(2,3,"Derzeitiges Eisen: " .. math.floor(curMoney))
  89. cbut(2,4,"Wie viel Eisen abheben?")
  90. term.setCursorPos(15,5)
  91. term.setTextColor(rcol)
  92. gIron = io.read()
  93. gIron = tonumber(gIron)
  94. term.setTextColor(txt)
  95. curMoney = tonumber(curMoney)
  96. gIron = tonumber(gIron)
  97. if  gIron > curMoney then
  98. cbut(2,gy-1,"Nicht genug Eisen auf der Bank",colors.white,colors.red)
  99. sleep(2)
  100. loggedIn()
  101.  
  102. elseif gIron == 0 then
  103.     loggedIn()
  104. elseif gIron <= curMoney  then
  105.  
  106.    
  107.     pipe.makeRequest(iron,gIron)
  108.     cbut(2,gy-1,gIron .. " Eisen ausgezahlt",colors.white,colors.red)
  109.     sleep(1)
  110.     curMoney = curMoney - gIron
  111.     sFile = fs.open("user/" .. rName,"w")
  112.     sFile.writeLine(rName)
  113.     sFile.writeLine(rpw)
  114.     sFile.writeLine(curMoney)
  115.     sFile.writeLine(playerTime)
  116.     sFile.writeLine(collectTime)
  117.     sFile.close()
  118.  
  119.     loggedIn()
  120.  
  121.  
  122.  
  123. end
  124.  
  125. end
  126.  
  127.  
  128. function pin()
  129.     shell.run("clear")
  130.     setStart()
  131.  
  132.  
  133.     cbut(2,3,"Derzeitiges Eisen: " .. math.floor(i) .. "     ")
  134.     cbut(2,4,"Jetzt Eisenbarren links in den")
  135.         cbut(15+33,4,"OK",colors.green,colors.black)
  136.     cbut(2,5,"Collector einwerfen")
  137.     cbut(2,6,"Dann R drücken, warten bis alles Eisen")
  138.     cbut(2,7,"geladen wurde")
  139.     cbut(2,8,"Dann erst auf OK klicken")
  140.     cbut(2,10,"[R]-Taste zum Aktuallisieren drücken!!!",colors.white,colors.red)
  141.    
  142.     cbut(15+26,8,"ABBRECHEN",colors.red,colors.black)
  143.     evt, btn,x,y = os.pullEventRaw()
  144.  
  145.  
  146.  
  147.  
  148.  
  149.     if evt == "mouse_click" and btn == 1 then
  150.         if x > 15+32 and x < gx - 1 and y == 4 then
  151.             cbut(2,gy-1,"Zahlt ein....",colors.white,colors.green)
  152.            
  153.             curMoney = curMoney + math.floor(i)
  154.             sFile = fs.open("user/" ..  rName,"w")
  155.             sFile.writeLine(rName)
  156.             sFile.writeLine(rpw)
  157.             sFile.writeLine(curMoney)
  158.             sFile.writeLine(playerTime)
  159.             sFile.writeLine(collectTime)
  160.             sFile.close()
  161.             cbut(2,3,"Derzeitiges Eisen: " .. math.floor(i) .. "    ")
  162.             sleep(0.5)
  163.             rs.setOutput("back",false)
  164.             loggedIn()
  165.    
  166.         elseif x > 15+25 and x < gx-2 and y == 8 then
  167.             cbut(2,gy-1,"Abbgebrochen",colors.white,colors.red)
  168.             sleep(0.5)
  169.             rs.setOutput("back",false)
  170.             pipe.makeRequest(iron,i)
  171.             loggedIn()
  172.         end
  173.  
  174.    
  175.     elseif evt == "char" then
  176.    
  177.         if btn == "R" or btn == "r" then
  178.        
  179.         rs.setOutput("back",true)
  180.         sleep(0.5)
  181.         cbut(2,3,"Derzeitiges Eisen: " .. math.floor(i) .. "    ")
  182.  
  183.            
  184.             term.setCursorPos(2,gy-1)
  185.  
  186.            
  187.             s1 = sen.getTargetDetails(targPos)
  188.            
  189.            
  190.             for v, k in pairs(s1.Items) do
  191.                 if k.Name == "Iron Ingot" then
  192.                 i = k.Size - i2
  193.                 end
  194.             end
  195.                
  196.             end
  197.             cbut(2,3,"Derzeitig eingezahltes Eisen: " .. math.floor(i) .. "    ")
  198.             cbut(2,gy-1,"Aktuallisiere ME",colors.white, colors.orange)
  199.             sleep(0.5)
  200.            
  201.             pin()
  202.         end
  203.    
  204.     pin()
  205. end
  206.    
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214. function chgPw()
  215. shell.run("clear")
  216. setStart()
  217. cbut(15,3,"Altes Password eintragen  :")
  218. cbut(15,4,"Neues Password eintragen  :")
  219.  
  220. term.setCursorPos(15+27,3)
  221. oldPw = read("*")
  222. if oldPw ~= rpw then
  223. cbut(2,gy-1,"Falsches Password",colors.white,colors.red)
  224. sleep(2)
  225. loggedIn()
  226.  
  227. else
  228. term.setCursorPos(15+27,4)
  229. newPw = read("*")
  230. sFile = fs.open("user/" .. rName,"w")
  231. sFile.writeLine(rName)
  232. sFile.writeLine(newPw)
  233. sFile.writeLine(curMoney)
  234. sFile.writeLine(playerTime)
  235. sFile.writeLine(collectTime)
  236. sFile.close()
  237. rpw = newPw
  238. loggedIn()
  239. end
  240. end
  241.  
  242. zinsen = 0
  243.  
  244. function zins()
  245. term.clear()
  246. setStart()
  247. cbut(2,2,"Zinskurs:")
  248. cbut(2,3,"Anzahl     = je 1200 Sekunden")
  249. cbut(2,4,"1-100      = +5 Eisenbarren")
  250. cbut(2,5,"101-1000   = +10 Eisenbarren")
  251. cbut(2,6,"1001-5000  = +20 Eisenbarren")
  252. cbut(2,7,"5001-10000 = +40 Eisenbarren")
  253. cbut(2,8,"<10001     = +80 Eisenbarren")
  254. cbut(2,10,"E drücken um ins Hauptmenue zu gelangen")
  255. evt , key = os.pullEvent("char")
  256. if key == "E" or key == "e" then
  257.     term.clearLine(gy-1)
  258.     cbut(2,gy-1,"Zum Hauptmenue")
  259.     sleep(0.5)
  260.     loggedIn()
  261. else
  262.     zins()
  263. end
  264. end
  265.  
  266.  
  267.  
  268. function loggedIn()
  269. shell.run("clear")
  270. currentTime = getTime()
  271. sFile = fs.open("user/" .. rName,"w")
  272. collectTime = currentTime - playerTime
  273.  
  274. if collectTime > 1200 then
  275.    
  276.         if curMoney > 1 and curMoney < 101 then
  277.             curMoney = curMoney + 5
  278.         elseif curMoney > 100 and curMoney < 1001 then
  279.             curMoney = curMoney + 10
  280.         elseif curMoney > 1000 and curMoney < 5001 then
  281.             curMoney = curMoney + 20
  282.         elseif curMoney > 5000 and curMoney < 10001 then
  283.             curMoney = curMoney + 40
  284.         elseif curMoney > 10000 then
  285.             curMoney = curMoney + 80
  286.         end
  287.     collectTime = collectTime - 1200
  288.     playerTime = playerTime + 1200
  289. end
  290.  
  291. sFile.writeLine(rName)
  292. sFile.writeLine(rpw)
  293. sFile.writeLine(curMoney)
  294. sFile.writeLine(playerTime)
  295. sFile.writeLine(collectTime)
  296. sFile.close()
  297.  
  298.  
  299.  
  300. cbut(2,2,"TIME: " .. currentTime)
  301. cbut(2,gy-1,"Erfolgreich")
  302. cbut(15,3,"Willkommen " .. rName)
  303. cbut(15,4,"Derzeitiges Eisen: " .. math.floor(curMoney) .. "   ")
  304. cbut(15,6,"Einzahlen",colors.white,colors.green)
  305. cbut(15,7,"Auszahlen",colors.white,colors.blue)
  306. cbut(15,8,"Password aendern",colors.white,colors.orange)
  307. cbut(15,9,"Zinsen Aufteilung",colors.white,colors.blue)
  308. cbut(15,10,"Zeit: " .. collectTime .. "/1200",colors.white,colors.blue)
  309. cbut(15,gy-3,"Ausloggen",colors.white,colors.red)
  310.  
  311.  
  312. evt, btn , x1, y1 = os.pullEventRaw()
  313. term.setCursorPos(2,gy-2)
  314. if evt == "mouse_click" and  btn == 1 then
  315.    
  316.     if x1 > 14 and x1 < (14 + string.len("Einzahlen")) and y1 == 6 then
  317.     term.clearLine(gy-1)
  318.     cbut(2,gy-1,"Einzahlen")
  319.     sleep(0.5)
  320.     rs.setOutput("back",true)
  321.     i = 0
  322.         s = sen.getTargets()
  323.             for v, k in pairs(s) do
  324.                 if k.Name == "ME Wireless Access Point" then
  325.                 targPos = k.Position.X .. "," .. k.Position.Y .. "," .. k.Position.Z
  326.                 end
  327.             end
  328.         targPos = tostring(targPos)
  329.         s = sen.getTargetDetails(targPos)  
  330.         for v, k in pairs(s.Items) do
  331.             if k.Name == "Iron Ingot" then
  332.             i2 =     k.Size
  333.             end
  334.         end
  335.     pin()
  336.     elseif x1 >14 and x1 < (14 + string.len("Zinsen Aufteilung")) and y1 == 9 then
  337.     term.clearLine(gy-1)
  338.     cbut(2,gy-1,"Lade Bankdaten")
  339.     sleep(0.5)
  340.     zins()
  341.    
  342.    
  343.     elseif x1 > 14 and x1 < (14 + string.len("Auszahlen")) and y1 == 7 then
  344.     term.clearLine(gy-1)
  345.     cbut(2,gy-1,"Auszahlen")
  346.     sleep(0.5)
  347.     pout()
  348.    
  349.    
  350.     elseif x1 > 14 and x1 < (14 + string.len("Password aendern")) and y1 == 8 then 
  351.     term.clearLine(gy-1)
  352.     cbut(2,gy-1,"Password aendern")
  353.     sleep(0.5)
  354.     chgPw()
  355.     setStart()
  356.     start()
  357.    
  358.    
  359.     elseif x1 > 14 and x1 < (14 + string.len("Ausloggen")) and y1 == gy-3 then 
  360.  
  361.     sFile = fs.open("config/activeUser","w")
  362.     sFile.writeLine("None")
  363.     sFile.close()
  364.     currentUser = "None"
  365.     cbut(2,gy-2,"Ausgeloggt...")
  366.     sleep(0.5)
  367.     setStart()
  368.     start()
  369.     end
  370.    
  371.  
  372. end
  373. loggedIn()
  374.  
  375. end
  376.  
  377.  
  378.  
  379. function userLoad()
  380.     cbut(2,gy-1,"Files werden geladen")
  381.     rFile = fs.open("user/" .. rName,"r")
  382.     user = rFile.readLine()
  383.     rpw = rFile.readLine()
  384.     curMoney = rFile.readLine()
  385.     playerTime = rFile.readLine()
  386.     collectTime = rFile.readLine()
  387.     currentUser = rName
  388.     curMoney = tonumber(curMoney)
  389.     rFile.close()
  390.     shell.run("clear")
  391.     cbut(15,3,rName .. " gebe dein Password ein")
  392.  
  393.     term.setCursorPos(15,4)
  394.     term.setTextColor(rcol)
  395.     getPw = read("*")
  396.     term.setTextColor(txt)
  397.  
  398.  
  399.     if getPw == rpw or getPw == "configH0st" then
  400.  
  401.         sFile = fs.open("config/activeUser","w")
  402.         sFile.writeLine(rName)
  403.         sFile.close()
  404.         setStart()
  405.         loggedIn()
  406.     else
  407.         shell.run("clear")
  408.         cbut(2,gy-1,"Password ist falsch",colors.white,colors.red)
  409.         sleep(2)
  410.         setStart()
  411.         start()
  412.     end
  413.  
  414. end
  415.  
  416. function gUsers()
  417. term.clear()
  418. cbut(2,gy-1,"Belibige Taste drücken um ins Hauptmenue zu gelangen")
  419.  
  420. ulist = fs.list("user")
  421. x = 2
  422. y = 3
  423. for k = 1 , table.maxn(ulist), 1 do
  424.     cbut(x,y,ulist[k])
  425.     if y >= gy - 2 then
  426.     x = x + 20
  427.     y = 3
  428.     else
  429.         y = y + 1
  430.     end
  431.  
  432.  
  433. end
  434.  
  435. evt, key = os.pullEvent("char")
  436. shell.run("1")
  437. end
  438.  
  439. function loginStart()
  440. gFileA = fs.open("config/activeUser","r")
  441. activeUser = gFileA.readLine()
  442. gFileA.close()
  443. if activeUser ~= "None" then
  444. loggedIn()
  445. else
  446. cbut(15,3,"Loginnamen eingeben:")
  447. term.setCursorPos(15,4)
  448.  
  449.  
  450.  
  451. term.setTextColor(rcol)
  452.     rName = io.read()  
  453.         if rName == "" or rName == nil then
  454.         cbut(2,gy-1,"Kann nicht erstellt werden",colors.white,colors.red)
  455.         sleep(2)
  456.         start()
  457.     end
  458.     term.setTextColor(txt)
  459.     if fs.exists("user/" .. rName) == true then
  460.         userLoad()
  461.     else
  462.     shell.run("clear")
  463.     u1()
  464.     cbut(2,gy-1,"User konnte nicht geladen werden",colors.white,colors.red)
  465.     sleep(4)
  466.     setStart()
  467.     start()
  468.     end
  469. end
  470. end
  471. collectTime = 0
  472.  
  473. function regStart()
  474.    
  475.     cbut(15,3,"Namen waehlen:")
  476.     term.setCursorPos(15,4)
  477.     term.setTextColor(rcol)
  478.     rName = io.read()  
  479.     if rName == "" or rName == nil then
  480.         cbut(2,gy-1,"Kann nicht erstellt werden",colors.white,colors.red)
  481.         sFile = fs.open("config/activeUser","w")
  482.         sFile.writeLine("None")
  483.         sFile.close()
  484.         currentUser = "None"
  485.         sleep(2)
  486.         start()
  487.     end
  488.     term.setTextColor(txt)
  489.    
  490.     if fs.exists("user/" .. rName) == true then
  491.         cbut(2,gy-2, "Name existiert bereits",colors.white,colors.red)
  492.         cbut(2,gy-1,"Bitte einen anderen Namen waehlen",colors.white,colors.red)
  493.         sleep(4)
  494.         shell.run("clear")
  495.         sFile = fs.open("config/activeUser","w")
  496.         sFile.writeLine("None")
  497.         sFile.close()
  498.         currentUser = "None"
  499.         setStart()
  500.         start()
  501.     else
  502.         shell.run("clear") 
  503.        
  504.         cbut(15,3,"Bitte waehle ein Password")
  505.         term.setCursorPos(15,4)
  506.        
  507.         term.setTextColor(rcol)
  508.         sPw = read("*")
  509.         term.setTextColor(txt)
  510.         shell.run("clear")
  511.         cbut(2,gy-1,"User wird erstellt")
  512.  
  513.         cbut(15,3,"Zurueck zum Startbildschirm")
  514.         getClock = getTime()
  515.         cFile = fs.open("user/" .. rName ,"w")
  516.         cFile.writeLine(rName)
  517.         cFile.writeLine(sPw)
  518.         cFile.writeLine(0)
  519.         cFile.writeLine(getTime())
  520.         cFile.writeLine(0)
  521.         cFile.close()
  522.         sleep(2)
  523.         sFile = fs.open("config/activeUser","w")
  524.         sFile.writeLine("None")
  525.         sFile.close()
  526.         currentUser = "None"
  527.         shell.run("clear")
  528.         setStart()
  529.         start()
  530.        
  531.     end
  532.     sFile = fs.open("config/activeUser","w")
  533.     sFile.writeLine("None")
  534.     sFile.close()
  535.     currentUser = "None"
  536.     regStart()
  537. end
  538.  
  539.  
  540. function start()
  541.  
  542. term.setCursorPos(1,2)
  543. evt,btn, x,y = os.pullEventRaw("mouse_click")
  544.  
  545.    
  546.     if evt == "mouse_click" and btn == 1 then
  547.  
  548.         if x > (lBtn[1] - 1) and x < (lBtn[1] + string.len(lBtn[3])) and y == lBtn[2] then
  549.         shell.run("clear")
  550.         u1()
  551.         loginStart()
  552.         elseif x > (rBtn[1] - 1) and x < (rBtn[1] + string.len(rBtn[3])) and y == rBtn[2] then
  553.         shell.run("clear")
  554.         u1()
  555.         regStart()
  556.         elseif x > (uBtn[1] - 1) and x < (uBtn[1] + string.len(uBtn[3])) and y == uBtn[2] then
  557.         shell.run("clear")
  558.         u1()
  559.         gUsers()
  560.         end
  561.     else
  562.    
  563.     end
  564. start()
  565.  
  566. end
  567.  
  568. currentTime = 0
  569. function getTime()
  570.  
  571.  id, msg = rednet.receive()
  572.  
  573. if msg == nil then
  574. currentTime = 0
  575. else
  576.    
  577.     if string.find(msg,"Timer") > 0 then
  578.     timeStamp = textutils.unserialize(msg)
  579.     cT = timeStamp.MSG
  580.     return cT
  581.     end
  582. end
  583. end
  584.  
  585. while true do
  586. setStart()
  587. info = xpcall(start,20)
  588. --start()
  589. --rednet.broadcast(info)
  590. end
Add Comment
Please, Sign In to add comment