pepejik

Untitled

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