SanyaRamzik

airtag_opc_glasses

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