Advertisement
jamawie

Akzeptator - Regeln

May 21st, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.87 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2. sen = sensor.wrap("top")
  3. mon = peripheral.wrap("back")
  4. x,y = mon.getSize()
  5.  
  6. akzeptierende = {}
  7. admins = {}
  8.  
  9.  
  10. function updateAdmins()
  11.     admins = {}
  12.     file = fs.open("admins.tbl","r")
  13.     line = file.readLine()
  14.     while line do
  15.         admins[#admins+1] = line
  16.         line = file.readLine()
  17.     end
  18.     file.close()
  19. end
  20.  
  21. function arrayContains(table,value)
  22.     for i=1,#table do
  23.         if table[i] == value then
  24.             return true
  25.         end
  26.     end
  27.     return false
  28. end
  29.  
  30. function update()
  31.     akzeptierende = {}
  32.     file = fs.open("akzeptierende.tbl","r")
  33.     line = file.readLine()
  34.     while line do
  35.         akzeptierende[#akzeptierende+1] = line
  36.         line = file.readLine()
  37.     end
  38.     file.close()
  39. end
  40.  
  41. function monitor_touch()
  42.     targets = sen.getTargets()
  43.     counter = 0
  44.     player = ""
  45.     for k,v in pairs(targets) do
  46.         if v.Name == "Player"
  47.         and v.Position.X>=-1.5 and v.Position.X<=1.5
  48.         and v.Position.Y>=-4 and v.Position.Y<=1
  49.         and v.Position.Z>=1 and v.Position.Z<=3.5
  50.         then
  51.             counter = counter+1
  52.             player = k
  53.         end
  54.     end
  55.  
  56.     if counter == 1 then
  57.         if not arrayContains(akzeptierende,player) then
  58.             file = fs.open("akzeptierende.tbl","a")
  59.             file.write(player.."\n")
  60.             file.close()
  61.             mon.setBackgroundColor(colors.red)
  62.             mon.setTextColor(colors.gray)
  63.             txt = player .. ","
  64.             mon.setCursorPos(1,5)
  65.             for i=1,x do
  66.                 mon.write(" ")
  67.             end
  68.             mon.setCursorPos(1,6)
  69.             for i=1,x do
  70.                 mon.write(" ")
  71.             end
  72.             mon.setCursorPos(math.floor((x-#txt)/2),5)
  73.             mon.write(txt)
  74.             txt = "Du hast nun akzeptiert"
  75.             mon.setCursorPos(math.floor((x-#txt)/2),6)
  76.             mon.write(txt)
  77.         else
  78.             mon.setBackgroundColor(colors.red)
  79.             mon.setTextColor(colors.gray)
  80.             txt = player .. ","
  81.             mon.setCursorPos(1,5)
  82.             for i=1,x do
  83.                 mon.write(" ")
  84.             end
  85.             mon.setCursorPos(1,6)
  86.             for i=1,x do
  87.                 mon.write(" ")
  88.             end
  89.             mon.setCursorPos(math.floor((x-#txt)/2),5)
  90.             mon.write(txt)
  91.             txt = "Du hast bereits akzeptiert"
  92.             mon.setCursorPos(math.floor((x-#txt)/2),6)
  93.             mon.write(txt)
  94.         end
  95.     else
  96.         mon.setBackgroundColor(colors.red)
  97.         mon.setTextColor(colors.gray)
  98.         mon.setCursorPos(1,5)
  99.         for i=1,x do
  100.             mon.write(" ")
  101.         end
  102.         mon.setCursorPos(1,6)
  103.         for i=1,x do
  104.             mon.write(" ")
  105.         end
  106.         txt = "Es muss genau 1 Spieler"
  107.         mon.setCursorPos(math.floor((x-#txt)/2),5)
  108.         mon.write(txt)
  109.         txt = "auf der Wolle stehen!"
  110.         mon.setCursorPos(math.floor((x-#txt)/2),6)
  111.         mon.write(txt)
  112.     end
  113. end
  114.  
  115. function key(k)
  116.     if k == 30 then
  117.         shell.run("edit akzeptierende.tbl")
  118.     elseif k == 22 then
  119.         shell.run("update")
  120.     elseif k == 19 then
  121.         os.reboot()
  122.     end
  123. end
  124.  
  125.  
  126.  
  127. updateAdmins()
  128. while true do
  129.     term.clear()
  130.     print("Druecke a um die Liste zu sehen, u zum updaten und r zum rebooten")
  131.  
  132.     if not fs.exists("akzeptierende.tbl") then
  133.         file = fs.open("akzeptierende.tbl","w")
  134.         file.close()
  135.     end
  136.  
  137.     update()
  138.  
  139.     mon.setBackgroundColor(colors.white)
  140.     for i=1,y do
  141.         mon.setCursorPos(1,i)
  142.         for j=1,x do
  143.             mon.write(" ")
  144.         end
  145.     end
  146.     mon.setTextColor(colors.cyan)
  147.     txt = "Shop-Regeln akzeptieren"
  148.     mon.setCursorPos(math.floor((x-#txt)/2),3)
  149.     mon.write(txt)
  150.     mon.setTextColor(colors.orange)
  151.     txt = "Klicke um zu akzeptieren"
  152.     mon.setCursorPos(1,9)
  153.     mon.setCursorPos(math.floor((x-#txt)/2),9)
  154.     mon.write(txt)
  155.     txt = "und stehe auf der roten Wolle"
  156.     mon.setCursorPos(math.floor((x-#txt)/2),10)
  157.     mon.write(txt)
  158.  
  159.     if rs.getInput("left") then
  160.         mon.setBackgroundColor(colors.red)
  161.         mon.setTextColor(colors.white)
  162.         for i=5,10 do
  163.             mon.setCursorPos(1,i)
  164.             for j=1,x do
  165.                 mon.write(" ")
  166.             end
  167.         end
  168.  
  169.         txt = "Wartung"
  170.         mon.setCursorPos(math.floor((x-#txt)/2),6)
  171.         mon.write(txt)
  172.         txt = "Ausser Betrieb!"
  173.         mon.setCursorPos(math.floor((x-#txt)/2),9)
  174.         mon.write(txt)
  175.     end
  176.  
  177.     event, a, b, c = os.pullEvent()
  178.     if event == "monitor_touch" then
  179.         if not rs.getInput("left") then
  180.             monitor_touch()
  181.         end
  182.     elseif event == "key" then
  183.         key(a) 
  184.     end
  185.     sleep(2)
  186. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement