Muzze77

IronBankSys

Mar 19th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.37 KB | None | 0 0
  1. bg = colors.white
  2. txt = colors.blue
  3. rcol = colors.green
  4. gx, gy = term.getSize()
  5.  
  6.     sFile = fs.open("Config_ActiveUser","w")
  7.     sFile.writeLine("None")
  8.     sFile.close()
  9.    
  10. function u1()
  11. welcomeText = "Willkommen bei der Iron-Bank"
  12. term.setCursorPos((gx/2)-(string.len(welcomeText) / 2),1)
  13. term.write(welcomeText)
  14. end
  15.  
  16. function setStart()
  17.  
  18. term.setBackgroundColor(bg)
  19. term.setTextColor(txt)
  20.  
  21. shell.run("clear")
  22. u1()
  23. setGUI()
  24. term.setCursorPos(2,gy - 1)
  25.  
  26.  
  27. end
  28.  
  29. function cbut(cx,cy,text,bcol,tcol)
  30. u1()
  31. if bcol == nil then
  32. bcol = colors.white
  33. end
  34. if tcol == nil then
  35. tcol = colors.blue
  36. end
  37.  
  38. term.setCursorPos(cx,cy)
  39. term.setBackgroundColor(bcol)
  40. term.setTextColor(tcol)
  41. term.write(text)
  42. term.setBackgroundColor(bg)
  43. term.setTextColor(txt)
  44.  
  45. end
  46.  
  47. function setGUI()
  48.  
  49.   lBtn = {15,3," LOGIN        ",colors.white,colors.green}
  50.   rBtn = {15,4," REGISTRIEREN ",colors.white,colors.red}
  51.   cbut(lBtn[1],lBtn[2],lBtn[3],lBtn[4],lBtn[5])
  52.   cbut(rBtn[1],rBtn[2],rBtn[3],rBtn[4],rBtn[5])
  53.  
  54.  
  55.  
  56. end
  57.  
  58. function pout()
  59. shell.run("clear")
  60. setStart()
  61. cbut(15,3,"Derzeitiges Eisen: " .. math.floor(curMoney))
  62. cbut(15,4,"Wie viel Eisen abheben?")
  63. term.setCursorPos(15,5)
  64. term.setTextColor(rcol)
  65. gIron = io.read()
  66. gIron = tonumber(gIron)
  67. term.setTextColor(txt)
  68. curMoney = tonumber(curMoney)
  69. if  gIron > curMoney then
  70. cbut(2,gy-1,"Nicht genug Eisen auf der Bank",colors.white,colors.red)
  71. sleep(2)
  72. loggedIn()
  73.  
  74. elseif gIron <= curMoney  then
  75.  
  76.     for v = 1, gIron , 1 do
  77.     curMoney = curMoney - 1
  78.     cbut(15,3,"Derzeitiges Eisen: " .. curMoney)
  79.     rs.setBundledOutput("back",colors.blue)
  80.     sleep(0.3)
  81.     rs.setBundledOutput("back",0)
  82.     sleep(0.3)
  83.     end
  84.     --curMoney = curMoney - math.floor(gIron)
  85.     sFile = fs.open(rName,"w")
  86.     sFile.writeLine(rName)
  87.     sFile.writeLine(rpw)
  88.     sFile.writeLine(curMoney)
  89.     sFile.close()
  90.  
  91.  
  92. end
  93.  
  94.  
  95. end
  96.  
  97.  
  98. function pin()
  99.  
  100. shell.run("clear")
  101. setStart()
  102. cbut(15,3,"Derzeitiges Eisen: " .. math.floor(n))
  103. cbut(15,4,"Jetzt Eisenbarren einwerfen dann")
  104. cbut(15+33,4,"OK",colors.green,colors.black)
  105. cbut(15,5,"Nicht mehr als 9 Stacks!",colors.white,colors.red)
  106.  
  107. cbut(15+26,8,"ABBRECHEN",colors.red,colors.black)
  108. evt, btn,x,y = os.pullEvent()
  109.  
  110. if evt == "redstone" then
  111.  
  112. n = n + 0.5
  113. pin()
  114. elseif evt == "mouse_click" and btn == 1 then
  115.     if x > 15+32 and x < gx - 2 and y == 4 then
  116.     cbut(2,gy-1,"Eingezahlt",colors.white,colors.green)
  117.     curMoney = curMoney + math.floor(n)
  118.     sFile = fs.open(rName,"w")
  119.     sFile.writeLine(rName)
  120.     sFile.writeLine(rpw)
  121.     sFile.writeLine(curMoney)
  122.     sFile.close()
  123.     for v = 1, 10 , 1 do
  124.     cbut(15,3,"Derzeitiges Eisen: " .. math.floor(n))
  125.     rs.setBundledOutput("back",colors.green)
  126.     sleep(0.2)
  127.     rs.setBundledOutput("back",0)
  128.     sleep(0.2)
  129.     end
  130.     loggedIn()
  131.    
  132.     elseif x > 15+25 and x < gx-2 and y == 8 then
  133.     cbut(2,gy-1,"Abbgebrochen",colors.white,colors.red)
  134.     for v = 1, 10 , 1 do
  135.     cbut(15,3,"Derzeitiges Eisen: " .. math.floor(n))
  136.     rs.setBundledOutput("back",colors.red)
  137.     sleep(0.2)
  138.     rs.setBundledOutput("back",0)
  139.     sleep(0.2)
  140.     end
  141.     loggedIn()
  142.     else
  143.     pin()
  144.     end
  145. else
  146. pin()
  147. end
  148.  
  149. end
  150.  
  151.  
  152.  
  153. function chgPw()
  154. shell.run("clear")
  155. setStart()
  156. cbut(15,3,"Altes Password eintragen  :")
  157. cbut(15,4,"Neues Password eintragen  :")
  158.  
  159. term.setCursorPos(15+27,3)
  160. oldPw = read("*")
  161. if oldPw ~= rpw then
  162. cbut(2,gy-1,"Falsches Password",colors.white,colors.red)
  163. sleep(2)
  164. loggedIn()
  165.  
  166. else
  167. term.setCursorPos(15+27,4)
  168. newPw = read("*")
  169. sFile = fs.open(rName,"w")
  170. sFile.writeLine(rName)
  171. sFile.writeLine(newPw)
  172. sFile.writeLine(curMoney)
  173. sFile.close()
  174. rpw = newPw
  175. end
  176. end
  177.  
  178. function loggedIn()
  179.  
  180.  
  181.  
  182. shell.run("clear")
  183. cbut(2,gy-1,"Erfolgreich")
  184. cbut(15,3,"Willkommen " .. rName)
  185. cbut(15,4,"Derzeitiges Eisen: " .. math.floor(curMoney))
  186. cbut(15,6,"Einzahlen",colors.white,colors.green)
  187. cbut(15,7,"Auszahlen",colors.white,colors.blue)
  188. cbut(15,8,"Password aendern",colors.white,colors.orange)
  189. cbut(15,gy-2,"Ausloggen",colors.white,colors.red)
  190.  
  191. evt, btn, x1,y1 = os.pullEvent()
  192. term.setCursorPos(2,gy-1)
  193.  
  194.    
  195.    
  196.    
  197.  
  198. if evt == "mouse_click" and  btn == 1 then
  199.    
  200.     if x1 > 14 and x1 < (14 + string.len("Einzahlen")) and y1 == 6 then
  201.     term.clearLine(gy-1)
  202.     cbut(2,gy-1,"Einzahlen")
  203.     sleep(0.2)
  204.     n = 0
  205.     pin()
  206.    
  207.    
  208.     elseif x1 > 14 and x1 < (14 + string.len("Auszahlen")) and y1 == 7 then
  209.     term.clearLine(gy-1)
  210.     cbut(2,gy-1,"Auszahlen")
  211.     sleep(0.2)
  212.     pout()
  213.    
  214.    
  215.     elseif x1 > 14 and x1 < (14 + string.len("Password aendern")) and y1 == 8 then 
  216.     term.clearLine(gy-1)
  217.     cbut(2,gy-1,"Password aendern")
  218.     sleep(0.2)
  219.     chgPw()
  220.     setStart()
  221.     start()
  222.    
  223.    
  224.     elseif x1 > 14 and x1 < (14 + string.len("Ausloggen")) and y1 == gy-2 then 
  225.  
  226.     sFile = fs.open("Config_ActiveUser","w")
  227.     sFile.writeLine("None")
  228.     sFile.close()
  229.     cbut(2,gy-2,"Ausgeloggt...")
  230.     sleep(0.2)
  231.     setStart()
  232.     start()
  233.     end
  234.    
  235.    
  236. end
  237. sleep(0.2)
  238. loggedIn()
  239.  
  240. end
  241.  
  242.  
  243.  
  244. function userLoad()
  245.     cbut(2,gy-1,"Files werden geladen")
  246.     rFile = fs.open(rName,"r")
  247.     user = rFile.readLine()
  248.     rpw = rFile.readLine()
  249.     curMoney = rFile.readLine()
  250.    
  251.     rFile.close()
  252.     shell.run("clear")
  253.     cbut(15,3,rName .. " gebe dein Password ein")
  254.  
  255.     term.setCursorPos(15,4)
  256.     term.setTextColor(rcol)
  257.     getPw = read("*")
  258.     term.setTextColor(txt)
  259.  
  260.  
  261.     if rpw == getPw then
  262.  
  263.     sFile = fs.open("Config_ActiveUser","w")
  264. sFile.writeLine(rName)
  265. sFile.close()
  266.        
  267.         loggedIn()
  268.     else
  269.         shell.run("clear")
  270.         cbut(2,gy-1,"Password ist falsch",colors.white,colors.red)
  271.         sleep(2)
  272.         setStart()
  273.     end
  274. end
  275.  
  276. function loginStart()
  277. gFileA = fs.open("Config_ActiveUser","r")
  278. activeUser = gFileA.readLine()
  279. gFileA.close()
  280. if activeUser ~= "None" then
  281. loggedIn()
  282. else
  283. cbut(15,3,"Loginnamen eingeben:")
  284. term.setCursorPos(15,4)
  285.  
  286.  
  287.  
  288. term.setTextColor(rcol)
  289.     rName = io.read()  
  290.         term.setTextColor(txt)
  291.     if fs.exists( rName) == true then
  292.    
  293.    
  294.    
  295.     userLoad()
  296.     else
  297.     shell.run("clear")
  298.     u1()
  299.     cbut(2,gy-1,"User konnte nicht geladen werden",colors.white,colors.red)
  300.     sleep(4)
  301.     setStart()
  302.     start()
  303.     end
  304. end
  305. end
  306.  
  307. function regStart()
  308.    
  309.     cbut(15,3,"Namen waehlen:")
  310.     term.setCursorPos(15,4)
  311.     term.setTextColor(rcol)
  312.     rName = io.read()  
  313.         term.setTextColor(txt)
  314.    
  315.     if fs.exists(rName) == true then
  316.         cbut(2,gy-2, "Name existiert bereits",colors.white,colors.red)
  317.         cbut(2,gy-1,"Bitte einen anderen Namen waehlen",colors.white,colors.red)
  318.         sleep(4)
  319.         shell.run("clear")
  320.         setStart()
  321.     else
  322.         shell.run("clear") 
  323.        
  324.         cbut(15,3,"Bitte waehle ein Password")
  325.         term.setCursorPos(15,4)
  326.        
  327.         term.setTextColor(rcol)
  328.         sPw = io.read()
  329.         term.setTextColor(txt)
  330.         shell.run("clear")
  331.         cbut(2,gy-1,"User wird erstellt")
  332.  
  333.         cbut(15,3,"Zurueck zum Startbildschirm")
  334.         cFile = fs.open(rName ,"w")
  335.         cFile.writeLine(rName)
  336.         cFile.writeLine(sPw)
  337.         cFile.writeLine(0)
  338.         cFile.close()
  339.         sleep(4)
  340.  
  341.         shell.run("clear")
  342.         setStart()
  343.        
  344.     end
  345. end
  346.  
  347.  
  348.  
  349. fRead = false
  350.  
  351. function timeGet()
  352. sTime = os.time()
  353. cbut(gx-6, 1,textutils.formatTime(sTime,true))
  354. sleep(1)
  355. end
  356.  
  357. function start()
  358.  
  359. term.setCursorPos(1,2)
  360. evt,btn, x,y = os.pullEvent("mouse_click")
  361.  
  362.    
  363.     if evt == "mouse_click" and btn == 1 then
  364.  
  365.         if x > (lBtn[1] - 1) and x < (lBtn[1] + string.len(lBtn[3])) and y == lBtn[2] then
  366.         shell.run("clear")
  367.         u1()
  368.         loginStart()
  369.         elseif x > (rBtn[1] - 1) and x < (rBtn[1] + string.len(rBtn[3])) and y == rBtn[2] then
  370.         shell.run("clear")
  371.         u1()
  372.         regStart()
  373.         else
  374.         setStart()
  375.         start()
  376.  
  377.         end
  378.  
  379.     end
  380. end
  381. setStart()
  382.  
  383. while true do
  384. start()
  385. --parallel.waitForAny(timeGet(),start())
  386. end
Add Comment
Please, Sign In to add comment