Advertisement
MagmaLP

test1

Jan 23rd, 2022 (edited)
934
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. term.setBackgroundColor(32768)
  2. term.clear()
  3. rs.setOutput("top", false)
  4. sleep(0.5)
  5.  
  6.  
  7. function calc_color(color)
  8.     return math.pow(2, color - 1)
  9. end
  10.  
  11. function msg(gap, line, color, groundb, text)
  12.     term.setBackgroundColor(calc_color(groundb))
  13.     term.setCursorPos(gap,line)
  14.     term.setTextColor(calc_color(color))
  15.     text = term.write(text)
  16. end  
  17.  
  18. function neueracc()
  19.     term.setBackgroundColor(32768)
  20.     term.clear()
  21.     msg(14,02,04,16,"Neuen Account erstellen")
  22.  
  23.     msg(02,05,04,16,"Wie soll dein Name sein?")
  24.     msg(01,06,04,16,"---------------------------------------------------")
  25.     msg(02,07,06,16,"")
  26.     local name = read()
  27.     if fs.exists("benutzer/" ..name) == true then      
  28.         msg(02,07,15,16,"Dieser Name ist schon vergeben")
  29.         sleep(1)
  30.         neueracc()
  31.     end
  32.  
  33.     msg(02,10,04,16,"Wie soll dein Passwort sein?")
  34.     msg(01,11,04,16,"---------------------------------------------------")
  35.     msg(02,12,06,16,"")
  36.     local passwort1 = read("*")
  37.  
  38.     msg(02,15,04,16,"Bitte Passwort wiederholen!")
  39.     msg(01,16,04,16,"---------------------------------------------------")
  40.     msg(02,17,06,16,"")
  41.     local passwort2 = read("*")
  42.     if passwort1 ~= passwort2 then
  43.         msg(02,17,15,16,"Das Passwort ist nicht gleich!")
  44.         sleep(1)
  45.         neueracc()
  46.     else
  47.         local file = fs.open("benutzer/" ..name.. "/", "w")
  48.         file.write(passwort1)
  49.         file.close()
  50.         local file = fs.open("geld/" ..name.. "/", "w")
  51.         file.write(0.0)
  52.         file.close()
  53.     end
  54.     msg(02,17,06,16,"Account wird erstellt.")
  55.     sleep(1)
  56.     start()
  57. end
  58.  
  59. function anmelden()
  60.     term.setBackgroundColor(32768)
  61.     term.clear()
  62.     msg(14,02,04,16,"Mit Account anmelden")
  63.  
  64.     msg(02,05,04,16,"Wie lautet dein Name?")
  65.     msg(01,06,04,16,"---------------------------------------------------")
  66.     msg(02,07,06,16,"")
  67.     name = read()  
  68.     if fs.exists("benutzer/" ..name) == false then
  69.         msg(02,07,06,16,"Benutzername existiern nicht")
  70.         sleep(1)
  71.         start()
  72.     end
  73.  
  74.     msg(02,10,04,16,"Wie lautet dein Passwort?")
  75.     msg(01,11,04,16,"---------------------------------------------------")
  76.     msg(02,12,06,16,"")
  77.     local passwort = read("*")
  78.     file = fs.open("benutzer/" ..name, "r")
  79.     local inhalt = file.readLine()
  80.     file.close()
  81.    
  82.     if passwort ~= inhalt then
  83.         msg(02,12,06,16,"Passwort falsch")
  84.         sleep(1)
  85.         start()
  86.     else
  87.         hauptbildschirm()
  88.     end              
  89. end
  90.  
  91. function hauptbildschirm()
  92.     term.setBackgroundColor(32768)
  93.     term.setCursorPos(1,1)
  94.     term.clear()
  95.    
  96.  
  97.     file = fs.open("geld/" ..name, "r")
  98.     local dollar = file.readLine()
  99.     file.close()
  100.  
  101.     msg(01,01,06,16,"< Account von "..name.." >")   msg(36,01,06,16," >  "..dollar.."$        ")
  102.     msg(01,02,04,16,"---------------------------------------------------")
  103.  
  104.     msg(06,07,15,15,"                  ")   msg(29,07,15,15,"                  ")
  105.     msg(06,08,01,15,"  Geld einzahlen  ")   msg(29,08,01,15,"  Geld auszahlen  ")
  106.     msg(06,09,15,15,"                  ")   msg(29,09,15,15,"                  ")
  107.  
  108.     msg(16,14,15,15,"                     ")
  109.     msg(16,15,01,15,"    Items kaufen     ")
  110.     msg(16,16,15,15,"                     ")
  111.    
  112.     msg(01,19,01,15," Logout ")
  113.  
  114.     local event, button, X, Y = os.pullEvent("mouse_click")
  115.     if X >= 06 and X <= 23 and Y >= 07 and Y <= 09 then
  116.         einzahlen()
  117.     elseif X >= 29 and X <= 46 and Y >= 07 and Y <= 09 then
  118.         setnull()
  119.     elseif X >= 16 and X <= 36 and Y >= 14 and Y <= 16 then
  120.         kaufen1()
  121.     elseif X >= 01 and X <= 08 and Y == 19 then
  122.         os.reboot()
  123.     else
  124.         hauptbildschirm()
  125.     end
  126. end
  127.    
  128. function einzahlen()
  129.     term.setBackgroundColor(32768)
  130.     term.clear()
  131.     rs.setOutput("right", true)
  132.     sleep(0.5)
  133.     file = fs.open("geld/" ..name, "r")
  134.     local dollar = file.readLine()
  135.     file.close()
  136.  
  137.     msg(01,01,06,16,"< Account von "..name.." >")   msg(36,01,06,16," >  "..dollar.."$        ")
  138.     msg(01,02,04,16,"---------------------------------------------------")
  139.     msg(01,04,04,16,"1x Tungston Ore       =     42$")
  140.     msg(01,05,04,16,"1x Shiny Ingot        =   1000$")
  141.     msg(01,06,04,16,"64x UU-Matter         =    110$")
  142.     msg(01,07,04,16,"1x Ferrouse Ore       =     12$")
  143.     msg(01,08,04,16,"1x Ghast Tear         =    130$")
  144.     msg(01,09,04,16,"1x Lead Ingot         =      8$")
  145.     msg(01,10,04,16,"1x Matrix: Identifier =    500$")
  146.  
  147.     msg(01,12,04,16,"Jetzt bitte links maximal 1024 Items von jeder")
  148.     msg(01,13,04,16,"Sorte einwerfen, Überschuss wird zurückgegeben.")
  149.  
  150.     msg(06,15,15,15,"                  ")   msg(29,15,15,15,"                  ")
  151.     msg(06,16,01,15,"    Berechnen     ")   msg(29,16,01,15,"    Abbrechen     ")
  152.     msg(06,17,15,15,"                  ")   msg(29,17,15,15,"                  ")
  153.  
  154.     msg(01,19,01,15," Logout ")
  155.  
  156.     local event, button, X, Y = os.pullEvent("mouse_click")
  157.     if X >= 29 and X <= 46 and Y >= 15 and Y <= 17 then         --Abbrechen
  158.         rs.setOutput("top", true)
  159.         hauptbildschirm()
  160.     elseif X >= 06 and X <= 23 and Y >= 13 and Y <= 15 then     --Berechnen
  161.         berechnung()  
  162.     elseif X >= 01 and X <= 08 and Y == 19 then                 --Logout
  163.         os.reboot()
  164.     else
  165.         einzahlen()
  166.     end
  167. end
  168.  
  169. function berechnung()
  170.     term.setBackgroundColor(32768)
  171.     term.clear()
  172.     rs.setOutput("right", true)
  173.     sleep(0.5)
  174.     file = fs.open("geld/" ..name, "r")
  175.     local dollar = file.readLine()
  176.     file.close()
  177.  
  178.     msg(01,01,06,16,"< Account von "..name.." >")   msg(36,01,06,16," >  "..dollar.."$        ")
  179.     msg(01,02,04,16,"---------------------------------------------------") 
  180.     msg(01,04,04,16,"Hier Turtle abfrage programmieren.")
  181. end
  182.  
  183. function setnull()
  184.     auszahlmenge = 0.0
  185.     auszahlbetrag = 0.0
  186.     auszahlen()
  187. end
  188.  
  189. function auszahlen()
  190.     term.setBackgroundColor(32768)
  191.     term.clear()
  192.     file = fs.open("geld/" ..name, "r")
  193.     local dollar = file.readLine()
  194.     file.close()
  195.     dollar = tonumber(dollar)
  196.  
  197.     msg(01,01,06,16,"< Account von "..name.." >")   msg(36,01,06,16," >  "..dollar.."$        ")
  198.     msg(01,02,04,16,"---------------------------------------------------")
  199.  
  200.     msg(01,03,04,16,"Die Auszahlung findet in Tungston Ore statt.")
  201.     msg(01,04,04,16,"50$ = 1 Tungston Ore")
  202.     msg(01,05,04,16,"---------------------------------------------------")
  203.     msg(09,06,15,15,"       ")  msg(23,06,15,15,"       ")  msg(38,06,15,15,"       ")
  204.     msg(09,07,01,15,"  + 1  ")  msg(23,07,01,15,"  +10  ")  msg(38,07,01,15,"  +64  ")
  205.     msg(09,08,15,15,"       ")  msg(23,08,15,15,"       ")  msg(38,08,15,15,"       ")
  206.  
  207.     msg(09,10,15,15,"       ")  msg(23,10,15,15,"       ")  msg(38,10,15,15,"       ")
  208.     msg(09,11,01,15,"  - 1  ")  msg(23,11,01,15,"  -10  ")  msg(38,11,01,15,"  -64  ")
  209.     msg(09,12,15,15,"       ")  msg(23,12,15,15,"       ")  msg(38,12,15,15,"       ")
  210.  
  211.     msg(01,14,04,16,"Tungston Ore:")    msg(14,14,06,16," "..auszahlmenge.." ")
  212.     msg(23,14,04,16,"Abzug in Dollar:") msg(39,14,06,16," "..auszahlbetrag.." ")
  213.  
  214.     msg(06,16,15,15,"             ")    msg(23,16,15,15,"              ")
  215.     msg(06,17,01,15,"  Auszahlen  ")    msg(23,17,01,15,"  Abbrechen   ")
  216.     msg(06,18,15,15,"             ")    msg(23,18,15,15,"              ")
  217.     msg(44,19,01,15," Logout ")
  218.  
  219.     local event, button, X, Y = os.pullEvent("mouse_click")
  220.     if X >= 09 and X <= 15 and Y >= 06 and Y <= 08 and auszahlmenge < 1024 then
  221.         auszahlmenge = auszahlmenge + 1
  222.         auszahlbetrag = auszahlbetrag + 50
  223.         auszahlen()
  224.     elseif X >= 23 and X <= 29 and Y >= 06 and Y <= 08 and auszahlmenge <= 1014 then
  225.         auszahlmenge = auszahlmenge + 10
  226.         auszahlbetrag = auszahlbetrag + 500
  227.         auszahlen()
  228.     elseif X >= 38 and X <= 44 and Y >= 06 and Y <= 08 and auszahlmenge <= 960 then
  229.         auszahlmenge = auszahlmenge + 64
  230.         auszahlbetrag = auszahlbetrag + 3200
  231.         auszahlen()
  232.  
  233.     elseif X >= 09 and X <= 15 and Y >= 10 and Y <= 12 and auszahlmenge > 0  then
  234.         auszahlmenge = auszahlmenge - 1
  235.         auszahlbetrag = auszahlbetrag - 50
  236.         auszahlen()
  237.     elseif X >= 23 and X <= 29 and Y >= 10 and Y <= 12 and auszahlmenge >= 10  then
  238.         auszahlmenge = auszahlmenge - 10
  239.         auszahlbetrag = auszahlbetrag - 500
  240.         auszahlen()
  241.     elseif X >= 38 and X <= 44 and Y >= 10 and Y <= 12 and auszahlmenge >= 64  then
  242.         auszahlmenge = auszahlmenge - 64
  243.         auszahlbetrag = auszahlbetrag - 3200
  244.         auszahlen()
  245.  
  246.     elseif X >= 06 and X <= 18 and Y >= 16 and Y <= 18 then
  247.         if auszahlbetrag <= dollar then
  248.             dollar = dollar - auszahlbetrag
  249.             local file = fs.open("geld/" ..name.. "/", "w")
  250.             file.write(dollar)
  251.             file.close()
  252.             rednet.open("bottom")
  253.             rednet.send(7957,auszahlmenge)
  254.             rs.setOutput("right", false)
  255.             sleep(0.5)
  256.             hauptbildschirm()
  257.         else
  258.             msg(01,19,06,16,"Du hast zu wenig Geld!")  
  259.             sleep(1)
  260.             auszahlen()
  261.         end
  262.     elseif X >= 23 and X <= 36 and Y >= 16 and Y <= 18 then
  263.             rs.setOutput("top", false)
  264.             hauptbildschirm()  
  265.     elseif X >= 44 and X <= 51 and Y == 19 then
  266.         os.reboot()
  267.     else
  268.         auszahlen()
  269.     end
  270. end
  271.  
  272. function reset1()
  273.     m0 = 0
  274.     m1 = 0
  275.     m2 = 0
  276.     m3 = 0
  277.     m4 = 0
  278.     m5 = 0
  279.     m6 = 0
  280.     m7 = 0
  281.     m8 = 0
  282.     m9 = 0
  283.     m10 = 0
  284.     m11 = 0
  285.     m12 = 0
  286.     m13 = 0
  287.     m14 = 0
  288.     m15 = 0
  289.     m16 = 0
  290.     m17 = 0
  291.     M = {m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17}
  292. end
  293.  
  294.  
  295.     b1 = 0
  296.     b2 = 0
  297.     b3 = 8000
  298.     b4 = 1000
  299.     b5 = 150
  300.     b6 = 126
  301.     b7 = 42
  302.     b8 = 84
  303.     b9 = 120
  304.     b10 = 120
  305.     b11 = 120
  306.     b12 = 333000
  307.     b13 = 190
  308.     b14 = 2500
  309.     b15 = 450
  310.     b16 = 500
  311.     b17 = 0
  312.     B = {b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17}
  313.  
  314.  
  315. function kaufen1()
  316.     reset1()
  317.     term.setBackgroundColor(32768)
  318.     term.clear()
  319.     file = fs.open("geld/" ..name, "r")
  320.     local dollar = file.readLine()
  321.     file.close()
  322.     betrag = 0
  323.     c = 0                                           --Errechneter Betrag
  324.  
  325.     msg(01,01,06,16,"< Account von "..name.." >")   msg(36,01,06,16," >  "..dollar.."$        ")
  326.     msg(01,02,04,16,"---------------------------------------------------")
  327.     msg(01,03,04,16,"| 8000$ HV Solar Panel")                   msg(51,03,04,16,"|")
  328.     msg(01,04,04,16,"| 1000$ MV Solar Panel")                   msg(51,04,04,16,"|")
  329.     msg(01,05,04,16,"|  150$ LV Solar Panel")                   msg(51,05,04,16,"|")
  330.     msg(01,06,04,16,"-  126$ Deep Storage Unit")                msg(51,06,04,16,"-")
  331.     msg(01,07,04,16,"|   42$ Autmatic Crafting Table MkII")     msg(51,07,04,16,"|")
  332.     msg(01,08,04,16,"|   84$ Igneus Extruder")                  msg(51,08,04,16,"|")
  333.     msg(01,09,04,16,"|  120$ Recycler")                         msg(51,09,04,16,"|")
  334.     msg(01,10,04,16,"-  120$ Electric Furnace")                 msg(51,10,04,16,"-")
  335.     msg(01,11,04,16,"|  120$ Macerator")                        msg(51,11,04,16,"|")
  336.     msg(01,12,04,16,"| 333k$ Adjustable Emitter")               msg(51,12,04,16,"|")
  337.     msg(01,13,04,16,"|  190$ MFSU")                             msg(51,13,04,16,"|")
  338.     msg(01,14,04,16,"- 2500$ Amaranthine Dust")                 msg(51,14,04,16,"-")
  339.     msg(01,15,04,16,"|  450$ Verdan Dust")                      msg(51,15,04,16,"|")
  340.     msg(01,16,04,16,"|  500$ Logic Matrix: Itentifier")         msg(51,16,04,16,"|")
  341.     msg(01,17,04,16,"|    0$ ")                                 msg(51,17,04,16,"|")
  342.     msg(01,18,04,16,"---------------------------------------------------")
  343.     msg(01,19,01,15," Kaufen ") msg(11,19,01,15," Abbrechen ")  msg(24,19,01,15," Logout ")
  344.     msg(34,19,04,16,"Betrag:")  msg(42,19,06,16,""..c.."$")
  345.  
  346.     for i = 3,17 do
  347.         msg(40,i,01,15," + ")  
  348.     end
  349.     for i = 3,17 do
  350.         msg(44,i,04,16,"0")
  351.     end
  352.     for i = 3,17 do
  353.         msg(47,i,01,15," - ")
  354.     end
  355.     kaufen2()
  356. end
  357.  
  358. function kaufen2()
  359.     file = fs.open("geld/" ..name, "r")
  360.     local dollar = file.readLine()
  361.     file.close()
  362.     dollar = tonumber(dollar)
  363.  
  364.     local event, button, X, Y = os.pullEvent("mouse_click")
  365.     for i = 3,16 do
  366.         if X >= 40 and X <= 42 and Y == i then                  -- +1
  367.             if M[i] < 60 then                                   -- max 64
  368.                 M[i] = M[i] + 1
  369.                 c = c + B[i]
  370.                 msg(44,i,04,16,""..M[i].."")
  371.                 msg(42,19,06,16,""..c.."$")
  372.                 break
  373.             end
  374.         end
  375.         if X >= 47 and X <= 49 and Y == i then                  -- -1
  376.             if M[i] > 0 then
  377.                 M[i] = M[i] - 1
  378.                 c = c - B[i]
  379.                 msg(44,i,04,16,""..M[i].." ")
  380.                 msg(42,19,06,16,""..c.."$     ")
  381.                 break
  382.             end
  383.         end
  384.     end
  385.  
  386.     if X >= 11 and X <= 21 and Y == 19 then                 --Abbrechen
  387.         for i = 1,16 do
  388.             M[i] = 0
  389.         end
  390.         rs.setOutput("top", false)
  391.         hauptbildschirm()  
  392.  
  393.     elseif X >= 24 and X <= 31 and Y == 19 then
  394.         os.reboot()
  395.    
  396.     elseif X >= 01 and X <= 08 and Y == 19 then             --Kaufen
  397.         if c > dollar then                                  --aber zu wenig Geld
  398.             msg(41,19,01,15," "..c.."$ ")
  399.             sleep(0.25)
  400.             msg(41,19,06,16," "..c.."$ ")
  401.             sleep(0.25)
  402.             msg(41,19,01,15," "..c.."$ ")
  403.             sleep(0.25)
  404.             msg(41,19,06,16," "..c.."$ ")
  405.             sleep(0.5)
  406.             kaufen2()
  407.         elseif c <= dollar then
  408.             dollar = dollar - c
  409.             local file = fs.open("geld/" ..name.. "/", "w")
  410.             file.write(dollar)
  411.             file.close()
  412.  
  413.             package = {}
  414.             for i,amount in pairs(M) do
  415.                 local a = {}
  416.    
  417.                 if amount > 0 then
  418.                     a = {
  419.                         ["Slot"] = i - 2,
  420.                         ["Amount"] = amount
  421.                     }
  422.                     table.insert(package, a)
  423.                 end
  424.             end
  425.             rednet.open("bottom")
  426.             rednet.send(6415,textutils.serialize(package))
  427.             rs.setOutput("top", false)
  428.             hauptbildschirm()
  429.         end
  430.     end    
  431.     kaufen2()  
  432. end
  433.  
  434. function start()
  435.     term.setBackgroundColor(32768)
  436.     term.clear()
  437.     msg(14,03,04,16,"Neuen Account erstellen")
  438.     msg(01,04,04,16,"---------------------------------------------------")
  439.     msg(15,05,15,15,"                     ")
  440.     msg(15,06,01,15,"     klick hier      ")
  441.     msg(15,07,15,15,"                     ")
  442.     msg(01,08,04,16,"---------------------------------------------------")
  443.  
  444.     msg(15,12,04,16,"Mit Account anmelden")
  445.     msg(01,13,04,16,"---------------------------------------------------")
  446.     msg(15,14,15,15,"                     ")
  447.     msg(15,15,01,15,"     klick hier      ")
  448.     msg(15,16,15,15,"                     ")
  449.     msg(01,17,04,16,"---------------------------------------------------")
  450.     msg(01,20,04,16," ")
  451.  
  452.     local event, button, X, Y = os.pullEvent("mouse_click")
  453.     if X >= 15 and X <= 34 and Y >= 05 and Y <= 07 then
  454.         neueracc()
  455.     elseif X >= 15 and X <= 34 and Y >= 14 and Y <= 16 then
  456.         anmelden()
  457.     else
  458.         start()
  459.     end
  460. end
  461.  
  462. start()
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement