Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local fs = require("filesystem")
- local computer = require("computer")
- local gpu = component.gpu
- local items = {
- {"dwcity:Materia", 0},
- {"minecraft:iron_ingot", 0},
- {"IC2:itemIngot", 0},
- {"IC2:itemOreIridium", 0},
- {"minecraft:redstone_block", 0},
- {"IC2:itemRubber", 0},
- }
- --------------------------------------------------------------
- local colors = {
- blue = 0x05F5F0,
- black = 0x000000,
- bred = 0x660000,
- green = 0x99FF33,
- sun = 0xFFFF00,
- red = 0x0000FF,
- orange = 0xFFA500,
- mem = 0xFFFFFF,
- gray = 0x939393,
- }
- -----------------------------------------------------------------------
- local friendList = {
- "Mrkola_play",
- "KillaLaharl",
- }
- local players = {
- {"Mrkola_play",false},
- {"KillaLaharl",false},
- }
- local blackList = {
- "krissss",
- "combomaster",
- "AliceWay",
- "sima21",
- "SkyDrive_",
- "Phenomenoon",
- "jewiven",
- "_Desert_Eagle_",
- "Samaya",
- }
- --------------------------------------------------------------------
- local chat_box, me, sensor, counter, bridge, redstone
- local euWorking, average, cb, me_a, s, bridgeCom, redstoneCom, allow_mem = true, false, false, false, false,
- false, false, false
- -------------{OPTIONS}------------------
- local redstoneSide = 4
- local TIME_ZONE = 3
- local widthBox = 90
- local transBox = 0.3
- local timeConstant = 1
- local getY = 15
- ---------------------------------------------
- local TC, RO, RN, RD, TPS = 2, 0, 0, 0, 0
- local strTPS = ""
- ---------------------------------------------
- local t_correction = TIME_ZONE * 3600
- local chat_box_name = "§8[§4ag0ny§8]"
- local adm = "Mrkola_play"
- local allow_mem = false
- --------------------------------------------------ENERGY-PROXY-----------------------------------------------------
- local average_counter = {
- molecular = {
- proxy=component.proxy("ab76db39-a54b-4b66-9a4e-9c22d65109d4"),
- icon="AdvancedSolarPanel:BlockMolecularTransformer",
- use=true,
- coordinates = {x = 1, y = getY + 75},
- color = colors.orange,
- },
- molecular2 = {
- proxy=component.proxy("ab76db39-a54b-4b66-9a4e-9c22d65109d4"),
- icon="AdvancedSolarPanel:BlockMolecularTransformer",
- use=true,
- coordinates = {x = 1, y = getY + 75},
- color = colors.red,
- },
- ractor = {
- proxy=component.proxy("b152cb85-cc27-45e3-a2f9-2ce03c99a5bc"),
- icon="IC2:blockReactorChamber",
- use=true,
- coordinates = {x = 1, y = getY + 55},
- color = colors.green,
- },
- solar = {
- proxy=component.proxy("d820fee8-b5ba-4df7-b1a0-7b0607d35c0f"),
- icon="AdvancedSolarPanel:BlockAdvSolarPanel",
- use=true,
- coordinates = {x = 1, y = getY + 35},
- color = colors.blue,
- }
- }
- ---------------------------------------------------------------------------------------------------------------------------------
- local localize = {
- join_in_game = " §7вошел в игру!",
- left_from_game = " §7покинул игру!",
- }
- ---------------------VISUAL----------------------------------------VISUAL-------------------------------------------------------------
- local function addBox(x, y, w, h, color, tran)
- return bridge.addBox(x, y, w, h, color, tran)
- end
- local function addText(x, y, text, color)
- return bridge.addText(x, y, text, color)
- end
- local function addIcon(x, y, name, meta)
- return bridge.addIcon(x, y, name, meta)
- end
- function gui()
- w, h = gpu.maxResolution()
- gpu.fill(1, 1, w, h, " ")
- end
- ------------------------------------------------------------CHECK-COM---------------------------------------------------
- local function digital(n)
- local text=''
- for f in string.gmatch(n,'%d') do text=text..f end
- return text
- end
- function check()
- if component.isAvailable("redstone") then
- redstoneCom = true
- redstone = component.redstone
- end
- if component.isAvailable("average_counter") then
- average = true
- counter = component.average_counter
- end
- if component.isAvailable("chat_box") then
- cb = true
- chat_box = component.chat_box
- chat_box.setName(chat_box_name)
- end
- if component.isAvailable("me_interface") then
- me_a = true
- me = component.me_interface
- end
- if component.isAvailable("openperipheral_sensor") then
- s = true
- sensor = component.openperipheral_sensor
- end
- if component.isAvailable("openperipheral_bridge") then
- bridgeCom = true
- bridge = component.openperipheral_bridge
- end
- if component.isAvailable("redstone") then
- redstoneCom = true
- redstone = component.redstone
- end
- componentsOnScreen()
- return false
- end
- ------------------------------------------------------------TIME----------------------------------------------------------
- local function getTime()
- local f = io.open("/tmp/TF", "w")
- f:write("test")
- f:close()
- return (fs.lastModified("/tmp/TF"))
- end
- local function drawTime()
- local time = getTime()
- local lastmod = tonumber(string.sub(time, 1, -4)) + TIME_ZONE * 3600
- local dt = os.date('%H:%M', lastmod)
- local x = 1
- local y = getY + 16
- local width = widthBox
- local height = 17
- local backgroundColor = colors.black
- local transparency = transBox
- addBox(x, y, width, height, backgroundColor, transparency)
- local textX = x + 5
- local textY = y + 5
- local textColor = colors.sun
- addText(textX, textY, "Время " .. dt, textColor)
- end
- --------------------------------------------
- --------------------------------------------
- function componentsOnScreen()
- gpu.set(1, 1, "Chat-box: " .. tostring(cb))
- gpu.set(1, 2, "ME: " .. tostring(me_a))
- gpu.set(1, 3, "radar: " .. tostring(s))
- gpu.set(1, 4, "Counter: " .. tostring(average))
- gpu.set(1, 5, "redstone: " .. tostring(redstoneCom))
- end
- function getSize(name,dmg)
- for _, item in ipairs(me.getItemsInNetwork()) do
- if item.name == name and item.damage == dmg then
- return item.size
- end
- end
- return 0
- end
- local function string_number(num)
- local answer = ""
- local reverse_num = {}
- local num = tostring(num):gsub(".", function(c)
- table.insert(reverse_num, c)
- end)
- for index, _ in pairs(reverse_num) do
- answer = answer .. reverse_num[#reverse_num - index + 1]
- if index % 3 == 0 and index ~= #reverse_num then
- answer = answer .. " "
- end
- end
- return answer:reverse()
- end
- -------------------------------------------------------------------ITEMS-------------------------------------------------------
- local function formatNumber(num)
- if num >= 1000000 then
- return string.format("%.1fM", num / 1000000)
- elseif num >= 1000 then
- return string.format("%.fK", num / 1000)
- else
- return tostring(num)
- end
- end
- local function drawItems()
- if me_a then
- local y = getY + 100
- local columnWidth = widthBox / 2
- local itemsPerColumn = math.ceil(#items / 2)
- addBox(1, y - 5, columnWidth, itemsPerColumn * 19, colors.black, transBox)
- addBox(columnWidth + 1, y - 5, columnWidth, itemsPerColumn * 19, colors.black, transBox)
- for i = 1, #items do
- local column = math.ceil(i / itemsPerColumn)
- local offsetX = (column - 1) * columnWidth
- local itemIndex = i % itemsPerColumn
- if itemIndex == 0 then
- itemIndex = itemsPerColumn
- end
- local itemY = y + (itemIndex - 1) * 18
- addIcon(offsetX + 3, itemY - 4, items[i][1], items[i][2])
- local formattedNumber = formatNumber(getSize(items[i][1], items[i][2]))
- addText(offsetX + 21, itemY, formattedNumber, colors.blue)
- end
- end
- end
- -------------------------------------------------------------MOLECULAR-----------------------------------------------------------------
- local function toggleMolecular2Energy()
- local molecular2_data = average_counter["molecular2"]
- if molecular2_data and molecular2_data.use then
- local averageEU = molecular2_data.proxy.getAverage()
- local currentRedstoneState = redstone.getOutput(redstoneSide)
- if averageEU == 0 and currentRedstoneState == 15 then
- redstone.setOutput(redstoneSide, 0)
- euWorking = true
- elseif averageEU > 0 and currentRedstoneState == 0 then
- redstone.setOutput(redstoneSide, 15)
- euWorking = false
- end
- end
- end
- ----------------------------------------------------------------TICK-PER-SECOND-------------------------------------------------------
- local function drawTPS()
- local TPS = {}
- local avgTPS = 0
- for tSlot=1, 3 do
- TPS[tSlot] = 0
- end
- for tSlot = 1, 3 do
- local realTimeOld = getTime()
- os.sleep(timeConstant)
- local realTimeNew = getTime()
- local realTimeDiff = realTimeNew - realTimeOld
- TPS[tSlot] = 20000 * timeConstant / realTimeDiff
- avgTPS = (TPS[1] + TPS[2] + TPS[3]) / 3
- end
- local color
- if avgTPS > 18 then
- color = 0x00FF00
- elseif avgTPS > 16 then
- color = 0xAAFF00
- elseif avgTPS > 14 then
- color = 0xFFFF00
- elseif avgTPS > 12 then
- color = 0xFFAA00
- else
- color = 0xFF4400
- end
- local x = 1
- local y = getY -3
- local width = widthBox
- local height = 17
- addBox(x, y, width, height, colors.black, transBox)
- local textOffsetX = 15
- local textX = x + textOffsetX
- local textY = y + 5
- addText(textX, textY, string.format("TPS: %.1f", avgTPS), color)
- return avgTPS
- end
- -------------------------------------------------------------DRAW-ENERGY---------------------------------------------------------
- local function drawEnergy()
- local isMolecularActive = false
- for device, counter in pairs(average_counter) do
- if device == "molecular" and counter.use and euWorking then
- isMolecularActive = true
- break
- end
- end
- for device, counter in pairs(average_counter) do
- if device ~= "molecular2" or not isMolecularActive then
- if counter.use then
- local averageEU = counter.proxy.getAverage()
- local av = ""
- if averageEU / 1000 <= 1 then
- av = string.format("%.3f EU/t", averageEU)
- elseif averageEU / 1000000 >= 1 then
- av = string.format("%.3f M EU/t", averageEU / 1000000)
- else
- av = string.format("%.1f k EU/t", averageEU / 1000)
- end
- if device ~= "molecular2" then
- addBox(counter.coordinates.x, counter.coordinates.y, widthBox, 18, colors.black, transBox)
- addIcon(counter.coordinates.x + 2, counter.coordinates.y + 1, counter.icon, 0)
- end
- if device == "molecular" then
- if euWorking then
- addText(counter.coordinates.x + 21, counter.coordinates.y + 5, av, counter.color)
- end
- else
- addText(counter.coordinates.x + 21, counter.coordinates.y + 5, av, counter.color)
- end
- end
- end
- end
- end
- -----------------------------------------------------------------------------------------
- local function updateEnergyStateAndDraw()
- toggleMolecular2Energy()
- drawEnergy()
- end
- -----------------------------------------------------------CHECK-online--------------------------------------------------------
- function checkOnline(n)
- computer.removeUser(adm)
- if computer.addUser(players[n][1]) then
- computer.removeUser(players[n][1])
- if players[n][2] == false then
- if cb then
- chat_box.say("§a"..players[n][1] .. localize.join_in_game)
- end
- players[n][2] = true
- end
- return true
- else
- if players[n][2] == true then
- if cb then
- chat_box.say("§c"..players[n][1] .. localize.left_from_game)
- end
- players[n][2] = false
- end
- computer.removeUser(players[n][1])
- return false
- end
- end
- -------------------------------------------------------------------
- function freeMemory()
- if allow_mem then
- 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)
- end
- end
- -----------------------------------------------------------------------ONLINE-------------------------------------------------
- function drawOnline()
- local leftMargin = -19
- local yMargin = getY + 141
- local onlineCount = 0
- local offlineCount = 0
- local y = getY + 186
- local onlinePlayers = {}
- local offlinePlayers = {}
- for i = 1, #players do
- if checkOnline(i) then
- onlineCount = onlineCount + 1
- table.insert(onlinePlayers, players[i][1])
- else
- offlineCount = offlineCount + 1
- table.insert(offlinePlayers, players[i][1])
- end
- end
- table.sort(onlinePlayers)
- for _, playerName in ipairs(onlinePlayers) do
- y = y + 10
- addText(leftMargin + 23, y, playerName, colors.green, 1)
- end
- addBox(leftMargin + 20, yMargin + 13, widthBox, 18, colors.black, transBox)
- addText(leftMargin + 43, yMargin + 19, "Offline: " .. offlineCount, colors.gray, 1)
- addIcon(leftMargin + 23, yMargin + 14, "dwcity:Dark_spirit")
- addBox(leftMargin + 20, yMargin + 33, widthBox, 18, colors.black, transBox)
- addText(leftMargin + 43, yMargin + 39, "Online: " .. onlineCount, colors.green, 1)
- addIcon(leftMargin + 23, yMargin + 34, "dwcity:Dark_spirit2")
- end
- --------------------------------------------------------------------SENSOR------------------------------------------------------------
- local function drawNearPlayers()
- if s then
- local y = getY - 3
- local temp = sensor.getPlayers()
- local actualPlayersCount = 0
- addBox(93, y, widthBox, 17, colors.black, transBox)
- for i = 1, #temp do
- local playerIsFriend = false
- local playerIsBlacklisted = false
- for j = 1, #blackList do
- if temp[i].name == blackList[j] then
- playerIsBlacklisted = true
- break
- end
- end
- for j = 1, #friendList do
- if temp[i].name == friendList[j] then
- playerIsFriend = true
- break
- end
- end
- if not playerIsBlacklisted then
- actualPlayersCount = actualPlayersCount + 1
- if playerIsFriend then
- addText(96, y + 22 + (actualPlayersCount - 1) * 10, temp[i].name, colors.green)
- else
- addText(96, y + 22 + (actualPlayersCount - 1) * 10, temp[i].name, colors.bred)
- end
- end
- end
- addText(95, y + 5, "§e|| Игроки рядом: §a" .. actualPlayersCount, colors.green)
- end
- return
- end
- -----------------------------------------------------------------------
- check()
- bridge.clear()
- addText(10, 150, "Инициализация", colors.blue)
- bridge.sync()
- gui()
- while true do
- check()
- computer.addUser(adm)
- bridge.clear()
- updateEnergyStateAndDraw()
- drawItems()
- drawTPS()
- drawTime()
- drawOnline()
- drawNearPlayers()
- freeMemory()
- os.sleep(0.1)
- bridge.sync()
- end
Advertisement
Add Comment
Please, Sign In to add comment