pepejik

Untitled

Nov 10th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.22 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, "Chat-box: " .. tostring(cb))
  172. gpu.set(1, 2, "ME: " .. tostring(me_a))
  173. gpu.set(1, 3, "radar: " .. tostring(s))
  174. gpu.set(1, 4, "Counter: " .. tostring(average))
  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. local TPS = {}
  257. local avgTPS = 0
  258.  
  259.  
  260. for tSlot=1, 3 do
  261. TPS[tSlot] = 0
  262. end
  263.  
  264.  
  265. for tSlot = 1, 3 do
  266. local realTimeOld = getTime()
  267. os.sleep(timeConstant)
  268. local realTimeNew = getTime()
  269. local realTimeDiff = realTimeNew - realTimeOld
  270. TPS[tSlot] = 20000 * timeConstant / realTimeDiff
  271. avgTPS = (TPS[1] + TPS[2] + TPS[3]) / 3
  272. end
  273.  
  274.  
  275. local color
  276. if avgTPS > 18 then
  277. color = 0x00FF00
  278. elseif avgTPS > 16 then
  279. color = 0xAAFF00
  280. elseif avgTPS > 14 then
  281. color = 0xFFFF00
  282. elseif avgTPS > 12 then
  283. color = 0xFFAA00
  284. else
  285. color = 0xFF4400
  286. end
  287.  
  288.  
  289. local x = 1
  290. local y = getY -3
  291. local width = widthBox
  292. local height = 17
  293.  
  294.  
  295. addBox(x, y, width, height, colors.black, transBox)
  296.  
  297.  
  298. local textOffsetX = 15
  299. local textX = x + textOffsetX
  300. local textY = y + 5
  301.  
  302. addText(textX, textY, string.format("TPS: %.1f", avgTPS), color)
  303.  
  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 -- Если устройство не "molecular2" или "molecular" не активно
  321. if counter.use then
  322. local averageEU = counter.proxy.getAverage()
  323. local av = ""
  324.  
  325. -- Определение единиц для отображения мощности
  326. if averageEU / 1000 <= 1 then
  327. av = string.format("%.3f EU/t", averageEU)
  328. elseif averageEU / 1000000 >= 1 then
  329. av = string.format("%.3f M EU/t", averageEU / 1000000)
  330. else
  331. av = string.format("%.1f k EU/t", averageEU / 1000)
  332. end
  333.  
  334. -- Рисуем прямоугольник и иконку для всех устройств, кроме "molecular2"
  335. if device ~= "molecular2" then
  336. addBox(counter.coordinates.x, counter.coordinates.y, widthBox, 18, colors.black, transBox)
  337. addIcon(counter.coordinates.x + 2, counter.coordinates.y + 1, counter.icon, 0)
  338. end
  339.  
  340. -- Рисуем информацию об энергии
  341. if device == "molecular" then
  342. if euWorking then
  343. addText(counter.coordinates.x + 21, counter.coordinates.y + 5, av, counter.color)
  344. end
  345. else
  346. addText(counter.coordinates.x + 21, counter.coordinates.y + 5, av, counter.color)
  347. end
  348. end
  349. end
  350. end
  351. end
  352.  
  353. -----------------------------------------------------------------------------------------
  354. local function updateEnergyStateAndDraw()
  355. -- Синхронизируем изменение энергии с отображением информации
  356. toggleMolecular2Energy()
  357. drawEnergy()
  358. end
  359. -----------------------------------------------------------CHECK-online--------------------------------------------------------
  360. function checkOnline(n)
  361. computer.removeUser(adm)
  362. if computer.addUser(players[n][1]) then
  363. computer.removeUser(players[n][1])
  364. if players[n][2] == false then
  365. if cb then
  366. chat_box.say("§a"..players[n][1] .. localize.join_in_game)
  367. end
  368. players[n][2] = true
  369. end
  370. return true
  371. else
  372. if players[n][2] == true then
  373. if cb then
  374. chat_box.say("§c"..players[n][1] .. localize.left_from_game)
  375. end
  376. players[n][2] = false
  377. end
  378. computer.removeUser(players[n][1])
  379. return false
  380. end
  381. end
  382. -------------------------------------------------------------------
  383. function freeMemory()
  384. if allow_mem then
  385. 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)
  386. end
  387. end
  388. -----------------------------------------------------------------------ONLINE-------------------------------------------------
  389. function drawOnline()
  390. local leftMargin = -19 -- Установите желаемый отступ от левого края экрана
  391. local yMargin = getY +161
  392. local onlineCount = 0
  393. local offlineCount = 0
  394. local y = getY + 210
  395. -- Создаем отдельные списки для онлайн и оффлайн игроков
  396. local onlinePlayers = {}
  397. local offlinePlayers = {}
  398.  
  399. for i = 1, #players do
  400. if checkOnline(i) then
  401. onlineCount = onlineCount + 1
  402. table.insert(onlinePlayers, players[i][1]) -- Добавляем онлайн игроков в список
  403. else
  404. offlineCount = offlineCount + 1
  405. table.insert(offlinePlayers, players[i][1]) -- Добавляем оффлайн игроков в список
  406. end
  407. end
  408.  
  409. -- Сортируем список онлайн игроков
  410. table.sort(onlinePlayers)
  411.  
  412. -- Показываем сортированный список онлайн игроков и количество оффлайн
  413. for _, playerName in ipairs(onlinePlayers) do
  414. y = y + 10
  415. addText(leftMargin + 23, y, playerName, colors.green, 1) -- Показываем имя игрока с отступом
  416. end
  417. addBox(leftMargin + 20, yMargin + 13, widthBox, 18, colors.black, transBox)
  418. addText(leftMargin + 43, yMargin + 19, "Offline: " .. offlineCount, colors.gray, 1)
  419. addIcon(leftMargin + 23, yMargin + 14, "dwcity:Dark_spirit") -- Иконка для оффлайн
  420. addBox(leftMargin + 20, yMargin + 33, widthBox, 18, colors.black, transBox)
  421. addText(leftMargin + 43, yMargin + 39, "Online: " .. onlineCount, colors.hex, 1)
  422. addIcon(leftMargin + 23, yMargin + 34, "dwcity:Dark_spirit2") -- Иконка для онлайн
  423. end
  424. --------------------------------------------------------------------SENSOR------------------------------------------------------------
  425. local function drawNearPlayers()
  426. if s then
  427. local y = getY - 3
  428. local temp = sensor.getPlayers()
  429. local actualPlayersCount = 0 -- Переменная для подсчета реального количества игроков (не учитывая тех, кто в блэклисте)
  430.  
  431. addBox(93, y, widthBox, 17, colors.black, transBox)
  432.  
  433. for i = 1, #temp do
  434. local playerIsFriend = false
  435. local playerIsBlacklisted = false
  436.  
  437. for j = 1, #blackList do
  438. if temp[i].name == blackList[j] then
  439. playerIsBlacklisted = true
  440. break
  441. end
  442. end
  443.  
  444. for j = 1, #friendList do
  445. if temp[i].name == friendList[j] then
  446. playerIsFriend = true
  447. break
  448. end
  449. end
  450.  
  451. if not playerIsBlacklisted then
  452. actualPlayersCount = actualPlayersCount + 1
  453.  
  454. if playerIsFriend then
  455. addText(96, y + 22 + (actualPlayersCount - 1) * 10, temp[i].name, colors.green)
  456. else
  457. addText(96, y + 22 + (actualPlayersCount - 1) * 10, temp[i].name, colors.red1)
  458. end
  459. end
  460. end
  461.  
  462. addText(95, y + 5, "§b|| Игроки рядом: §a" .. actualPlayersCount, colors.red1)
  463. end
  464. return
  465. end
  466. -----------------------------------------------------------------------
  467. check()
  468. bridge.clear()
  469. addText(10, 150, "Инициализация", colors.blue)
  470. bridge.sync()
  471. gui()
  472.  
  473. while true do
  474. check()
  475. computer.addUser(adm)
  476. bridge.clear()
  477. updateEnergyStateAndDraw()
  478. drawItems()
  479. drawTPS()
  480. drawTime()
  481. drawOnline()
  482. drawNearPlayers()
  483. freeMemory()
  484. os.sleep(0.1)
  485. bridge.sync()
  486. end
Advertisement
Add Comment
Please, Sign In to add comment