pepejik

Untitled

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