pepejik

Untitled

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