Add entity nametags to hide nametags behind nodes

This commit is contained in:
rubenwardy 2018-01-21 20:40:41 +00:00
parent ff3eb5e49f
commit 526b4fdad3
159 changed files with 179 additions and 9 deletions

@ -1 +1 @@
Subproject commit 8b12a8e4f12ec12a076a161b7ed808ab147e785f Subproject commit 87d0438db65a41780d02431aee5a286d65a86059

View file

@ -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

View file

@ -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
View 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
View 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)

View file

@ -0,0 +1 @@
ctf_flag

14
mods/playertag/init.lua Normal file
View 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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Some files were not shown because too many files have changed in this diff Show more