From 8a7723179806ac05765a1d60200ddb0c6424775b Mon Sep 17 00:00:00 2001 From: hkc Date: Thu, 12 Oct 2023 21:36:32 +0300 Subject: [PATCH] Ignore self and use UUIDs --- augment/main.lua | 7 ++++++- augment/modules/wh.lua | 38 +++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/augment/main.lua b/augment/main.lua index ad05222..76e28bf 100644 --- a/augment/main.lua +++ b/augment/main.lua @@ -9,6 +9,7 @@ _G.canvas3d = canvas3d_src.create() _G.player = nil _G.nearbyEntities = {} +_G.nearbyEntitiesByUUID = {} local function run_wrapped(func, filename) return function() @@ -71,7 +72,11 @@ function() -- Neural Interface coroutine print("NI routine started") while _G._running do _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() os.sleep(0.05) end diff --git a/augment/modules/wh.lua b/augment/modules/wh.lua index 1836b82..46929fb 100644 --- a/augment/modules/wh.lua +++ b/augment/modules/wh.lua @@ -1,29 +1,29 @@ return function() local cache = {} while _G._running do - local el = _G.nearbyEntities - for i, entry in ipairs(cache) do - if el[i] == nil then - entry.cube.setSize(0.0, 0.0, 0.0) - entry.text.setAlpha(0x00) + for id, entry in pairs(cache) do + if nearbyEntitiesByUUID[id] == nil then + entry.cube.remove() + entry.frame.remove() 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) - cache[i].frame.setDepthTested(false) + for id, entity in pairs(nearbyEntitiesByUUID) do + 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 - - 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 os.sleep(0.05) end