serafim7

Show online users [OpenComputers]

Jun 23rd, 2021 (edited)
599
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --https://i.imgur.com/DODsH05.png
  2. --https://pastebin.com/fgVyP3LK
  3. --update 23.06.21
  4.  
  5. local users = {
  6.   {"Creeper","Owner"},
  7.   {"Zombi","Member"},
  8.   {"Skeleton","Member"},
  9.   {"Ghast","Member"},
  10.   {"Blaze","Member"},
  11.   {"Witch","Member"}
  12. }
  13.  
  14. local x_resol = 35
  15. local y_resol = 16
  16.  
  17. local component = require("component")
  18. local computer = require("computer")
  19. local event = require("event")
  20. local gpu = component.gpu
  21. local w,h = gpu.getViewport()
  22.  
  23. local function check()
  24.   gpu.fill(1,1,x_resol,y_resol," ")
  25.   local line = 1
  26.   for ind = 1,#users do
  27.     local name = users[ind][1]
  28.     local rank = users[ind][2]
  29.     gpu.setForeground(0xFFFFFF)
  30.     gpu.set(1,line,"[")
  31.     gpu.set(string.len(rank)+2,line,"] - "..name)
  32.     if rank == "Owner" then
  33.       gpu.setForeground(0xFF0000)
  34.     elseif rank == "Member" then
  35.       gpu.setForeground(0x0000FF)
  36.     end
  37.     gpu.set(2,line,rank)
  38.     if computer.addUser(name) then
  39.       computer.removeUser(name)
  40.       gpu.setForeground(0x00FF00)
  41.       gpu.set(x_resol-7,line,"online")
  42.     else
  43.       gpu.setForeground(0x999999)
  44.       gpu.set(x_resol-7,line,"offline")
  45.     end
  46.     line = line + 1
  47.   end
  48. end
  49.  
  50. for ind = 1,#users do
  51.   computer.removeUser(users[ind][1])
  52. end
  53. os.execute("cls")
  54. gpu.setResolution(x_resol,y_resol)
  55.  
  56. while true do
  57.   check()
  58.   local e = ({event.pull(5,"key_down")})[4]
  59.   if e == 29 or e == 157 then -- Ctrl Выход
  60.     gpu.setResolution(w,h)
  61.     gpu.setBackground(0x000000)
  62.     gpu.setForeground(0xFFFFFF)
  63.     os.execute("cls")
  64.     os.exit()
  65.   end
  66. end
RAW Paste Data