68 lines
1.9 KiB
Lua
68 lines
1.9 KiB
Lua
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"
|
||
|
||
function contains(arr, name)
|
||
for i = 1, #arr do
|
||
if name == arr[i] then
|
||
return false
|
||
end
|
||
end
|
||
return true
|
||
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
|
||
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
|