pepejik

Untitled

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