Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local fs = require("filesystem")
- local computer = require("computer")
- --local chatOnGlassesLib = require("ChatOnGlassesLib")
- local gpu = component.gpu
- local items = {
- {id = "dwcity:Vis_materia", dmg = 0},
- {id = "customnpcs:npcMoney", dmg = 0}
- }
- local players = {
- { name = "Krobys", isJoin = true, isHideOnline = true},
- { name = "OSSO", isJoin = false, isHideOnline = false},
- { name = "PREVESHE", isJoin = false, isHideOnline = false}
- }
- local peripherals = {
- chat_box = nill,
- me_interface = nill,
- sensor = nill,
- bridge = component.openperipheral_bridge or error("No openperipheral_bridge available")
- }
- local settings = {
- tps = true,
- me_items = true,
- sensor_players = true,
- player_items = true,
- chat_box = true,
- local_chat = true,
- memory_monitoring = true,
- admin = "Krobys",
- chat_box_name = "§8[§4Алиса§8]"
- }
- defaultSlotValue = 18
- local constraints = {
- leftBorderAbsolute = defaultSlotValue / 2,
- topBorderAbsolute = defaultSlotValue / 2,
- timeTextWidth = defaultSlotValue * 5,
- --timeValueWidth = defaultSlotValue * 5,--not using now
- nickname_width = defaultSlotValue * 4,
- online_value_width = defaultSlotValue * 3,
- tpsTextWith = defaultSlotValue * 3,
- tpsValueWidth = defaultSlotValue * 2,
- me_item_width = defaultSlotValue * 4,
- players_near_title_width = defaultSlotValue * 5,
- monitoring_me_title_width = defaultSlotValue * 5,
- status_player_title_width = defaultSlotValue * 5,
- status_player_box_width = defaultSlotValue,
- memory_status_width = defaultSlotValue * 6
- }
- -------------{TIME OPTIONS}------------------
- local TIME_ZONE = 0 --Ваш часовой пояс
- local t_correction = TIME_ZONE * 3600
- ---------------------------------------------
- local localize = {
- time = "§9Время:",
- tps = "TPS:",
- avg_tps = "Avg TPS:",
- join_in_game = " §7вошел в игру!",
- left_from_game = " §7покинул игру!",
- user_online = "online",
- user_offline = "offline",
- near_ME = "Игроки рядом",
- monitoring_me_title = "Мониторинг МЭ",
- status_players_title = "Статус игроков"
- }
- local colors = {
- time_color = 0x0000CD, --Время 00:00:00
- tps_title_color = 0x0000CD, --TPS и Avg TPS
- tps_value_color = 0x0000CD, --значения тпс цвет
- monitoring_me_title_color = 0x0000CD, --Мониторинг МЭ надпись
- monitoring_me_item_count_color = 0x0000CD, --Мониторинг МЭ цвет количества
- players_near_title_color = 0x0000CD, --Игроки поблизости цвет
- player_near_nickname_color = 0x0000CD, --Цвет никнейма игрока поблизости
- player_status_title_color = 0x0000CD, --Статус игроков цвет надписи
- player_status_nickname_color = 0x0000CD, --Никнейм статуса игроков цвет
- player_status_online_color = 0x00FF00, --цвет бокса при онлайн игроке
- player_status_offline_color = 0xFF0000, --цвет бокса при оффлайн игроке
- memory_info_color = 0x0000CD, --Память 200 MB/4134 MB - цвет
- memory_percent_color = 0x0000CD, --Проценты памяти 40% цвет
- white = 0xFFFFFF,
- charge_level_color = 0x55FF55, --заряд предметов цвет
- not_charge_level_color = 0x000000
- }
- --------------------------------------------
- timeConstant = 1
- joke = 0
- tSlot = 1
- TPS = {}
- avgTPS = 0
- for tSlot=1,10 do
- TPS[tSlot]=0
- end
- --------------------------------------------
- local absoluteYIndex = constraints.topBorderAbsolute
- function time()
- local f = fs.open("/tmp/timeFile","w")
- f:write("test")
- f:close()
- return(fs.lastModified("/tmp/timeFile"))
- end
- local function drawSlot(x, y, slotWidth, slotHeight, textToDrawInSlot, textColorToDrawInSlot, bgColor)
- local borderColor = 0xFFFFFF
- local borderWidth = 1
- peripherals.bridge.addLine({ x, y }, { x, y + slotHeight }, borderColor)
- peripherals.bridge.addLine({ x + slotWidth, y }, { x + slotWidth, y + slotHeight }, borderColor)
- peripherals.bridge.addLine({ x, y }, { x + slotWidth, y }, borderColor)
- peripherals.bridge.addLine({ x, y + slotHeight }, { x + slotWidth, y + slotHeight}, borderColor)
- peripherals.bridge.addBox(x + borderWidth, y + borderWidth, slotWidth - 2, slotHeight - 2, bgColor or 0xCCCCCC, 0.5)
- if textToDrawInSlot and textColorToDrawInSlot then
- local marginTop = (slotHeight - 8) / 2
- addText(x + 3, y + marginTop, textToDrawInSlot, textColorToDrawInSlot)
- end
- end
- function check()
- if settings.chat_box then
- if component.isAvailable("chat_box") then
- peripherals.chat_box = component.chat_box
- peripherals.chat_box.setName(settings.chat_box_name)
- else
- settings.chat_box = false
- end
- end
- if settings.me_items then
- if component.isAvailable("me_interface") then
- peripherals.me_interface = component.me_interface
- else
- settings.me_items = false
- end
- end
- if settings.sensor_players then
- if component.isAvailable("openperipheral_sensor") then
- peripherals.sensor = component.openperipheral_sensor
- else
- settings.sensor_players = false
- end
- end
- componentsOnScreen()
- end
- function getFreeMemory()
- if settings.memory_monitoring then
- local current = math.floor((computer.freeMemory() / 1000))
- local total = math.floor((computer.totalMemory() / 1000))
- 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)
- local freePercent = math.floor(((computer.freeMemory() / computer.totalMemory()) * 100))
- 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)
- end
- end
- local function getTimeHost()
- local file = io.open('/tmp/UNIX.tmp', 'w')
- file:write('TIME_ZONE = '..TIME_ZONE)
- file:close()
- local lastmod = tonumber(string.sub(fs.lastModified('/tmp/UNIX.tmp'), 1, -4)) + t_correction
- local dt = os.date('%H:%M:%S', lastmod)
- return dt
- end
- function addBox(x, y, w, h, color, tran)
- peripherals.bridge.addBox(x, y, w, h, color, tran)
- end
- function addText(x, y, text, color)
- peripherals.bridge.addText(x, y, text, color)
- end
- function addIcon(x, y, name, meta)
- peripherals.bridge.addIcon(x, y, name, meta)
- end
- function gui()
- w, h = gpu.maxResolution()
- gpu.fill(1, 1, w, h, " ")
- end
- function componentsOnScreen()
- gpu.set(1, 1, "Chat-box: " .. tostring(settings.chat_box))
- gpu.set(1, 2, "ME: " .. tostring(settings.me_items))
- gpu.set(1, 3, "Sensor: " .. tostring(settings.sensor_players))
- gpu.set(1, 4, "TPS: " .. tostring(settings.tps))
- end
- function addMEInfo(network)
- drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.monitoring_me_title_width, defaultSlotValue, localize.monitoring_me_title, colors.monitoring_me_title_color)
- absoluteYIndex = absoluteYIndex + defaultSlotValue
- if settings.me_items then
- for i = 1, #items do
- local itemCount = getSize(network, items[i].id, items[i].dmg)
- drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, defaultSlotValue, defaultSlotValue)
- addIcon(constraints.leftBorderAbsolute + 1, absoluteYIndex + 1, items[i].id, items[i].dmg)
- drawSlot(constraints.leftBorderAbsolute + defaultSlotValue, absoluteYIndex, constraints.me_item_width, defaultSlotValue, itemCount, colors.monitoring_me_item_count_color)
- absoluteYIndex = absoluteYIndex + defaultSlotValue
- end
- end
- end
- function getSize(network,name,dmg)
- local count = 0
- for _, item in ipairs(network) do
- if item.name == name and item.damage == dmg then
- count = count + item.size
- end
- end
- return string.format("%u", count)
- end
- function setTime()
- local timeText = localize.time .. " "..getTimeHost()
- drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.timeTextWidth, defaultSlotValue, timeText, colors.time_color)
- absoluteYIndex = absoluteYIndex + defaultSlotValue
- end
- function checkOnline(n)
- computer.removeUser(settings.admin)
- if computer.addUser(players[n].name) then
- computer.removeUser(players[n].name)
- if not players[n].isJoin then
- if cb then
- chat_box.say("§a"..players[n].name .. localize.join_in_game)
- end
- players[n].isJoin = true
- end
- return true
- else
- if players[n].isJoin then
- if cb then
- chat_box.say("§c"..players[n].name .. localize.left_from_game)
- end
- players[n].isJoin = false
- end
- computer.removeUser(players[n].name)
- return false
- end
- end
- function drawOnline()
- absoluteYIndex = constraints.topBorderAbsolute
- drawSlot(constraints.timeTextWidth + constraints.leftBorderAbsolute, absoluteYIndex, constraints.status_player_title_width, defaultSlotValue, localize.status_players_title, colors.player_status_title_color)
- absoluteYIndex = absoluteYIndex + defaultSlotValue
- for i = 1, #players do
- if not players[i].isHideOnline then
- drawSlot(constraints.timeTextWidth + constraints.leftBorderAbsolute, absoluteYIndex, constraints.nickname_width, defaultSlotValue, players[i].name, colors.player_status_nickname_color)
- if checkOnline(i) then
- drawSlot(constraints.timeTextWidth + constraints.nickname_width + constraints.leftBorderAbsolute, absoluteYIndex, constraints.status_player_box_width, defaultSlotValue, nill, nill, colors.player_status_online_color)
- else
- drawSlot(constraints.timeTextWidth + constraints.nickname_width + constraints.leftBorderAbsolute, absoluteYIndex, constraints.status_player_box_width, defaultSlotValue, nill, nill, colors.player_status_offline_color)
- end
- absoluteYIndex = absoluteYIndex + defaultSlotValue
- end
- end
- end
- function getPlayersNearME()
- local temp = peripherals.sensor.getPlayers()
- local playersCount = #temp
- for g = 1, #temp do
- for j = 1, #players do
- if players[j].name == temp[g].name and players[j].isHideOnline then
- playersCount = playersCount - 1
- end
- end
- end
- if playersCount > 0 then
- drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.players_near_title_width, defaultSlotValue, localize.near_ME, colors.players_near_title_color)
- absoluteYIndex = absoluteYIndex + defaultSlotValue
- end
- if settings.player_items then
- for i = 1, #temp do
- local isShowPlayer = true
- for j = 1, #players do
- if players[j].name == temp[i].name and players[j].isHideOnline then
- isShowPlayer = false
- break
- end
- end
- if isShowPlayer then
- drawPlayerDetails(constraints.leftBorderAbsolute, absoluteYIndex, temp[i].name, defaultSlotValue)
- absoluteYIndex = absoluteYIndex + defaultSlotValue
- end
- end
- end
- end
- function drawPlayerDetails(startX, startY, playerName, slotSize)
- local inventory = peripherals.sensor.getPlayerByName(playerName).all().player.inventory
- drawSlot(startX, startY, constraints.nickname_width, slotSize, playerName, colors.player_near_nickname_color)
- local slotAreaX = startX + constraints.nickname_width - slotSize--todo
- local slotAreaY = startY
- for i = 1, 9 do
- local slotX = slotAreaX + (i * slotSize)
- local slotY = slotAreaY
- drawSlot(slotX, slotY, slotSize, slotSize)
- local inventorySlotLink = inventory[i]
- if inventorySlotLink then
- local inventorySlot = inventorySlotLink.all()
- addIcon(slotX + 1, slotY + 1 , inventorySlot.id, inventorySlot.dmg)
- if inventorySlot.qty and inventorySlot.qty > 1 then
- if inventorySlot.qty > 9 then
- addText(slotX + slotSize/2 - 3, slotY + slotSize/2 + 1, string.format("%u", inventorySlot.qty), colors.white)
- else
- addText(slotX + slotSize/2 + 3, slotY + slotSize/2 + 1, string.format("%u", inventorySlot.qty), colors.white)
- end
- end
- if inventorySlot.electric then
- if inventorySlot.electric.charge then
- local gapX = 2
- local gapBottom = 3
- local barWidth = slotSize - gapX * 2
- local chargePercent = inventorySlot.electric.charge / inventorySlot.electric.maxCharge
- local chargeWidth = barWidth * chargePercent
- addBox(slotX + gapX, slotY + slotSize - gapBottom, barWidth, 1, colors.not_charge_level_color, 1)
- addBox(slotX + gapX, slotY + slotSize - gapBottom, chargeWidth, 1, colors.charge_level_color, 1)
- end
- end
- if inventorySlot.energy_te then
- if inventorySlot.energy_te.energyStored < inventorySlot.energy_te.maxEnergyStored then
- local gapX = 2
- local gapBottom = 3
- local barWidth = slotSize - gapX * 2
- local chargePercent = inventorySlot.energy_te.energyStored / inventorySlot.energy_te.maxEnergyStored
- local chargeWidth = barWidth * chargePercent
- addBox(slotX + gapX, slotY + slotSize - gapBottom, barWidth, 1, colors.not_charge_level_color, 1)
- addBox(slotX + gapX, slotY + slotSize - gapBottom, chargeWidth, 1, colors.charge_level_color, 1)
- end
- end
- end
- end
- end
- function getCurrentTPS()
- realTimeOld = time()
- os.sleep(timeConstant)
- realTimeNew = time()
- realTimeDiff = realTimeNew-realTimeOld
- TPS[tSlot] = 20000*timeConstant/realTimeDiff
- avgTPS = (TPS[1]+TPS[2]+TPS[3]+TPS[4]+TPS[5]+TPS[6]+TPS[7]+TPS[8]+TPS[9]+TPS[10])/10
- drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.tpsTextWith, defaultSlotValue, localize.tps, colors.tps_title_color)
- drawSlot(constraints.leftBorderAbsolute + constraints.tpsTextWith, absoluteYIndex, constraints.tpsValueWidth, defaultSlotValue, string.format("%.2f",TPS[tSlot]), colors.tps_value_color)
- absoluteYIndex = absoluteYIndex + defaultSlotValue
- drawSlot(constraints.leftBorderAbsolute, absoluteYIndex, constraints.tpsTextWith, defaultSlotValue, localize.avg_tps, colors.tps_title_color)
- drawSlot(constraints.leftBorderAbsolute + constraints.tpsTextWith, absoluteYIndex, constraints.tpsValueWidth, defaultSlotValue, string.format("%.2f",avgTPS), colors.tps_value_color)
- absoluteYIndex = absoluteYIndex + defaultSlotValue
- if tSlot == 10 then
- tSlot = 0
- end
- tSlot = tSlot + 1
- end
- gui()
- while true do
- absoluteYIndex = constraints.topBorderAbsolute
- check()
- computer.addUser(settings.admin)
- peripherals.bridge.clear()
- setTime() --время вверху
- if settings.memory_monitoring then
- getFreeMemory()
- end
- if settings.tps then
- getCurrentTPS()
- end
- if settings.me_items then
- local network = peripherals.me_interface.getItemsInNetwork()
- addMEInfo(network)
- network = nil
- end
- if settings.sensor_players then
- mem1 = computer.freeMemory()
- getPlayersNearME()
- end
- drawOnline() --онлайн игроки
- peripherals.bridge.sync()
- os.sleep(timeConstant)
- end
Advertisement
Advertisement