pepejik

Untitled

Nov 11th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.35 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local fs = require("filesystem")
  4. local computer = require("computer")
  5. local gpu = component.gpu
  6. local items = {
  7. { "dwcity:Materia", 0 },
  8. { "minecraft:iron_ingot", 0 },
  9. { "IC2:itemIngot", 0 },
  10. { "IC2:itemIngot", 1 },
  11. { "minecraft:gold_ingot", 0 },
  12. { "minecraft:redstone", 0 },
  13. { "minecraft:coal", 0 },
  14. { "dwcity:X32", 0 }
  15. }
  16. --------------------------------------------------------------
  17. local colors = {
  18. blue = 0x05F5F0,
  19. black = 0x000000,
  20. bred = 0xFF2400,
  21. green = 0x99FF33,
  22. sun = 0xFFFF00,
  23. red = 0x0052A3,
  24. orange = 0xFFA500,
  25. mem = 0xFFFFFF, -- память
  26. gray = 0x939393,
  27. hex = 0xC522A9,
  28. pur = 0x00FF00,
  29. red1 = 0xFF2400,
  30. }
  31. -----------------------------------------------------------------------
  32. local friendList = {
  33. "Skayrons",
  34. "Lovense",
  35. "Truncator",
  36. "Lovense1",
  37. }
  38. local players = {
  39. { "Skayrons", false },
  40. { "Lovense", false },
  41. { "Lovense1", false },
  42. { "Truncator", false },
  43. }
  44. local blackList = {
  45. "krissss",
  46. "combomaster",
  47. "AliceWay",
  48. "sima21",
  49. "SkyDrive_",
  50. "Phenomenoon",
  51. "jewiven",
  52. "_Desert_Eagle_",
  53. "Samaya",
  54. }
  55. --------------------------------------------------------------------
  56. local chat_box, me, sensor, counter, bridge
  57. local euWorking, average, cb, me_a, s, bridgeCom, allow_mem = true, false, false, false, false,
  58. false, false
  59. -------------{OPTIONS}------------------
  60. local TIME_ZONE = 3
  61. local widthBox = 90
  62. local transBox = 0.3
  63. local timeConstant = 1
  64. local getY = 24
  65. ---------------------------------------------
  66. local TC, RO, RN, RD, TPS = 2, 0, 0, 0, 0
  67. local strTPS = ""
  68. ---------------------------------------------
  69. local t_correction = TIME_ZONE * 3600
  70. local chat_box_name = "§8[§4Малышка§8]"
  71. local adm = "Truncator" -- Ник админа компа
  72. local allow_mem = false -- Отображать на экране кол-во памяти или нет
  73. --------------------------------------------------ENERGY-PROXY-----------------------------------------------------
  74. local average_counter = {
  75. molecular = {
  76. proxy = component.proxy("1f86c069-deca-433e-960b-2c75fd811e0d"),
  77. icon = "AdvancedSolarPanel:BlockMolecularTransformer",
  78. use = true,
  79. coordinates = { x = 1, y = getY + 75 },
  80. color = colors.orange
  81. }
  82. }
  83. ---------------------------------------------------------------------------------------------------------------------------------
  84. local localize = {
  85. join_in_game = " §7вошел в игру!",
  86. left_from_game = " §7покинул игру!",
  87. }
  88.  
  89. ---------------------VISUAL----------------------------------------VISUAL-------------------------------------------------------------
  90. local function addBox(x, y, w, h, color, tran)
  91. return bridge.addBox(x, y, w, h, color, tran)
  92. end
  93.  
  94. local function addText(x, y, text, color)
  95. return bridge.addText(x, y, text, color)
  96. end
  97.  
  98. local function addIcon(x, y, name, meta)
  99. return bridge.addIcon(x, y, name, meta)
  100. end
  101.  
  102. function gui()
  103. w, h = gpu.maxResolution()
  104. gpu.fill(1, 1, w, h, " ")
  105. end
  106. ------------------------------------------------------------CHECK-COM---------------------------------------------------
  107. local function digital(n)
  108. local text = ''
  109. for f in string.gmatch(n, '%d') do
  110. text = text .. f
  111. end
  112. return text
  113. end
  114.  
  115. function check()
  116. if component.isAvailable("average_counter") then
  117. average = true
  118. counter = component.average_counter
  119. end
  120. if component.isAvailable("chat_box") then
  121. cb = true
  122. chat_box = component.chat_box
  123. chat_box.setName(chat_box_name)
  124. end
  125. if component.isAvailable("me_interface") then
  126. me_a = true
  127. me = component.me_interface
  128. end
  129. if component.isAvailable("openperipheral_sensor") then
  130. s = true
  131. sensor = component.openperipheral_sensor
  132. end
  133. if component.isAvailable("openperipheral_bridge") then
  134. bridgeCom = true
  135. bridge = component.openperipheral_bridge
  136. end
  137. componentsOnScreen()
  138. return false
  139. end
  140. ------------------------------------------------------------TIME----------------------------------------------------------
  141. local function getTime()
  142. local f = io.open("/tmp/TF", "w")
  143. f:write("test")
  144. f:close()
  145. return (fs.lastModified("/tmp/TF"))
  146. end
  147.  
  148. local function drawTime()
  149. local time = getTime()
  150. local lastmod = tonumber(string.sub(time, 1, -4)) + TIME_ZONE * 3600
  151. local dt = os.date('%H:%M', lastmod)
  152.  
  153. local x = 1
  154. local y = getY + 16
  155. local width = widthBox
  156. local height = 17
  157. local backgroundColor = colors.black
  158. local transparency = transBox
  159.  
  160. addBox(x, y, width, height, backgroundColor, transparency)
  161.  
  162. local textX = x + 10
  163. local textY = y + 5
  164.  
  165. local textColor = colors.sun
  166.  
  167. addText(textX, textY, "Время " .. dt, textColor)
  168. end
  169. --------------------------------------------
  170.  
  171. --------------------------------------------
  172. function componentsOnScreen()
  173. gpu.set(1, 1, "TPS: " .. tostring(getAvgTPS()))
  174. gpu.set(1, 2, "Molecular AVG: " .. getMolecularAvg())
  175. end
  176.  
  177. function getSize(name, dmg)
  178. for _, item in ipairs(me.getItemsInNetwork()) do
  179. if item.name == name and item.damage == dmg then
  180. return item.size
  181. end
  182. end
  183. return 0
  184. end
  185.  
  186. local function string_number(num)
  187. local answer = ""
  188. local reverse_num = {}
  189. local num = tostring(num):gsub(".", function(c)
  190. table.insert(reverse_num, c)
  191. end)
  192. for index, _ in pairs(reverse_num) do
  193. answer = answer .. reverse_num[#reverse_num - index + 1]
  194. if index % 3 == 0 and index ~= #reverse_num then
  195. answer = answer .. " "
  196. end
  197. end
  198. return answer:reverse()
  199. end
  200. -------------------------------------------------------------------ITEMS-------------------------------------------------------
  201. local function formatNumber(num)
  202. if num >= 1000000 then
  203. return string.format("%.1fM", num / 1000000)
  204. elseif num >= 1000 then
  205. return string.format("%.fK", num / 1000)
  206. else
  207. return tostring(num)
  208. end
  209. end
  210.  
  211. local function drawItems()
  212. if me_a then
  213. local y = getY + 100
  214. local columnWidth = widthBox / 2 -- Ширина каждого столбца
  215. local itemsPerColumn = math.ceil(#items / 2) -- Количество элементов в каждом столбце
  216.  
  217. addBox(1, y - 5, columnWidth, itemsPerColumn * 19, colors.black, transBox) -- Первый столбец
  218. addBox(columnWidth + 1, y - 5, columnWidth, itemsPerColumn * 19, colors.black, transBox) -- Второй столбец
  219.  
  220. for i = 1, #items do
  221. local column = math.ceil(i / itemsPerColumn) -- Определение текущего столбца
  222. local offsetX = (column - 1) * columnWidth -- Смещение по горизонтали в зависимости от текущего столбца
  223.  
  224. local itemIndex = i % itemsPerColumn -- Индекс элемента в текущем столбце
  225. if itemIndex == 0 then
  226. itemIndex = itemsPerColumn
  227. end
  228.  
  229. local itemY = y + (itemIndex - 1) * 18 -- Рассчитываем позицию Y для текущего элемента
  230. addIcon(offsetX + 3, itemY - 4, items[i][1], items[i][2])
  231. local formattedNumber = formatNumber(getSize(items[i][1], items[i][2]))
  232. addText(offsetX + 21, itemY, formattedNumber, colors.blue)
  233. end
  234. end
  235. end
  236. -------------------------------------------------------------MOLECULAR-----------------------------------------------------------------
  237. local function toggleMolecular2Energy()
  238. local molecular2_data = average_counter["molecular2"]
  239. if molecular2_data and molecular2_data.use then
  240. local averageEU = molecular2_data.proxy.getAverage()
  241. local currentRedstoneState = redstone.getOutput(redstoneSide)
  242.  
  243. -- Если значение энергии равно нулю и Redstone включен, выключаем Redstone
  244. if averageEU == 0 and currentRedstoneState == 15 then
  245. redstone.setOutput(redstoneSide, 0)
  246. euWorking = true
  247. -- Если значение энергии больше нуля и Redstone выключен, включаем Redstone
  248. elseif averageEU > 0 and currentRedstoneState == 0 then
  249. redstone.setOutput(redstoneSide, 15)
  250. euWorking = false
  251. end
  252. end
  253. end
  254. ----------------------------------------------------------------TICK-PER-SECOND-------------------------------------------------------
  255. local function drawTPS()
  256.  
  257. local avgTPS = getAvgTPS()
  258.  
  259. local color
  260. if avgTPS > 18 then
  261. color = 0x00FF00
  262. elseif avgTPS > 16 then
  263. color = 0xAAFF00
  264. elseif avgTPS > 14 then
  265. color = 0xFFFF00
  266. elseif avgTPS > 12 then
  267. color = 0xFFAA00
  268. else
  269. color = 0xFF4400
  270. end
  271.  
  272. local x = 1
  273. local y = getY - 3
  274. local width = widthBox
  275. local height = 17
  276.  
  277. addBox(x, y, width, height, colors.black, transBox)
  278.  
  279. local textOffsetX = 15
  280. local textX = x + textOffsetX
  281. local textY = y + 5
  282.  
  283. addText(textX, textY, string.format("TPS: %.1f", avgTPS), color)
  284.  
  285. return avgTPS
  286. end
  287.  
  288. function getAvgTPS()
  289. local TPS = {}
  290. local avgTPS = 0
  291.  
  292. for tSlot = 1, 3 do
  293. TPS[tSlot] = 0
  294. end
  295.  
  296. for tSlot = 1, 3 do
  297. local realTimeOld = getTime()
  298. os.sleep(timeConstant)
  299. local realTimeNew = getTime()
  300. local realTimeDiff = realTimeNew - realTimeOld
  301. TPS[tSlot] = 20000 * timeConstant / realTimeDiff
  302. avgTPS = (TPS[1] + TPS[2] + TPS[3]) / 3
  303. end
  304. return avgTPS
  305. end
  306. -------------------------------------------------------------DRAW-ENERGY---------------------------------------------------------
  307. local function drawEnergy()
  308. local isMolecularActive = false -- Флаг, сигнализирующий об активности устройства "molecular"
  309.  
  310. -- Первый проход - проверяем, активен ли "molecular"
  311. for device, counter in pairs(average_counter) do
  312. if device == "molecular" and counter.use and euWorking then
  313. isMolecularActive = true -- "molecular" активен и работает
  314. break -- Выходим из цикла, так как нашли активное устройство "molecular"
  315. end
  316. end
  317.  
  318. -- Второй проход - рисуем информацию о энергии
  319. for device, counter in pairs(average_counter) do
  320. if device ~= "molecular2" or not isMolecularActive then
  321. -- Если устройство не "molecular2" или "molecular" не активно
  322. if counter.use then
  323. local averageEU = counter.proxy.getAverage()
  324. local av = ""
  325.  
  326. -- Определение единиц для отображения мощности
  327. if averageEU / 1000 <= 1 then
  328. av = string.format("%.3f EU/t", averageEU)
  329. elseif averageEU / 1000000 >= 1 then
  330. av = string.format("%.3f M EU/t", averageEU / 1000000)
  331. else
  332. av = string.format("%.1f k EU/t", averageEU / 1000)
  333. end
  334.  
  335. -- Рисуем прямоугольник и иконку для всех устройств, кроме "molecular2"
  336. if device ~= "molecular2" then
  337. addBox(counter.coordinates.x, counter.coordinates.y, widthBox, 18, colors.black, transBox)
  338. addIcon(counter.coordinates.x + 2, counter.coordinates.y + 1, counter.icon, 0)
  339. end
  340.  
  341. -- Рисуем информацию об энергии
  342. if device == "molecular" then
  343. if euWorking then
  344. addText(counter.coordinates.x + 21, counter.coordinates.y + 5, av, counter.color)
  345. end
  346. else
  347. addText(counter.coordinates.x + 21, counter.coordinates.y + 5, av, counter.color)
  348. end
  349. end
  350. end
  351. end
  352. end
  353.  
  354. function getMolecularAvg()
  355. local isMolecularActive = false -- Флаг, сигнализирующий об активности устройства "molecular"
  356.  
  357. -- Первый проход - проверяем, активен ли "molecular"
  358. for device, counter in pairs(average_counter) do
  359. if device == "molecular" and counter.use and euWorking then
  360. isMolecularActive = true -- "molecular" активен и работает
  361. break -- Выходим из цикла, так как нашли активное устройство "molecular"
  362. end
  363. end
  364.  
  365. -- Второй проход - рисуем информацию о энергии
  366. for device, counter in pairs(average_counter) do
  367. if device ~= "molecular2" or not isMolecularActive then
  368. -- Если устройство не "molecular2" или "molecular" не активно
  369. if counter.use then
  370. local averageEU = counter.proxy.getAverage()
  371. local av = ""
  372.  
  373. -- Определение единиц для отображения мощности
  374. if averageEU / 1000 <= 1 then
  375. av = string.format("%.3f EU/t", averageEU)
  376. elseif averageEU / 1000000 >= 1 then
  377. av = string.format("%.3f M EU/t", averageEU / 1000000)
  378. else
  379. av = string.format("%.1f k EU/t", averageEU / 1000)
  380. end
  381. return av
  382. end
  383. end
  384. end
  385. end
  386.  
  387. -----------------------------------------------------------------------------------------
  388. local function updateEnergyStateAndDraw()
  389. -- Синхронизируем изменение энергии с отображением информации
  390. toggleMolecular2Energy()
  391. drawEnergy()
  392. end
  393. -----------------------------------------------------------CHECK-online--------------------------------------------------------
  394. function checkOnline(n)
  395. computer.removeUser(adm)
  396. if computer.addUser(players[n][1]) then
  397. computer.removeUser(players[n][1])
  398. if players[n][2] == false then
  399. if cb then
  400. chat_box.say("§a" .. players[n][1] .. localize.join_in_game)
  401. end
  402. players[n][2] = true
  403. end
  404. return true
  405. else
  406. if players[n][2] == true then
  407. if cb then
  408. chat_box.say("§c" .. players[n][1] .. localize.left_from_game)
  409. end
  410. players[n][2] = false
  411. end
  412. computer.removeUser(players[n][1])
  413. return false
  414. end
  415. end
  416. -------------------------------------------------------------------
  417. function freeMemory()
  418. if allow_mem then
  419. 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)
  420. end
  421. end
  422. -----------------------------------------------------------------------ONLINE-------------------------------------------------
  423. function drawOnline()
  424. local leftMargin = -19 -- Установите желаемый отступ от левого края экрана
  425. local yMargin = getY + 161
  426. local onlineCount = 0
  427. local offlineCount = 0
  428. local y = getY + 210
  429. -- Создаем отдельные списки для онлайн и оффлайн игроков
  430. local onlinePlayers = {}
  431. local offlinePlayers = {}
  432.  
  433. for i = 1, #players do
  434. if checkOnline(i) then
  435. onlineCount = onlineCount + 1
  436. table.insert(onlinePlayers, players[i][1]) -- Добавляем онлайн игроков в список
  437. else
  438. offlineCount = offlineCount + 1
  439. table.insert(offlinePlayers, players[i][1]) -- Добавляем оффлайн игроков в список
  440. end
  441. end
  442.  
  443. -- Сортируем список онлайн игроков
  444. table.sort(onlinePlayers)
  445.  
  446. -- Показываем сортированный список онлайн игроков и количество оффлайн
  447. for _, playerName in ipairs(onlinePlayers) do
  448. y = y + 10
  449. addText(leftMargin + 23, y, playerName, colors.green, 1) -- Показываем имя игрока с отступом
  450. end
  451. addBox(leftMargin + 20, yMargin + 13, widthBox, 18, colors.black, transBox)
  452. addText(leftMargin + 43, yMargin + 19, "Offline: " .. offlineCount, colors.gray, 1)
  453. addIcon(leftMargin + 23, yMargin + 14, "dwcity:Dark_spirit") -- Иконка для оффлайн
  454. addBox(leftMargin + 20, yMargin + 33, widthBox, 18, colors.black, transBox)
  455. addText(leftMargin + 43, yMargin + 39, "Online: " .. onlineCount, colors.hex, 1)
  456. addIcon(leftMargin + 23, yMargin + 34, "dwcity:Dark_spirit2") -- Иконка для онлайн
  457. end
  458. --------------------------------------------------------------------SENSOR------------------------------------------------------------
  459. local function drawNearPlayers()
  460. if s then
  461. local y = getY - 3
  462. local temp = sensor.getPlayers()
  463. local actualPlayersCount = 0 -- Переменная для подсчета реального количества игроков (не учитывая тех, кто в блэклисте)
  464.  
  465. addBox(93, y, widthBox, 17, colors.black, transBox)
  466.  
  467. for i = 1, #temp do
  468. local playerIsFriend = false
  469. local playerIsBlacklisted = false
  470.  
  471. for j = 1, #blackList do
  472. if temp[i].name == blackList[j] then
  473. playerIsBlacklisted = true
  474. break
  475. end
  476. end
  477.  
  478. for j = 1, #friendList do
  479. if temp[i].name == friendList[j] then
  480. playerIsFriend = true
  481. break
  482. end
  483. end
  484.  
  485. if not playerIsBlacklisted then
  486. actualPlayersCount = actualPlayersCount + 1
  487.  
  488. if playerIsFriend then
  489. addText(96, y + 22 + (actualPlayersCount - 1) * 10, temp[i].name, colors.green)
  490. else
  491. addText(96, y + 22 + (actualPlayersCount - 1) * 10, temp[i].name, colors.red1)
  492. end
  493. end
  494. end
  495.  
  496. addText(95, y + 5, "§b|| Игроки рядом: §a" .. actualPlayersCount, colors.red1)
  497. end
  498. return
  499. end
  500. -----------------------------------------------------------------------
  501. check()
  502. bridge.clear()
  503. addText(10, 150, "Инициализация", colors.blue)
  504. bridge.sync()
  505. gui()
  506.  
  507. while true do
  508. check()
  509. computer.addUser(adm)
  510. bridge.clear()
  511. updateEnergyStateAndDraw()
  512. drawItems()
  513. drawTPS()
  514. drawTime()
  515. drawOnline()
  516. drawNearPlayers()
  517. freeMemory()
  518. os.sleep(0.1)
  519. bridge.sync()
  520. end
Advertisement
Add Comment
Please, Sign In to add comment