Advertisement
mrWhiskasss

glases

Jul 22nd, 2023
970
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local fs = require("filesystem")
  3. local computer = require("computer")
  4. --local chatOnGlassesLib = require("ChatOnGlassesLib")
  5. local gpu = component.gpu
  6.  
  7. local items = {
  8.     {id = "dwcity:Vis_materia", dmg = 0},
  9.     {id = "customnpcs:npcMoney", dmg = 0}
  10. }
  11. local players = {
  12.     { name = "Krobys", isJoin = true, isHideOnline = true},
  13.     { name = "OSSO", isJoin = false, isHideOnline = false},
  14.     { name = "PREVESHE", isJoin = false, isHideOnline = false}
  15. }
  16. local peripherals = {
  17.     chat_box = nill,
  18.     me_interface = nill,
  19.     sensor = nill,
  20.     bridge = component.openperipheral_bridge or error("No openperipheral_bridge available")
  21. }
  22. local settings = {
  23.     tps = true,
  24.     me_items = true,
  25.     sensor_players = true,
  26.     player_items = true,
  27.     chat_box = true,
  28.     local_chat = true,
  29.     memory_monitoring = true,
  30.     admin = "Krobys",
  31.     chat_box_name = "§8[§4Алиса§8]"
  32. }
  33. defaultSlotValue = 18
  34. local constraints = {
  35.     leftBorderAbsolute = defaultSlotValue / 2,
  36.     topBorderAbsolute = defaultSlotValue / 2,
  37.  
  38.     timeTextWidth = defaultSlotValue * 5,
  39.     --timeValueWidth = defaultSlotValue * 5,--not using now
  40.  
  41.     nickname_width = defaultSlotValue * 4,
  42.     online_value_width = defaultSlotValue * 3,
  43.  
  44.     tpsTextWith = defaultSlotValue * 3,
  45.     tpsValueWidth = defaultSlotValue * 2,
  46.  
  47.     me_item_width = defaultSlotValue * 4,
  48.  
  49.     players_near_title_width = defaultSlotValue * 5,
  50.  
  51.     monitoring_me_title_width = defaultSlotValue * 5,
  52.  
  53.     status_player_title_width = defaultSlotValue * 5,
  54.     status_player_box_width = defaultSlotValue,
  55.  
  56.     memory_status_width = defaultSlotValue * 6
  57. }
  58. -------------{TIME OPTIONS}------------------
  59. local TIME_ZONE = 0 --Ваш часовой пояс
  60. local t_correction = TIME_ZONE * 3600
  61. ---------------------------------------------
  62.  
  63. local localize = {
  64.     time = "§9Время:",
  65.     tps = "TPS:",
  66.     avg_tps = "Avg TPS:",
  67.     join_in_game = " §7вошел в игру!",
  68.     left_from_game = " §7покинул игру!",
  69.     user_online = "online",
  70.     user_offline = "offline",
  71.     near_ME = "Игроки рядом",
  72.     monitoring_me_title = "Мониторинг МЭ",
  73.     status_players_title = "Статус игроков"
  74. }
  75. local colors = {
  76.     time_color = 0x0000CD, --Время 00:00:00
  77.     tps_title_color = 0x0000CD, --TPS и Avg TPS
  78.     tps_value_color = 0x0000CD, --значения тпс цвет
  79.     monitoring_me_title_color = 0x0000CD, --Мониторинг МЭ надпись
  80.     monitoring_me_item_count_color = 0x0000CD, --Мониторинг МЭ цвет количества
  81.     players_near_title_color = 0x0000CD, --Игроки поблизости цвет
  82.     player_near_nickname_color = 0x0000CD, --Цвет никнейма игрока поблизости
  83.     player_status_title_color = 0x0000CD, --Статус игроков цвет надписи
  84.     player_status_nickname_color = 0x0000CD, --Никнейм статуса игроков цвет
  85.     player_status_online_color = 0x00FF00, --цвет бокса при онлайн игроке
  86.     player_status_offline_color = 0xFF0000, --цвет бокса при оффлайн игроке
  87.     memory_info_color = 0x0000CD, --Память 200 MB/4134 MB - цвет
  88.     memory_percent_color = 0x0000CD, --Проценты памяти 40% цвет
  89.  
  90.     white = 0xFFFFFF,
  91.     charge_level_color = 0x55FF55, --заряд предметов цвет
  92.     not_charge_level_color = 0x000000
  93. }
  94. --------------------------------------------
  95. timeConstant = 1
  96. joke = 0
  97. tSlot = 1
  98. TPS = {}
  99. avgTPS = 0
  100. for tSlot=1,10 do
  101.     TPS[tSlot]=0
  102. end
  103. --------------------------------------------
  104. local absoluteYIndex = constraints.topBorderAbsolute
  105.  
  106. function time()
  107.     local f = fs.open("/tmp/timeFile","w")
  108.     f:write("test")
  109.     f:close()
  110.     return(fs.lastModified("/tmp/timeFile"))
  111. end
  112.  
  113. local function drawSlot(x, y, slotWidth, slotHeight, textToDrawInSlot, textColorToDrawInSlot, bgColor)
  114.     local borderColor = 0xFFFFFF
  115.     local borderWidth = 1
  116.  
  117.     peripherals.bridge.addLine({ x, y }, { x, y + slotHeight }, borderColor)
  118.     peripherals.bridge.addLine({ x + slotWidth, y }, { x + slotWidth, y + slotHeight }, borderColor)
  119.     peripherals.bridge.addLine({ x, y }, { x + slotWidth, y }, borderColor)
  120.     peripherals.bridge.addLine({ x, y + slotHeight }, { x + slotWidth, y + slotHeight}, borderColor)
  121.     peripherals.bridge.addBox(x + borderWidth, y + borderWidth, slotWidth - 2, slotHeight - 2, bgColor or 0xCCCCCC, 0.5)
  122.  
  123.     if textToDrawInSlot and textColorToDrawInSlot then
  124.         local marginTop = (slotHeight - 8) / 2
  125.         addText(x + 3, y + marginTop, textToDrawInSlot, textColorToDrawInSlot)
  126.     end
  127. end
  128.  
  129. function check()
  130.     if settings.chat_box then
  131.         if component.isAvailable("chat_box") then
  132.             peripherals.chat_box = component.chat_box
  133.             peripherals.chat_box.setName(settings.chat_box_name)
  134.         else
  135.             settings.chat_box = false
  136.         end
  137.     end
  138.     if settings.me_items then
  139.         if component.isAvailable("me_interface") then
  140.             peripherals.me_interface = component.me_interface
  141.         else
  142.             settings.me_items = false
  143.         end
  144.     end
  145.     if settings.sensor_players then
  146.         if component.isAvailable("openperipheral_sensor") then
  147.             peripherals.sensor = component.openperipheral_sensor
  148.         else
  149.             settings.sensor_players = false
  150.         end
  151.     end
  152.     componentsOnScreen()
  153. end
  154.  
  155. function getFreeMemory()
  156.     if settings.memory_monitoring then
  157.         local current = math.floor((computer.freeMemory() / 1000))
  158.         local total = math.floor((computer.totalMemory() / 1000))
  159.         drawSlot(constraints.leftBorderAbsolute + constraints.timeTextWidth + constraints.status_player_title_width, constraints.topBorderAbsolute, constraints.memory_status_width, defaultSlotValue, "MEM: "..current.."mb".."/"..total.."mb", colors.memory_info_color)
  160.         local freePercent = math.floor(((computer.freeMemory() / computer.totalMemory()) * 100))
  161.         drawSlot(constraints.leftBorderAbsolute + constraints.timeTextWidth + constraints.status_player_title_width + constraints.memory_status_width, constraints.topBorderAbsolute, defaultSlotValue * 1.5, defaultSlotValue, freePercent .. "%", colors.memory_percent_color)
  162.     end
  163. end
  164.  
  165. local function getTimeHost()
  166.     local file = io.open('/tmp/UNIX.tmp', 'w')
  167.     file:write('TIME_ZONE = '..TIME_ZONE)
  168.     file:close()
  169.     local lastmod = tonumber(string.sub(fs.lastModified('/tmp/UNIX.tmp'), 1, -4)) + t_correction
  170.     local dt = os.date('%H:%M:%S', lastmod)
  171.     return dt
  172. end
  173.  
  174. function addBox(x, y, w, h, color, tran)
  175.     peripherals.bridge.addBox(x, y, w, h, color, tran)
  176. end
  177.  
  178. function addText(x, y, text, color)
  179.     peripherals.bridge.addText(x, y, text, color)
  180. end
  181.  
  182. function addIcon(x, y, name, meta)
  183.     peripherals.bridge.addIcon(x, y, name, meta)
  184. end
  185.  
  186. function gui()
  187.     w, h = gpu.maxResolution()
  188.     gpu.fill(1, 1, w, h, " ")
  189. end
  190.  
  191. function componentsOnScreen()
  192.     gpu.set(1, 1, "Chat-box: " .. tostring(settings.chat_box))
  193.     gpu.set(1, 2, "ME: " .. tostring(settings.me_items))
  194.     gpu.set(1, 3, "Sensor: " .. tostring(settings.sensor_players))
  195.     gpu.set(1, 4, "TPS: " .. tostring(settings.tps))
  196. end
  197.  
  198. function addMEInfo(network)
  199.     drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.monitoring_me_title_width, defaultSlotValue, localize.monitoring_me_title, colors.monitoring_me_title_color)
  200.     absoluteYIndex = absoluteYIndex + defaultSlotValue
  201.     if settings.me_items then
  202.         for i = 1, #items do
  203.             local itemCount = getSize(network, items[i].id, items[i].dmg)
  204.             drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, defaultSlotValue, defaultSlotValue)
  205.             addIcon(constraints.leftBorderAbsolute + 1, absoluteYIndex + 1, items[i].id, items[i].dmg)
  206.             drawSlot(constraints.leftBorderAbsolute + defaultSlotValue, absoluteYIndex, constraints.me_item_width, defaultSlotValue, itemCount, colors.monitoring_me_item_count_color)
  207.             absoluteYIndex = absoluteYIndex + defaultSlotValue
  208.         end
  209.     end
  210. end
  211.  
  212. function getSize(network,name,dmg)
  213.     local count = 0
  214.     for _, item in ipairs(network) do
  215.         if item.name == name and item.damage == dmg then
  216.             count = count + item.size
  217.         end
  218.     end
  219.     return string.format("%u", count)
  220. end
  221.  
  222. function setTime()
  223.     local timeText = localize.time .. " "..getTimeHost()
  224.     drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.timeTextWidth, defaultSlotValue, timeText, colors.time_color)
  225.     absoluteYIndex = absoluteYIndex + defaultSlotValue
  226. end
  227.  
  228. function checkOnline(n)
  229.     computer.removeUser(settings.admin)
  230.     if computer.addUser(players[n].name) then
  231.         computer.removeUser(players[n].name)
  232.         if not players[n].isJoin then
  233.             if cb then
  234.                 chat_box.say("§a"..players[n].name .. localize.join_in_game)
  235.             end
  236.             players[n].isJoin = true
  237.         end
  238.         return true
  239.     else
  240.         if players[n].isJoin then
  241.             if cb then
  242.                 chat_box.say("§c"..players[n].name .. localize.left_from_game)
  243.             end
  244.             players[n].isJoin = false
  245.         end
  246.         computer.removeUser(players[n].name)
  247.         return false
  248.     end
  249. end
  250.  
  251. function drawOnline()
  252.     absoluteYIndex = constraints.topBorderAbsolute
  253.     drawSlot(constraints.timeTextWidth + constraints.leftBorderAbsolute, absoluteYIndex, constraints.status_player_title_width, defaultSlotValue, localize.status_players_title, colors.player_status_title_color)
  254.     absoluteYIndex = absoluteYIndex + defaultSlotValue
  255.     for i = 1, #players do
  256.         if not players[i].isHideOnline then
  257.             drawSlot(constraints.timeTextWidth + constraints.leftBorderAbsolute, absoluteYIndex, constraints.nickname_width, defaultSlotValue, players[i].name, colors.player_status_nickname_color)
  258.  
  259.             if checkOnline(i) then
  260.                 drawSlot(constraints.timeTextWidth + constraints.nickname_width + constraints.leftBorderAbsolute, absoluteYIndex, constraints.status_player_box_width, defaultSlotValue, nill, nill, colors.player_status_online_color)
  261.             else
  262.                 drawSlot(constraints.timeTextWidth + constraints.nickname_width + constraints.leftBorderAbsolute, absoluteYIndex, constraints.status_player_box_width, defaultSlotValue, nill, nill, colors.player_status_offline_color)
  263.             end
  264.             absoluteYIndex = absoluteYIndex + defaultSlotValue
  265.         end
  266.     end
  267. end
  268.  
  269. function getPlayersNearME()
  270.     local temp = peripherals.sensor.getPlayers()
  271.     local playersCount = #temp
  272.     for g = 1, #temp do
  273.         for j = 1, #players do
  274.             if players[j].name == temp[g].name and players[j].isHideOnline then
  275.                 playersCount = playersCount - 1
  276.             end
  277.         end
  278.     end
  279.     if playersCount > 0 then
  280.         drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.players_near_title_width, defaultSlotValue, localize.near_ME, colors.players_near_title_color)
  281.         absoluteYIndex = absoluteYIndex + defaultSlotValue
  282.     end
  283.     if settings.player_items then
  284.         for i = 1, #temp do
  285.             local isShowPlayer = true
  286.             for j = 1, #players do
  287.                 if players[j].name == temp[i].name and players[j].isHideOnline then
  288.                     isShowPlayer = false
  289.                     break
  290.                 end
  291.             end
  292.             if isShowPlayer then
  293.                 drawPlayerDetails(constraints.leftBorderAbsolute, absoluteYIndex, temp[i].name, defaultSlotValue)
  294.                 absoluteYIndex = absoluteYIndex + defaultSlotValue
  295.             end
  296.         end
  297.     end
  298. end
  299.  
  300. function drawPlayerDetails(startX, startY, playerName, slotSize)
  301.     local inventory = peripherals.sensor.getPlayerByName(playerName).all().player.inventory
  302.     drawSlot(startX, startY, constraints.nickname_width, slotSize, playerName, colors.player_near_nickname_color)
  303.     local slotAreaX = startX + constraints.nickname_width - slotSize--todo
  304.     local slotAreaY = startY
  305.     for i = 1, 9 do
  306.         local slotX = slotAreaX + (i * slotSize)
  307.         local slotY = slotAreaY
  308.         drawSlot(slotX, slotY, slotSize, slotSize)
  309.         local inventorySlotLink = inventory[i]
  310.         if inventorySlotLink then
  311.             local inventorySlot = inventorySlotLink.all()
  312.             addIcon(slotX + 1, slotY + 1 , inventorySlot.id, inventorySlot.dmg)
  313.             if inventorySlot.qty and inventorySlot.qty > 1 then
  314.                 if inventorySlot.qty > 9 then
  315.                     addText(slotX + slotSize/2 - 3, slotY + slotSize/2 + 1, string.format("%u", inventorySlot.qty), colors.white)
  316.                 else
  317.                     addText(slotX + slotSize/2 + 3, slotY + slotSize/2 + 1, string.format("%u", inventorySlot.qty), colors.white)
  318.                 end
  319.             end
  320.             if inventorySlot.electric then
  321.                 if inventorySlot.electric.charge then
  322.                     local gapX = 2
  323.                     local gapBottom = 3
  324.                     local barWidth = slotSize - gapX * 2
  325.                     local chargePercent = inventorySlot.electric.charge / inventorySlot.electric.maxCharge
  326.                     local chargeWidth = barWidth * chargePercent
  327.                     addBox(slotX + gapX, slotY + slotSize - gapBottom, barWidth, 1, colors.not_charge_level_color, 1)
  328.                     addBox(slotX + gapX, slotY + slotSize - gapBottom, chargeWidth, 1, colors.charge_level_color, 1)
  329.                 end
  330.             end
  331.             if inventorySlot.energy_te then
  332.                 if inventorySlot.energy_te.energyStored < inventorySlot.energy_te.maxEnergyStored then
  333.                     local gapX = 2
  334.                     local gapBottom = 3
  335.                     local barWidth = slotSize - gapX * 2
  336.                     local chargePercent = inventorySlot.energy_te.energyStored / inventorySlot.energy_te.maxEnergyStored
  337.                     local chargeWidth = barWidth * chargePercent
  338.                     addBox(slotX + gapX, slotY + slotSize - gapBottom, barWidth, 1, colors.not_charge_level_color, 1)
  339.                     addBox(slotX + gapX, slotY + slotSize - gapBottom, chargeWidth, 1, colors.charge_level_color, 1)
  340.                 end
  341.             end
  342.         end
  343.     end
  344. end
  345.  
  346. function getCurrentTPS()
  347.     realTimeOld = time()
  348.     os.sleep(timeConstant)
  349.     realTimeNew = time()
  350.     realTimeDiff = realTimeNew-realTimeOld
  351.     TPS[tSlot] = 20000*timeConstant/realTimeDiff
  352.     avgTPS = (TPS[1]+TPS[2]+TPS[3]+TPS[4]+TPS[5]+TPS[6]+TPS[7]+TPS[8]+TPS[9]+TPS[10])/10
  353.     drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.tpsTextWith, defaultSlotValue, localize.tps, colors.tps_title_color)
  354.     drawSlot(constraints.leftBorderAbsolute + constraints.tpsTextWith, absoluteYIndex, constraints.tpsValueWidth, defaultSlotValue, string.format("%.2f",TPS[tSlot]), colors.tps_value_color)
  355.     absoluteYIndex = absoluteYIndex + defaultSlotValue
  356.     drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.tpsTextWith, defaultSlotValue, localize.avg_tps, colors.tps_title_color)
  357.     drawSlot(constraints.leftBorderAbsolute + constraints.tpsTextWith, absoluteYIndex, constraints.tpsValueWidth, defaultSlotValue, string.format("%.2f",avgTPS), colors.tps_value_color)
  358.     absoluteYIndex = absoluteYIndex + defaultSlotValue
  359.     if tSlot == 10 then
  360.         tSlot = 0
  361.     end
  362.     tSlot = tSlot + 1
  363. end
  364.  
  365. gui()
  366.  
  367. while true do
  368.     absoluteYIndex = constraints.topBorderAbsolute
  369.     check()
  370.     computer.addUser(settings.admin)
  371.     peripherals.bridge.clear()
  372.     setTime() --время вверху
  373.     if settings.memory_monitoring then
  374.         getFreeMemory()
  375.     end
  376.     if settings.tps then
  377.         getCurrentTPS()
  378.     end
  379.     if settings.me_items then
  380.         local network = peripherals.me_interface.getItemsInNetwork()
  381.         addMEInfo(network)
  382.         network = nil
  383.     end
  384.     if settings.sensor_players then
  385.         mem1 = computer.freeMemory()
  386.         getPlayersNearME()
  387.  
  388.     end
  389.     drawOnline() --онлайн игроки
  390.     peripherals.bridge.sync()
  391.     os.sleep(timeConstant)
  392. end
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement