Add entity nametags to hide nametags behind nodes
|
@ -1 +1 @@
|
||||||
Subproject commit 8b12a8e4f12ec12a076a161b7ed808ab147e785f
|
Subproject commit 87d0438db65a41780d02431aee5a286d65a86059
|
|
@ -1,7 +1,9 @@
|
||||||
minetest.register_can_bypass_userlimit(function(name, ip)
|
if minetest.register_can_bypass_userlimit then
|
||||||
|
minetest.register_can_bypass_userlimit(function(name, ip)
|
||||||
local pstat, discard = ctf_stats.player_or_nil(name)
|
local pstat, discard = ctf_stats.player_or_nil(name)
|
||||||
local actual_max_users = tonumber(minetest.settings:get("max_users")) +
|
local actual_max_users = tonumber(minetest.settings:get("max_users")) +
|
||||||
tonumber(minetest.settings:get("max_extra_users") or "10")
|
tonumber(minetest.settings:get("max_extra_users") or "10")
|
||||||
local req_score = tonumber(minetest.settings:get("userlimit_bypass_required_score") or "10000")
|
local req_score = tonumber(minetest.settings:get("userlimit_bypass_required_score") or "10000")
|
||||||
return pstat and pstat.score > req_score and #minetest.get_connected_players() < actual_max_users
|
return pstat and pstat.score > req_score and #minetest.get_connected_players() < actual_max_users
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
|
|
@ -48,7 +48,7 @@ local function add_HP_gauge(name)
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local ent = minetest.add_entity(pos, "gauges:hp_bar")
|
local ent = minetest.add_entity(pos, "gauges:hp_bar")
|
||||||
if ent ~= nil then
|
if ent ~= nil then
|
||||||
ent:set_attach(player, "", {x = 0, y = 10, z = 0}, {x = 0, y = 0, z = 0})
|
ent:set_attach(player, "", {x = 0, y = 9, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
ent = ent:get_luaentity()
|
ent = ent:get_luaentity()
|
||||||
ent.wielder = player:get_player_name()
|
ent.wielder = player:get_player_name()
|
||||||
end
|
end
|
||||||
|
|
5
mods/playertag/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
This mod hides the existing tags, and adds entity based tags that are only as visible as the player.
|
||||||
|
|
||||||
|
Some code taken from gauges (CC0 1.0) https://forum.minetest.net/viewtopic.php?t=10250
|
||||||
|
And also some code and textures from npcf (LGPL for code, WTFPL for textures) https://forum.minetest.net/viewtopic.php?t=7321
|
||||||
|
My part of the code is WTFPL.
|
148
mods/playertag/api.lua
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
local nametags = {}
|
||||||
|
local tag_settings = {}
|
||||||
|
local ATTACH_POSITION = minetest.rgba and {x=0,y=20,z=0} or {x=0,y=10,z=0}
|
||||||
|
|
||||||
|
local TYPE_BUILTIN = 0
|
||||||
|
local TYPE_ENTITY = 1
|
||||||
|
playertag = {
|
||||||
|
TYPE_BUILTIN = TYPE_BUILTIN,
|
||||||
|
TYPE_ENTITY = TYPE_ENTITY,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function add_entity_tag(player)
|
||||||
|
local ent = minetest.add_entity(player:get_pos(), "playertag:tag")
|
||||||
|
|
||||||
|
-- Build name from font texture
|
||||||
|
local color = "W"
|
||||||
|
local texture = "npcf_tag_bg.png"
|
||||||
|
local x = math.floor(134 - ((player:get_player_name():len() * 11) / 2))
|
||||||
|
local i = 0
|
||||||
|
player:get_player_name():gsub(".", function(char)
|
||||||
|
if char:byte() > 64 and char:byte() < 91 then
|
||||||
|
char = "U"..char
|
||||||
|
end
|
||||||
|
texture = texture.."^[combine:84x14:"..(x+i)..",0="..color.."_"..char..".png"
|
||||||
|
i = i + 11
|
||||||
|
end)
|
||||||
|
ent:set_properties({ textures={texture} })
|
||||||
|
|
||||||
|
-- Attach to player
|
||||||
|
ent:set_attach(player, "", ATTACH_POSITION, {x=0,y=0,z=0})
|
||||||
|
ent:get_luaentity().wielder = player:get_player_name()
|
||||||
|
|
||||||
|
-- Store
|
||||||
|
nametags[player:get_player_name()] = ent
|
||||||
|
|
||||||
|
-- Hide fixed nametag
|
||||||
|
player:set_nametag_attributes({
|
||||||
|
color = {a = 0, r = 0, g = 0, b = 0}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function remove_entity_tag(player)
|
||||||
|
tag_settings[player:get_player_name()] = nil
|
||||||
|
local tag = nametags[player:get_player_name()]
|
||||||
|
if tag then
|
||||||
|
tag:remove()
|
||||||
|
tag = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function update(player, settings)
|
||||||
|
tag_settings[player:get_player_name()] = settings
|
||||||
|
|
||||||
|
if settings.type == TYPE_BUILTIN then
|
||||||
|
minetest.log("error", "type: builtin")
|
||||||
|
remove_entity_tag(player)
|
||||||
|
print(dump(settings.color))
|
||||||
|
player:set_nametag_attributes({
|
||||||
|
color = settings.color
|
||||||
|
})
|
||||||
|
elseif settings.type == TYPE_ENTITY then
|
||||||
|
minetest.log("error", "type: entity")
|
||||||
|
add_entity_tag(player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function playertag.set(player, type, color)
|
||||||
|
local oldset = tag_settings[player:get_player_name()]
|
||||||
|
color = color or { a=255, r=255, g=255, b=255 }
|
||||||
|
if not oldset or oldset.type ~= type or oldset.color ~= color then
|
||||||
|
minetest.log("error", "updating")
|
||||||
|
update(player, { type = type, color = color })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local nametag = {
|
||||||
|
npcf_id = "nametag",
|
||||||
|
physical = false,
|
||||||
|
collisionbox = {x=0, y=0, z=0},
|
||||||
|
visual = "sprite",
|
||||||
|
textures = {"default_dirt.png"},--{"npcf_tag_bg.png"},
|
||||||
|
visual_size = {x=2.16, y=0.18, z=2.16},--{x=1.44, y=0.12, z=1.44},
|
||||||
|
}
|
||||||
|
|
||||||
|
function nametag:on_activate(staticdata, dtime_s)
|
||||||
|
if staticdata == "expired" then
|
||||||
|
minetest.log("error", "Nametag expired, removing")
|
||||||
|
local name = self.wielder and self.wielder:get_player_name()
|
||||||
|
if name and nametags[name] == self.object then
|
||||||
|
nametags[name] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function nametag:get_staticdata()
|
||||||
|
return "expired"
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("a", {
|
||||||
|
func = function(name)
|
||||||
|
playertag.set(minetest.get_player_by_name(name), TYPE_BUILTIN)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
function nametag:on_step(dtime)
|
||||||
|
local name = self.wielder
|
||||||
|
local wielder = name and minetest.get_player_by_name(name)
|
||||||
|
if not wielder then
|
||||||
|
minetest.log("error", "no such wielder, removing")
|
||||||
|
self.object:remove()
|
||||||
|
elseif not tag_settings[name] or tag_settings[name].type ~= TYPE_ENTITY then
|
||||||
|
minetest.log("error", "wrong player setting, removing")
|
||||||
|
if name and nametags[name] == self.object then
|
||||||
|
nametags[name] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_entity("playertag:tag", nametag)
|
||||||
|
|
||||||
|
local function step()
|
||||||
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
|
local settings = tag_settings[player:get_player_name()]
|
||||||
|
if settings and settings.type == TYPE_ENTITY then
|
||||||
|
local ent = nametags[player:get_player_name()]
|
||||||
|
if not ent or ent:get_luaentity() == nil then
|
||||||
|
add_entity_tag(player)
|
||||||
|
else
|
||||||
|
ent:set_attach(player, "", ATTACH_POSITION, {x=0,y=0,z=0})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.after(10, step)
|
||||||
|
end
|
||||||
|
minetest.after(10, step)
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
playertag.set(player, TYPE_ENTITY)
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function (player)
|
||||||
|
remove_entity_tag(player)
|
||||||
|
end)
|
1
mods/playertag/depends.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
ctf_flag
|
14
mods/playertag/init.lua
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
dofile(minetest.get_modpath("playertag") .. "/api.lua")
|
||||||
|
|
||||||
|
ctf_flag.register_on_pick_up(function(attname, flag)
|
||||||
|
playertag.set(minetest.get_player_by_name(attname), playertag.TYPE_BUILTIN,
|
||||||
|
{ a=255, r=255, g=0, b=0 })
|
||||||
|
end)
|
||||||
|
|
||||||
|
ctf_flag.register_on_drop(function(attname, flag)
|
||||||
|
playertag.set(minetest.get_player_by_name(attname), playertag.TYPE_ENTITY)
|
||||||
|
end)
|
||||||
|
|
||||||
|
ctf_flag.register_on_capture(function(attname, flag)
|
||||||
|
playertag.set(minetest.get_player_by_name(attname), playertag.TYPE_ENTITY)
|
||||||
|
end)
|
BIN
mods/playertag/textures/0.png
Normal file
After Width: | Height: | Size: 110 B |
BIN
mods/playertag/textures/1.png
Normal file
After Width: | Height: | Size: 111 B |
BIN
mods/playertag/textures/10.png
Normal file
After Width: | Height: | Size: 116 B |
BIN
mods/playertag/textures/11.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/12.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/13.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/14.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/15.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/16.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/17.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/18.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/19.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/2.png
Normal file
After Width: | Height: | Size: 116 B |
BIN
mods/playertag/textures/20.png
Normal file
After Width: | Height: | Size: 110 B |
BIN
mods/playertag/textures/3.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/4.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/5.png
Normal file
After Width: | Height: | Size: 115 B |
BIN
mods/playertag/textures/6.png
Normal file
After Width: | Height: | Size: 116 B |
BIN
mods/playertag/textures/7.png
Normal file
After Width: | Height: | Size: 116 B |
BIN
mods/playertag/textures/8.png
Normal file
After Width: | Height: | Size: 115 B |
BIN
mods/playertag/textures/9.png
Normal file
After Width: | Height: | Size: 115 B |
BIN
mods/playertag/textures/B_-.png
Normal file
After Width: | Height: | Size: 85 B |
BIN
mods/playertag/textures/B_0.png
Normal file
After Width: | Height: | Size: 129 B |
BIN
mods/playertag/textures/B_1.png
Normal file
After Width: | Height: | Size: 116 B |
BIN
mods/playertag/textures/B_2.png
Normal file
After Width: | Height: | Size: 131 B |
BIN
mods/playertag/textures/B_3.png
Normal file
After Width: | Height: | Size: 129 B |
BIN
mods/playertag/textures/B_4.png
Normal file
After Width: | Height: | Size: 128 B |
BIN
mods/playertag/textures/B_5.png
Normal file
After Width: | Height: | Size: 136 B |
BIN
mods/playertag/textures/B_6.png
Normal file
After Width: | Height: | Size: 142 B |
BIN
mods/playertag/textures/B_7.png
Normal file
After Width: | Height: | Size: 107 B |
BIN
mods/playertag/textures/B_8.png
Normal file
After Width: | Height: | Size: 128 B |
BIN
mods/playertag/textures/B_9.png
Normal file
After Width: | Height: | Size: 138 B |
BIN
mods/playertag/textures/B_UA.png
Normal file
After Width: | Height: | Size: 130 B |
BIN
mods/playertag/textures/B_UB.png
Normal file
After Width: | Height: | Size: 113 B |
BIN
mods/playertag/textures/B_UC.png
Normal file
After Width: | Height: | Size: 131 B |
BIN
mods/playertag/textures/B_UD.png
Normal file
After Width: | Height: | Size: 119 B |
BIN
mods/playertag/textures/B_UE.png
Normal file
After Width: | Height: | Size: 100 B |
BIN
mods/playertag/textures/B_UF.png
Normal file
After Width: | Height: | Size: 98 B |
BIN
mods/playertag/textures/B_UG.png
Normal file
After Width: | Height: | Size: 136 B |
BIN
mods/playertag/textures/B_UH.png
Normal file
After Width: | Height: | Size: 104 B |
BIN
mods/playertag/textures/B_UI.png
Normal file
After Width: | Height: | Size: 98 B |
BIN
mods/playertag/textures/B_UJ.png
Normal file
After Width: | Height: | Size: 109 B |
BIN
mods/playertag/textures/B_UK.png
Normal file
After Width: | Height: | Size: 140 B |
BIN
mods/playertag/textures/B_UL.png
Normal file
After Width: | Height: | Size: 98 B |
BIN
mods/playertag/textures/B_UM.png
Normal file
After Width: | Height: | Size: 124 B |
BIN
mods/playertag/textures/B_UN.png
Normal file
After Width: | Height: | Size: 130 B |
BIN
mods/playertag/textures/B_UO.png
Normal file
After Width: | Height: | Size: 120 B |
BIN
mods/playertag/textures/B_UP.png
Normal file
After Width: | Height: | Size: 117 B |
BIN
mods/playertag/textures/B_UQ.png
Normal file
After Width: | Height: | Size: 130 B |
BIN
mods/playertag/textures/B_UR.png
Normal file
After Width: | Height: | Size: 130 B |
BIN
mods/playertag/textures/B_US.png
Normal file
After Width: | Height: | Size: 147 B |
BIN
mods/playertag/textures/B_UT.png
Normal file
After Width: | Height: | Size: 93 B |
BIN
mods/playertag/textures/B_UU.png
Normal file
After Width: | Height: | Size: 101 B |
BIN
mods/playertag/textures/B_UV.png
Normal file
After Width: | Height: | Size: 128 B |
BIN
mods/playertag/textures/B_UW.png
Normal file
After Width: | Height: | Size: 122 B |
BIN
mods/playertag/textures/B_UX.png
Normal file
After Width: | Height: | Size: 114 B |
BIN
mods/playertag/textures/B_UY.png
Normal file
After Width: | Height: | Size: 116 B |
BIN
mods/playertag/textures/B_UZ.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
mods/playertag/textures/B__.png
Normal file
After Width: | Height: | Size: 83 B |
BIN
mods/playertag/textures/B_a.png
Normal file
After Width: | Height: | Size: 132 B |
BIN
mods/playertag/textures/B_b.png
Normal file
After Width: | Height: | Size: 128 B |
BIN
mods/playertag/textures/B_c.png
Normal file
After Width: | Height: | Size: 115 B |
BIN
mods/playertag/textures/B_d.png
Normal file
After Width: | Height: | Size: 123 B |
BIN
mods/playertag/textures/B_e.png
Normal file
After Width: | Height: | Size: 122 B |
BIN
mods/playertag/textures/B_f.png
Normal file
After Width: | Height: | Size: 102 B |
BIN
mods/playertag/textures/B_g.png
Normal file
After Width: | Height: | Size: 140 B |
BIN
mods/playertag/textures/B_h.png
Normal file
After Width: | Height: | Size: 113 B |
BIN
mods/playertag/textures/B_i.png
Normal file
After Width: | Height: | Size: 107 B |
BIN
mods/playertag/textures/B_j.png
Normal file
After Width: | Height: | Size: 112 B |
BIN
mods/playertag/textures/B_k.png
Normal file
After Width: | Height: | Size: 141 B |
BIN
mods/playertag/textures/B_l.png
Normal file
After Width: | Height: | Size: 107 B |
BIN
mods/playertag/textures/B_m.png
Normal file
After Width: | Height: | Size: 102 B |
BIN
mods/playertag/textures/B_n.png
Normal file
After Width: | Height: | Size: 112 B |
BIN
mods/playertag/textures/B_o.png
Normal file
After Width: | Height: | Size: 109 B |
BIN
mods/playertag/textures/B_p.png
Normal file
After Width: | Height: | Size: 138 B |
BIN
mods/playertag/textures/B_q.png
Normal file
After Width: | Height: | Size: 130 B |
BIN
mods/playertag/textures/B_r.png
Normal file
After Width: | Height: | Size: 103 B |
BIN
mods/playertag/textures/B_s.png
Normal file
After Width: | Height: | Size: 133 B |
BIN
mods/playertag/textures/B_t.png
Normal file
After Width: | Height: | Size: 112 B |
BIN
mods/playertag/textures/B_u.png
Normal file
After Width: | Height: | Size: 101 B |
BIN
mods/playertag/textures/B_v.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
mods/playertag/textures/B_w.png
Normal file
After Width: | Height: | Size: 122 B |
BIN
mods/playertag/textures/B_x.png
Normal file
After Width: | Height: | Size: 119 B |
BIN
mods/playertag/textures/B_y.png
Normal file
After Width: | Height: | Size: 138 B |
BIN
mods/playertag/textures/B_z.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/playertag/textures/W_-.png
Normal file
After Width: | Height: | Size: 78 B |
BIN
mods/playertag/textures/W_0.png
Normal file
After Width: | Height: | Size: 107 B |
BIN
mods/playertag/textures/W_1.png
Normal file
After Width: | Height: | Size: 93 B |
BIN
mods/playertag/textures/W_2.png
Normal file
After Width: | Height: | Size: 101 B |
BIN
mods/playertag/textures/W_3.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
mods/playertag/textures/W_4.png
Normal file
After Width: | Height: | Size: 110 B |
BIN
mods/playertag/textures/W_5.png
Normal file
After Width: | Height: | Size: 103 B |
BIN
mods/playertag/textures/W_6.png
Normal file
After Width: | Height: | Size: 114 B |