Update tabletRadar.lua

This commit is contained in:
erius0 2021-01-09 00:20:23 +03:00 committed by GitHub
parent e79615c07a
commit f0877643c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,24 +1,76 @@
local component = require("component") local component = require("component")
local event = require("event")
local shell = require("shell")
local radar = component.radar local radar = component.radar
local gpu = component.gpu
local mode = "p"
local entities = radar.getPlayers()
local WHITELIST = {"erius", "DummyWalrus"} local WHITELIST = {"erius", "DummyWalrus"}
local instr = "радар запущен - нажми E чтобы выйти\nP - режим игроков, I - режим предметов, M - режим мобовn"
print("радар запущен") function contains(arr, name)
for i = 1, #arr do
function isWhiteListed(name) if name == arr[i] then
for whitelisted in WHITELIST do
if name == whitelisted then
return false return false
end end
end end
return true return true
end 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 while true do
local players = radar.getPlayers() onKeyPressed()
for i = 1, #players do shell.execute("clear")
if isWhiteListed(players[i].name) then print(instr)
print(players[i].name.." ; Расстояние: "..players[i].distance.." ; Координаты: x = "..players[i].x.." y = "..players[i].y.." z = "..players[i].z) 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("") 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 end
end end