From f0877643c660b95844f3cd96b6ffcaad82158f4a Mon Sep 17 00:00:00 2001 From: erius0 <63460770+erius0@users.noreply.github.com> Date: Sat, 9 Jan 2021 00:20:23 +0300 Subject: [PATCH] Update tabletRadar.lua --- tabletRadar.lua | 70 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/tabletRadar.lua b/tabletRadar.lua index 8bb7020..d076d2e 100644 --- a/tabletRadar.lua +++ b/tabletRadar.lua @@ -1,24 +1,76 @@ local component = require("component") +local event = require("event") +local shell = require("shell") local radar = component.radar +local gpu = component.gpu + +local mode = "p" +local entities = radar.getPlayers() local WHITELIST = {"erius", "DummyWalrus"} +local instr = "радар запущен - нажми E чтобы выйти\nP - режим игроков, I - режим предметов, M - режим мобовn" -print("радар запущен") - -function isWhiteListed(name) - for whitelisted in WHITELIST do - if name == whitelisted then +function contains(arr, name) + for i = 1, #arr do + if name == arr[i] then return false end end return true end +function tableSize(table) + local count = 0 + for _ in pairs(table) do + count = count + 1 + end + return count +end + +function onKeyPressed() + local _, _, _, key, _ = event.pull(0.05, "key_down") + if key == 0x12 then + shell.execute("linkedSend.lua") + elseif key == 0x19 then + mode = "p" + elseif key == 0x32 then + mode = "m" + elseif key == 0x17 then + mode = "i" + elseif key == 0x1E then + mode = "a" + end + if mode == "p" then + entities = radar.getPlayers() + elseif mode == "m" then + entities = radar.getMobs() + elseif mode == "i" then + entities = radar.getItems() + end +end + while true do - local players = radar.getPlayers() - for i = 1, #players do - if isWhiteListed(players[i].name) then - print(players[i].name.." ; Расстояние: "..players[i].distance.." ; Координаты: x = "..players[i].x.." y = "..players[i].y.." z = "..players[i].z) + onKeyPressed() + shell.execute("clear") + print(instr) + for i = 1, #entities do + local size = tableSize(entities[i]) + if mode == "p" then + if contains(WHITELIST, entities[i].name) then + gpu.setForeground(0x00FF00) + print(entities[i].name.." - "..string.format("%.1f", entities[i].distance).." метров") + print("") + gpu.setForeground(0xFFFFFF) + end + elseif mode == "i" then + gpu.setForeground(0x00BFFF) + print(entities[i].label.." - "..string.format("%.1f", entities[i].distance).." метров, количество - "..entities[i].size) print("") + gpu.setForeground(0xFFFFFF) + elseif mode == "m" then + gpu.setForeground(0xFFFF00) + print(entities[i].name.." - "..string.format("%.1f", entities[i].distance).." метров") + print("") + gpu.setForeground(0xFFFFFF) end end end