Muzze77

IronBankSys_SENSOR

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