esp: add nodelist

This commit is contained in:
cora 2020-11-27 02:38:22 +01:00 committed by Schmappie Eldress
parent f956ff8566
commit 435d82cc57
2 changed files with 24 additions and 10 deletions

View File

@ -9,26 +9,30 @@ local esplimit=30; -- display at most this many waypoints
local espinterval=4 --number of seconds to wait between scans (a lower number can induce clientside lag)
local stpos={x=0,y=0,z=0}
--nodes={"group:chest",'mcl_chests:chest','mcl_chests:chest_left','mcl_chests:ender_chest','group:shulker_box','mcl_crafting_table:crafting_table','mcl_furnaces:furnace'}
nodes={'mcl_chests:chest','mcl_chests:chest_left','mcl_chests:ender_chest','group:shulker_box','mcl_furnaces:furnace','mcl_chests:violet_shulker_box'}
nodes=nlist.get("esp")
local wps={}
local hud2=nil
local hud;
local lastch=0
local wason=false
minetest.register_globalstep(function()
if not minetest.settings:get_bool("espactive") then
if wason then
for k,v in pairs(wps) do
minetest.localplayer:hud_remove(v)
table.remove(wps,k)
end
nlist.hide()
end
return
end
if not minetest.localplayer then return end
if os.time() < lastch + espinterval then return end
lastch=os.time()
if not minetest.settings:get_bool('nlist_edmode') then nlist.show_list("esp") end
local pos = minetest.localplayer:get_pos()
local pos1 = vector.add(pos,{x=radius,y=radius,z=radius})
local pos2 = vector.add(pos,{x=-radius,y=-radius,z=-radius})
@ -36,8 +40,7 @@ minetest.register_globalstep(function()
for k,v in pairs(wps) do --clear waypoints out of range
local hd=minetest.localplayer:hud_get(v)
local dst=vector.distance(pos,hd.world_pos)
if (dst > radius + 50 ) then
if not hd or vector.distance(pos,hd.world_pos) > radius + 50 then
minetest.localplayer:hud_remove(v)
table.remove(wps,k)
end

View File

@ -3,11 +3,16 @@ local storage=minetest.get_mod_storage()
local sl="default"
local mode=1 --1:add, 2:remove
local nled_hud
local edmode_wason=false
minetest.register_globalstep(function()
if not minetest.settings:get_bool('nlist_edmode') then
if edmode_wason then
if nled_hud then minetest.localplayer:hud_remove(nled_hud) end
edmode_wason=false
end
return end
nlist.show_list(sl)
edmode_wason=true
nlist.show_list(sl,true)
end)
minetest.register_on_punchnode(function(p, n)
@ -61,6 +66,10 @@ function nlist.show_list(list)
set_nled_hud(txt)
end
function nlist.hide()
if nled_hud then minetest.localplayer:hud_remove(nled_hud) end
end
function nlist.random(list)
local str=storage:get(list)
local tb=str:split(',')
@ -72,12 +81,14 @@ function nlist.random(list)
end
function set_nled_hud(ttext)
function set_nled_hud(ttext,help)
if not minetest.localplayer then return end
if type(ttext) ~= "string" then return end
local act="add"
if mode == 2 then act="remove" end
local text="Nodelist edit mode\n .nla/.nlr to switch\n punch node to ".. act .. "\n.nlc to clear\n List:" .. ttext
local htext="Nodelist edit mode\n .nla/.nlr to switch\n punch node to ".. act .. "\n.nlc to clear\n"
local text ="List: ".. ttext
if help then text=htext..text end
if nled_hud then
minetest.localplayer:hud_change(nled_hud,'text',text)
else