LuaScripts/tabletRadar.lua

77 lines
2 KiB
Lua
Raw Normal View History

2021-01-08 17:13:28 +00:00
local component = require("component")
2021-01-08 21:20:23 +00:00
local event = require("event")
local shell = require("shell")
2021-01-08 17:13:28 +00:00
local radar = component.radar
2021-01-08 21:20:23 +00:00
local gpu = component.gpu
2021-01-08 17:13:28 +00:00
2021-01-08 21:20:23 +00:00
local mode = "p"
local entities = radar.getPlayers()
local WHITELIST = {"erius", "DummyWalrus"}
local instr = "радар запущен - нажми E чтобы выйти\nP - режим игроков, I - режим предметов, M - режим мобовn"
2021-01-08 17:13:28 +00:00
2021-01-08 21:20:23 +00:00
function contains(arr, name)
for i = 1, #arr do
if name == arr[i] then
2021-01-08 18:13:18 +00:00
return false
end
end
return true
end
2021-01-08 21:20:23 +00:00
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
2021-01-08 17:13:28 +00:00
while true do
2021-01-08 21:20:23 +00:00
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).." метров")
2021-01-08 18:02:13 +00:00
print("")
2021-01-08 21:20:23 +00:00
gpu.setForeground(0xFFFFFF)
2021-01-08 18:02:13 +00:00
end
2021-01-08 17:13:28 +00:00
end
end