Advertisement
Guest User

1.lua

a guest
Apr 10th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.58 KB | None | 0 0
  1. local component = require("component")
  2. local computer=require("computer")
  3. local event = require("event")
  4. local term = require("term")
  5. local shell = require("shell")
  6. local fs = require("filesystem")
  7. local unicode=require("unicode")
  8. local serial = require("serialization")
  9. if not fs.exists("/lib/.lua") then
  10.     shell.execute("wget https://www.dropbox.com/s/q5gi1m28mtc3hk7/alex.lua?dl=1 /lib/alex.lua")
  11. end
  12. if not (fs.exists(shell.getWorkingDirectory() .. "/AdminsBD.lua")) then
  13.   shell.execute("wget https://www.dropbox.com/s/owtyden7djr9jwp/AdminsBD.lua?dl=1 AdminsBD.lua")
  14. end
  15. local alex = require("alex")
  16. local g = component.gpu
  17. event.shouldInterrupt = function () return false end
  18. --------------------Настройки--------------------
  19. local WIDTH, HEIGHT = 146, 42 --Разрешение моника 146/112 x 42
  20. local COLOR1 = 0x00ffff --Рамка
  21. local COLOR2 = 0x333333 --Цвет кнопок
  22. local UPDATE = 300 --Апдейт отображения информации в сек.
  23. local SCOREBOARDS = {"Admin", "TAdmin", "Admin", "Admin", "gd", "gm", "st", "Dev", "Builder", "Modn",
  24. "Helper2", "Helper1"} --Названия Скорбордов (Создать такие же на серве, либо поменять тут)
  25. local MOD_CHAT_COLOR = {"&8", "&8", "&8", "&8", "&9", "&9", "&3", "&5", "&5", "&6", "&2", "&a"} --Изменение цвета ника в Мод.Чате
  26. local CHANGE_COLOR_NICKNAME = true --Смена цвета ника в мод.чате и листе
  27. local CHANGE_SCOREBOARDS = true --Смена цвета в табе, при наличии скорбордов
  28. -------------------------------------------------
  29. print("\nИнициализация...")
  30. os.sleep(2)
  31. print("Запуск программы...")
  32. os.sleep(2)
  33.  
  34. local mid = WIDTH / 2
  35. local sel = nil
  36. local kontrol = {"Alexhotice","aceman129","Ksena","rotativorotary"}
  37. local admins
  38. local timer = 0
  39. local stat = {"&0[&4Админ&0] - &0", "&0[&4Тех.Админ&0] - &0", "&0[&4Глобал Мод&0] - &0", "&0[&4Куратор&0] - &0", "&0[&9Дизайнер&0] - &3","&0[&9Гл.Модератор&0] - &3",
  40. "&0[&3Ст.Модератор&0] - &3", "&0[&5Разработчик&0] - &d", "&0[&5Строитель&0] - &d", "&0[&4Модератор&0] - &6","&0[&2Помощник&0] - &2", "&0[&aСтажёр&0] - &2"}
  41.  
  42. file = io.open(shell.getWorkingDirectory() .. "/AdminsBD.lua", "r")
  43. local reads = file:read(9999999)
  44. if reads ~= nil then
  45.   admins = serial.unserialize("{" .. reads .. "}")
  46. else
  47.   admins = {}
  48. end
  49. file:close()
  50.  
  51. g.setResolution(WIDTH, HEIGHT)
  52. alex.logo("OpenAdmins", COLOR1, COLOR2, WIDTH, HEIGHT)
  53.  
  54. function Save()
  55.   file = io.open(shell.getWorkingDirectory() .. "/AdminsBD.lua", "w")
  56.   local text = ""
  57.   for i = 1, #admins do
  58.     text = text .. "{'"..admins[i][1].."','"..admins[i][2].."','"..admins[i][3].."'},\n"    
  59.   end
  60.   file:write(text)
  61.   file:close()
  62. end
  63. function Seen(nick)
  64.   local year, month, day, hour, minute = 0,0,0,0,0
  65.   local c = alex.com("seen " .. nick)
  66.   local _, b = string.find(c, "§6Игрок§c")
  67.   if (b == nil) then
  68.     return "&4error"
  69.   end
  70.   local text = string.sub(c, b+1, unicode.len(c))
  71.   if string.find(text, "лет") ~= nil then
  72.     year = string.sub(text, string.find(text, " лет")-2, string.find(text, " лет")-1)
  73.   end
  74.   if string.find(text, "год") ~= nil then
  75.     year = 1
  76.   end
  77.   if string.find(text, "месяц") ~= nil then
  78.     month = string.sub(text, string.find(text, " месяц")-2, string.find(text, " месяц")-1)
  79.   end
  80.   if string.find(text, "дн") ~= nil then
  81.     day = string.sub(text, string.find(text, " дн")-2, string.find(text, " дн")-1)
  82.   elseif string.find(text, "день") ~= nil then
  83.     day = 1
  84.   end
  85.   if string.find(text, "час") ~= nil then
  86.     hour = string.sub(text, string.find(text, " час")-2, string.find(text, " час")-1)
  87.   end
  88.   if string.find(text, "минут") ~= nil then
  89.     minute = string.sub(text, string.find(text, " минут")-2, string.find(text, " минут")-1)
  90.   end
  91.   local status
  92.   if string.find(c, "онлайн") ~= nil then
  93.     status = "&2online"
  94.   else
  95.     status = "&0offline"
  96.   end
  97.   return status, tonumber(year), tonumber(month), tonumber(day), tonumber(hour), tonumber(minute)
  98. end
  99. function Update()
  100.   for i = 1, #admins do
  101.     g.set(mid-45,i+13,"                                     ")
  102.     alex.text(mid-45, i+13, admins[i][1] .. admins[i][2])
  103.     alex.text(mid-8, i+13, admins[i][3] .. "  ")
  104.    
  105.     alex.text(mid+4, i+13, "&6" .. alex.playtime(admins[i][2]) .. "    ")
  106.    
  107.     local status, year, month, day, hour, minute = Seen(admins[i][2])
  108.     g.set(mid+20,i+13,"                       ")
  109.     if status == "&4error" then
  110.       alex.text(mid+20,i+13, status)
  111.     elseif year ~= 0 then
  112.       alex.text(mid+20,i+13, status .. " - " .. year .. " лет " .. month .. " мес. ")
  113.     elseif month ~= 0 then
  114.       alex.text(mid+20,i+13, status .. " - " .. month .. " мес. " .. day .. " дн. ")
  115.     elseif day ~= 0 then
  116.       alex.text(mid+20,i+13, status .. " - " .. day .. " дн. " .. hour .. " ч. ")
  117.     else
  118.       alex.text(mid+20,i+13, status .. " - " .. hour .. " ч. " .. minute .. " мин. ")
  119.     end
  120.   end
  121. end
  122. function Sort()
  123.   local buffer = {}
  124.   for i = 1, #stat do
  125.     for j = 1, #admins do
  126.       if stat[i] == admins[j][1] then
  127.         table.insert(buffer, admins[j])
  128.       end
  129.     end
  130.   end
  131.   admins = buffer
  132. end
  133. function Sel()
  134.   for i = 1, #kontrol do
  135.   for i = 1, #admins do
  136.     alex.text(mid-51,i+13, "   ")
  137.     alex.text(mid+45,i+13, "   ")
  138.     if sel~= nil then
  139.       if sel == admins[i][2] then
  140.         alex.text(mid-51,i+13, "&b>>>")
  141.         alex.text(mid+45,i+13, "&b<<<")
  142.       end
  143.     end
  144.   end
  145.   end
  146. end
  147. function Draw()
  148.   for i = 1, #kontrol do
  149.   if sel ~= nil then
  150.     alex.button(mid-44,HEIGHT-4,20,3,COLOR1,COLOR2,"Повысить")
  151.     alex.button(mid-22,HEIGHT-4,20,3,COLOR1,COLOR2,"Понизить")
  152.     alex.button(mid+6,HEIGHT-4,20,3,COLOR1,COLOR2,"Male/Female")
  153.     alex.button(mid+28,HEIGHT-4,20,3,COLOR1,COLOR2,"Удалить")
  154.   else
  155.     g.fill(3,HEIGHT-6, WIDTH-11, 5, " ")
  156.   end
  157.   end
  158. end
  159. function Index(array, value)
  160.   for i = 1, #array do
  161.     if value == array[i] then
  162.       return i
  163.     end
  164.   end
  165. end
  166. function Click(w,h)
  167.   if sel~= nil then
  168.     local sel_id
  169.     for i = 1, #admins do
  170.       if sel == admins[i][2] then
  171.         sel_id = i
  172.         break
  173.       end
  174.     end
  175.     if w>=mid-44 and w<=mid-25 and h>=HEIGHT-4 and h<=HEIGHT-2 then
  176.       index = Index(stat,admins[sel_id][1]) - 1
  177.       if index == 0 then index = 1 end
  178.       admins[sel_id][1] = stat[index]  
  179.       Sort()
  180.       if CHANGE_SCOREBOARDS then
  181.         alex.com("scoreboard teams join " .. SCOREBOARDS[index] .. " " .. sel)
  182.       end
  183.       if CHANGE_COLOR_NICKNAME then
  184.         alex.com("nick " .. sel .. " " .. MOD_CHAT_COLOR[index] .. sel)
  185.       end
  186.     elseif w>=mid-22 and w<=mid-3 and h>=HEIGHT-4 and h<=HEIGHT-2 then
  187.       index = Index(stat,admins[sel_id][1]) + 1
  188.       if index == #stat + 1 then index = #stat end
  189.       admins[sel_id][1] = stat[index]
  190.       Sort()
  191.       if CHANGE_SCOREBOARDS then
  192.         alex.com("scoreboard teams join " .. SCOREBOARDS[index] .. " " .. sel)
  193.       end
  194.       if CHANGE_COLOR_NICKNAME then
  195.         alex.com("nick " .. sel .. " " .. MOD_CHAT_COLOR[index] .. sel)
  196.       end
  197.     elseif w>=mid+6 and w<=mid+25 and h>=HEIGHT-4 and h<=HEIGHT-2 then
  198.       if admins[sel_id][3] == "&bMale" then
  199.         admins[sel_id][3] = "&dFemale"
  200.       else
  201.         admins[sel_id][3] = "&bMale"
  202.       end
  203.     elseif w>=mid+28 and w<=mid+47 and h>=HEIGHT-4 and h<=HEIGHT-2 then
  204.       table.remove(admins, sel_id)
  205.       g.fill(3,13,WIDTH-4,25, " ")
  206.       if CHANGE_SCOREBOARDS then
  207.         alex.com("scoreboard teams leave " .. sel)
  208.       end
  209.       if CHANGE_COLOR_NICKNAME then
  210.         alex.com("nick " .. sel .. " " .. sel)
  211.       end
  212.     end
  213.     Update()
  214.     Save()
  215.   end
  216.   if w>=WIDTH-8 and w<=WIDTH-4 and h>=HEIGHT-4 and h<=HEIGHT-2 then
  217.     alex.text(mid-44, HEIGHT-6,"&bВведите ник:")
  218.     term.setCursor(mid-30, HEIGHT-6)
  219.     local n = io.read()
  220.     table.insert(admins, {stat[#stat], n, "&bMale"})
  221.     g.set(mid-44, HEIGHT-6,"                                                                                        ")
  222.     Update()
  223.     Save()
  224.     alex.com("scoreboard teams join " .. SCOREBOARDS[#SCOREBOARDS] .. " " .. n)
  225.     alex.com("nick " .. n .. " " .. MOD_CHAT_COLOR[#MOD_CHAT_COLOR] .. n)
  226.   end
  227.   if h-13 >= 1 and h-13 <= #admins then
  228.     sel = admins[h-13][2]
  229.     Sel()
  230.   else
  231.     sel = nil
  232.     Sel()
  233.   end
  234.   Draw()
  235. end
  236. alex.button(WIDTH - 8,HEIGHT-4,5,3,COLOR1,COLOR2,"")
  237. Update()
  238. while true do
  239.   for i = 1, #kontrol do
  240.   local e,_,w,h,_,nick = event.pull(UPDATE, "touch")
  241.   if e == "touch" then
  242.     Click(w,h)
  243.   end
  244.   if sel == nil then
  245.     Update()
  246.   end
  247.   end
  248. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement