pepejik

Untitled

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