LuaScripts/tabletRadar.lua

65 lines
1.8 KiB
Lua
Raw Permalink 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 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
if mode == "p" then
if contains(WHITELIST, entities[i].name) then
gpu.setForeground(0x00FF00)
print(entities[i].name.." - "..string.format("%.1f", entities[i].distance).." метров")
gpu.setForeground(0xFFFFFF)
end
elseif mode == "i" then
gpu.setForeground(0x00BFFF)
print(entities[i].label.." - "..string.format("%.1f", entities[i].distance).." метров, количество - "..entities[i].size)
gpu.setForeground(0xFFFFFF)
elseif mode == "m" then
gpu.setForeground(0xFFFF00)
print(entities[i].name.." - "..string.format("%.1f", entities[i].distance).." метров")
gpu.setForeground(0xFFFFFF)
2021-01-08 18:02:13 +00:00
end
2021-01-08 17:13:28 +00:00
end
end