pepejik

Untitled

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