Advertisement
Guest User

glasses.lua

a guest
Jul 25th, 2022
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.13 KB | None | 0 0
  1. local component = require("component")
  2. local fs = require("filesystem")
  3. local computer = require("computer")
  4. local bridge = component.openperipheral_bridge
  5. local gpu = component.gpu
  6. local items = {
  7.   {"IC2:itemIngot", 0},
  8.   {"IC2:itemIngot", 1},
  9.   {"minecraft:iron_ingot", 0},
  10.   {"minecraft:gold_ingot", 0},
  11.   {"minecraft:nether_star", 0},
  12.   {"minecraft:diamond", 0},
  13.   {"IC2:itemPlutonium", 0},
  14.   {"IC2:itemRubber", 0}
  15. }
  16.  
  17. local players = {
  18.   {"_sinnie", false},
  19.   {"MrPva", false}
  20. }
  21. local chat_box, me, radar, counter
  22. local average, me_a, cb, r = false, false, false, false
  23. -------------{TIME OPTIONS}------------------
  24. local TIME_ZONE = 3 --Ваш часовой пояс
  25. ---------------------------------------------
  26.  
  27. ---------------------------------------------
  28. local t_correction = TIME_ZONE * 3600
  29. local chat_box_name = "§8[§4Алиса§8]"
  30. local adm = "_sinnie" -- Ник админа компа
  31. local allow_mem = true -- Отображать на экране кол-во памяти или нет
  32. local localize = {
  33.   time = "§9Время МСК:",
  34.   join_in_game = " §7вошел в игру!",
  35.   left_from_game = " §7покинул игру!",
  36.   user_online = "online",
  37.   user_offline = "offline",
  38.   near_ME = "Игроки около МЭ"
  39. }
  40. local colors = {
  41.   item_size = 0x05F5F0, -- кол-во предметов
  42.   eu = 0x5555FF, -- еу/т
  43.   mem = 0xFFFFFF, -- память
  44.   time = 0x55F055, --Время
  45.   time_text = 0x00FFFF, -- текст "Время МСК:"(пример)
  46.   online = 0x008000, --оналайн на очках
  47.   offline = 0xB22222, -- оффлайн на очках
  48.   near = 0x0000CD, --текст "Игроки рядом с МЭ"
  49.   players_near = 0xFF4500, -- цвет игроков рядом
  50.   players = 0x228B22 -- цвет игроков в Online/offline
  51. }
  52. --------------------------------------------
  53.  
  54. function check()
  55.   if component.isAvailable("average_counter") then
  56.     average = true
  57.     counter = component.average_counter
  58.   end
  59.   if component.isAvailable("chat_box") then
  60.     cb = true
  61.     chat_box = component.chat_box
  62.     chat_box.setName(chat_box_name)
  63.   end
  64.   if component.isAvailable("me_controller") then
  65.     me_a = true
  66.     me = component.me_controller
  67.   end
  68.   if component.isAvailable("radar") then
  69.     r = true
  70.     radar = component.radar
  71.   end
  72.   componentsOnScreen()
  73. end
  74.  
  75. local function getTimeHost()
  76.   local file = io.open('/tmp/UNIX.tmp', 'w')
  77.   file:write('TIME_ZONE = '..TIME_ZONE)
  78.   file:close()
  79.   local lastmod = tonumber(string.sub(fs.lastModified('/tmp/UNIX.tmp'), 1, -4)) + t_correction
  80.   local dt = os.date('%H:%M:%S', lastmod)
  81.   return dt
  82. end
  83.  
  84. function addBox(x, y, w, h, color, tran)
  85.   bridge.addBox(x, y, w, h, color, tran)
  86. end
  87.  
  88. function addText(x, y, text, color)
  89.   bridge.addText(x, y, text, color)
  90. end
  91.  
  92. function addIcon(x, y, name, meta)
  93.   bridge.addIcon(x, y, name, meta)
  94. end
  95.  
  96. function gui()
  97.   w, h = gpu.maxResolution()
  98.   gpu.fill(1, 1, w, h, " ")
  99. end
  100.  
  101. function componentsOnScreen()
  102.   gpu.set(1, 1, "Chat-box: " .. tostring(cb))
  103.   gpu.set(1, 2, "ME: " .. tostring(me_a))
  104.   gpu.set(1, 3, "Radar: " .. tostring(r))
  105.   gpu.set(1, 4, "Counter: " .. tostring(average))
  106. end
  107.  
  108. function addAllIcons()
  109.   y = 25
  110.   for i = 1, #items do
  111.     y = y + 15
  112.     addIcon(0, y, items[i][1], items[i][2])
  113.   end
  114. end
  115.  
  116. function getSize(name,dmg)
  117.  for _, item in ipairs(me.getItemsInNetwork()) do
  118.   if item.name == name and item.damage == dmg then
  119.    return item.size
  120.   end
  121.  end
  122.  return 0
  123. end
  124.  
  125. function setEnergy()
  126.   addIcon(0, 25, "AdvancedSolarPanel:BlockMolecularTransformer", 0)
  127.   if counter.getAverage() / 1000 <= 1 then
  128.     av = string.format("%.3f", tostring(counter.getAverage())) .. "EU/t"
  129.   elseif counter.getAverage() / 1000000 >= 1 then
  130.     av = string.format("%.3f", tostring(counter.getAverage() / 1000000)) .. "MEU/t"
  131.   else
  132.     av = string.format("%.1f", tostring(counter.getAverage() / 1000)) .. "kEU/t"
  133.   end
  134.   addText(25, 27, av, colors.eu)
  135. end
  136.  
  137. function setTime()
  138.   addText(0, 2, localize.time, colors.time_text)
  139.   addText(55, 2, getTimeHost(), colors.time)
  140. end
  141.  
  142. function freeMemory()
  143.   if allow_mem then
  144.     addText(0, 12, "MEM: "..math.floor((computer.freeMemory() / 1000)).."mb".."/"..math.floor((computer.totalMemory() / 1000)).."mb".." "..math.floor(((computer.freeMemory() / computer.totalMemory()) * 100)).."%", colors.mem)
  145.   end
  146. end
  147.  
  148. function checkOnline(n)
  149.   computer.removeUser(adm)
  150.   if computer.addUser(players[n][1]) then
  151.     computer.removeUser(players[n][1])
  152.     if players[n][2] == false then
  153.       if cb then
  154.         chat_box.say("§a"..players[n][1] .. localize.join_in_game)
  155.       end
  156.       players[n][2] = true
  157.     end
  158.     return true
  159.   else
  160.     if players[n][2] == true then
  161.       if cb then
  162.         chat_box.say("§c"..players[n][1] .. localize.left_from_game)
  163.       end
  164.       players[n][2] = false
  165.     end
  166.     computer.removeUser(players[n][1])
  167.     return false
  168.   end
  169. end
  170.  
  171. function drawOnline()
  172.   yy = 17
  173.   for i = 1, #players do
  174.     yy = yy + 8
  175.     addText(90, yy, players[i][1], colors.players)
  176.     if checkOnline(i) then
  177.       addText(130, yy, localize.user_online, colors.online)
  178.     else
  179.       addText(130, yy, localize.user_offline, colors.offline)
  180.     end
  181.   end
  182. end
  183.  
  184. function getPlayersNearME()
  185.   addText(90, 75, localize.near_ME, colors.near)
  186.   a = 75
  187.   temp = radar.getPlayers()
  188.   for i = 1, #temp do
  189.     a = a + 10
  190.     for j = 1, #players do
  191.       if temp[i].name == players[j][1] then
  192.         return
  193.       else
  194.         addText(90, a, temp[i].name.." "..math.floor(temp[i].distance), colors.players_near)
  195.       end
  196.     end
  197.   end
  198. end
  199.  
  200. check()
  201. bridge.clear()
  202. addBox(25, 0, 100, 100, 0xFFFFFF, 0)
  203. addAllIcons()
  204. bridge.sync()
  205. gui()
  206.  
  207. while true do
  208.   check()
  209.   computer.addUser(adm)
  210.   bridge.clear()
  211.   if me_a then
  212.     addAllIcons()
  213.     y = 27
  214.     for i = 1, #items do
  215.       y = y + 15
  216.       addText(25, y, getSize(items[i][1], items[i][2]), colors.item_size)
  217.     end
  218.   end
  219.   if average then
  220.     setEnergy()
  221.   end
  222.   setTime()
  223.   drawOnline()
  224.   freeMemory()
  225.   if r then
  226.     getPlayersNearME()
  227.   end
  228.   os.sleep(0.001)
  229.   bridge.sync()
  230. end
  231.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement