Ignore self and use UUIDs
This commit is contained in:
parent
969bc3d65c
commit
8a77231798
|
@ -9,6 +9,7 @@ _G.canvas3d = canvas3d_src.create()
|
||||||
|
|
||||||
_G.player = nil
|
_G.player = nil
|
||||||
_G.nearbyEntities = {}
|
_G.nearbyEntities = {}
|
||||||
|
_G.nearbyEntitiesByUUID = {}
|
||||||
|
|
||||||
local function run_wrapped(func, filename)
|
local function run_wrapped(func, filename)
|
||||||
return function()
|
return function()
|
||||||
|
@ -71,7 +72,11 @@ function() -- Neural Interface coroutine
|
||||||
print("NI routine started")
|
print("NI routine started")
|
||||||
while _G._running do
|
while _G._running do
|
||||||
_G.player = safeset(NI.getMetaOwner, "getMetaOwner()", _G.player)
|
_G.player = safeset(NI.getMetaOwner, "getMetaOwner()", _G.player)
|
||||||
_G.nearbyEntities = safeset(NI.sense, "sense()", _G.entities)
|
_G.nearbyEntities = safeset(NI.sense, "sense()", _G.nearbyEntities or {})
|
||||||
|
_G.nearbyEntitiesByUUID = {}
|
||||||
|
for i = 1, #_G.nearbyEntities do
|
||||||
|
_G.nearbyEntitiesByUUID[_G.nearbyEntities[i].id] = _G.nearbyEntities[i]
|
||||||
|
end
|
||||||
_G.canvas3d.recenter()
|
_G.canvas3d.recenter()
|
||||||
os.sleep(0.05)
|
os.sleep(0.05)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
return function()
|
return function()
|
||||||
local cache = {}
|
local cache = {}
|
||||||
while _G._running do
|
while _G._running do
|
||||||
local el = _G.nearbyEntities
|
for id, entry in pairs(cache) do
|
||||||
for i, entry in ipairs(cache) do
|
if nearbyEntitiesByUUID[id] == nil then
|
||||||
if el[i] == nil then
|
entry.cube.remove()
|
||||||
entry.cube.setSize(0.0, 0.0, 0.0)
|
entry.frame.remove()
|
||||||
entry.text.setAlpha(0x00)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i, entity in ipairs(nearbyEntities) do
|
|
||||||
if cache[i] == nil then
|
|
||||||
cache[i] = {}
|
|
||||||
cache[i].cube = canvas3d.addBox(0, 0, 0)
|
|
||||||
cache[i].frame = canvas3d.addFrame({ 0, 0, 0 })
|
|
||||||
cache[i].text = cache[i].frame.addText({ 0, 0 }, "")
|
|
||||||
|
|
||||||
cache[i].cube.setDepthTested(false)
|
for id, entity in pairs(nearbyEntitiesByUUID) do
|
||||||
cache[i].frame.setDepthTested(false)
|
if id ~= player.id then
|
||||||
|
if cache[id] == nil then
|
||||||
|
cache[id] = {}
|
||||||
|
cache[id].cube = canvas3d.addBox(0, 0, 0)
|
||||||
|
cache[id].frame = canvas3d.addFrame({ 0, 0, 0 })
|
||||||
|
cache[id].text = cache[id].frame.addText({ 0, 0 }, "")
|
||||||
|
end
|
||||||
|
cache[id].cube.setDepthTested(false)
|
||||||
|
cache[id].frame.setDepthTested(false)
|
||||||
|
cache[id].cube.setPosition(entity.x, entity.y, entity.z)
|
||||||
|
cache[id].frame.setPosition(entity.x, entity.y, entity.z)
|
||||||
|
cache[id].text.setAlpha(0xFF)
|
||||||
|
cache[id].text.setText(entity.name)
|
||||||
|
cache[id].text.setColor(0xFF0000FF)
|
||||||
end
|
end
|
||||||
|
|
||||||
cache[i].cube.setPosition(entity.x, entity.y, entity.z)
|
|
||||||
cache[i].frame.setPosition(entity.x, entity.y, entity.z)
|
|
||||||
cache[i].text.setAlpha(0xFF)
|
|
||||||
cache[i].text.setText(entity.name)
|
|
||||||
cache[i].text.setColor(0xFF0000FF)
|
|
||||||
end
|
end
|
||||||
os.sleep(0.05)
|
os.sleep(0.05)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue