Advertisement
Guest User

Untitled

a guest
Nov 10th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.99 KB | None | 0 0
  1. --Variablen--
  2. local fs = require("filesystem")
  3. local event = require("event")
  4. local component = require("component")
  5. local modem = component.modem
  6. local Tablet = "e0d2bad8-26dc-44b8-a307-592316ea050b"       --Adresse des Tablets für das Konto--
  7. local Channel = 1                                           --Port des kontos(immer unterschiedliche Ports verwenden!)--
  8.  
  9. --Netzwerkkanal öffnen--
  10. modem.open(Channel)
  11.  
  12. --Schleife für Aktionen--
  13. while true do                                                                         --                --
  14.                                                                                       --                --
  15. --Warten auf Nachricht mit Absenderadresse und Wert--                                 --                --
  16. local _, _, Adresse, _, _, Betr = event.pull("modem_message")                         --                --
  17. local Betrag = tostring(Betr)                                                         --                --
  18.                                                                                       --                --
  19. --Prüfen ob der Kontostand nur gelesen werden soll--                                  --                --
  20. if Betrag == "read" then                                                              --  __________    --
  21.  local Konto = fs.open("Konto.txt", "rb")                                             --            \   --
  22.  modem.send(Tablet, Channel, Konto:read())                                            --             !  --
  23.  Konto.close()                                                                        --             !  --
  24.                                                                                       --             !  --
  25. --Sonst mit der Überweisung beginnen--                                                --             !  --
  26. else                                                                                  --  ___________!  --
  27.                                                                                       --             !  --
  28. --Prüfen ob Der Betrag Positiv ist--                                                  --             !  --
  29.  if Betrag > 0 then                                                                   --  ________   !  --
  30.                                                                                       --          \  !  --
  31. --Wenn ja prüfen ob die Nachricht vom User stammt--                                   --           ! !  --
  32.   if Adresse == Tablet then                                                           --  ______   ! !  --
  33.                                                                                       --        \  ! !  --
  34. --Wenn ja, Überweisung--                                                              --         ! ! !  --
  35.    local Konto = fs.open("konto.txt", "r")                                            --         ! ! !  --
  36.    local Kontostand = "tostring(Konto:read())"                                        --         ! ! !  --
  37.                                                                                       --         ! ! !  --
  38. --Prüfen ob auf dem Konto genug Geld vorhanden ist--                                  --         ! ! !  --
  39.    if Kontostand >= Betrag then                                                       --  ____   ! ! !  --
  40.                                                                                       --      \  ! ! !  --
  41. --Überweisung des Geldes--                                                            --       ! ! ! !  --
  42.     modem.send(Tablet, Channel, "Success")                                            --       ! ! ! !  --
  43.     local _, _, _, _, _, Empf, Port = event.pull("modem_message")                     --       ! ! ! !  --
  44.     local Emp = tostring(Empf)                                                        --       ! ! ! !  --
  45.     modem.send(Emp, Port, Betrag)                                                     --       ! ! ! !  --
  46.     local _, _, _, _, _, _ = event.pull("modem_message")                              --       ! ! ! !  --
  47.     Kontostand = Kontostand - Betrag                                                  --       ! ! ! !  --
  48.     Konto.close()                                                                     --       ! ! ! !  --
  49.     local Konto = fs.open("konto.txt", "w")                                           --       ! ! ! !  --
  50.     Konto:write(Kontostand)                                                           --       ! ! ! !  --
  51.     modem.send(Tablet, Channel, "Success")                                            --       ! ! ! !  --
  52.     Konto.close()                                                                     --       ! ! ! !  --
  53. --Sonst Fehler senden--                                                               --       ! ! ! !  --
  54.    else                                                                               --  _____! ! ! !  --
  55.     modem.send(Tablet, Channel, "Error2: Not enough money on account")                --       ! ! ! !  --
  56.    end                                                                                --  ____/  ! ! !  --
  57.                                                                                       --         ! ! !  --
  58. --Sonst Addition des Geldes--                                                         --         ! ! !  --
  59.   else                                                                                --  _______! ! !  --
  60.    local Konto = fs.open("konto.txt", "r")                                             --         ! ! !  --
  61.    local kontostand = "tostring(Konto:read())"                                        --         ! ! !  --
  62.    Kontostand = Kontostand + Betrag                                                   --         ! ! !  --
  63.    Konto.close()                                                                      --         ! ! !  --
  64.    local Konto = fs.open("konto.txt", "w")                                            --         ! ! !  --
  65.    Konto:write(Kontostand)                                                            --         ! ! !  --
  66.    modem.send(Adresse, Channel, "Success")                                            --         ! ! !  --
  67.    Konto.close()                                                                      --         ! ! !  --
  68.   end                                                                                 --  ______/  ! !  --
  69. --Wenn nicht Positiv Fehler Senden                                                    --           ! !  --
  70.  else                                                                                 --  _________! !  --
  71.   modem.send(Tablet, Channel, "Error1: Cannot transfer negative values or nil")       --           ! !  --
  72.  end                                                                                  --  ________/  !  --
  73. end                                                                                   --  __________/   --
  74. end                                                                                   --                --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement