Change nametag color on capture
This commit is contained in:
parent
1cfb4ae8ef
commit
4d225d61d5
@ -1,22 +1,41 @@
|
|||||||
ctf.hud.register_part(function(player, name, tplayer)
|
function ctf_colors.get_color(name, tplayer)
|
||||||
local text_color = ctf.team(tplayer.team).data.color
|
local tcolor_text = ctf.team(tplayer.team).data.color
|
||||||
local color = ctf.flag_colors[text_color]
|
local tcolor_hex = ctf.flag_colors[tcolor_text]
|
||||||
if not color then
|
if not tcolor_hex then
|
||||||
color = "0x000000"
|
tcolor_hex = "0x000000"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return tcolor_text, tcolor_hex
|
||||||
|
end
|
||||||
|
|
||||||
|
function ctf_colors.get_nametag_color(name, tplayer, tcolor_text, tcolor_hex)
|
||||||
|
if ctf.setting("colors.nametag.tcolor") then
|
||||||
|
return "0xFF" .. string.sub(tcolor_hex, 3)
|
||||||
|
else
|
||||||
|
return "0xFFFFFFFF"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ctf_colors.update(player, name, tplayer)
|
||||||
|
if not player then
|
||||||
|
player = minetest.get_player_by_name(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
local tcolor_text, tcolor_hex = ctf_colors.get_color(name, tplayer)
|
||||||
|
|
||||||
if ctf.setting("colors.nametag") then
|
if ctf.setting("colors.nametag") then
|
||||||
player:set_nametag_attributes({ color = "0xFF" .. string.sub(color, 3) })
|
player:set_nametag_attributes({
|
||||||
|
color = ctf_colors.get_nametag_color(name, tplayer, tcolor_text, tcolor_hex) })
|
||||||
end
|
end
|
||||||
|
|
||||||
if ctf.setting("colors.skins") and text_color and color then
|
if ctf.setting("colors.skins") and tcolor_text and tcolor_hex then
|
||||||
if minetest.global_exists("armor") then
|
if minetest.global_exists("armor") then
|
||||||
-- TODO: how should support for skin mods be done?
|
-- TODO: how should support for skin mods be done?
|
||||||
armor.textures[name].skin = "ctf_colors_skin_" .. text_color .. ".png"
|
armor.textures[name].skin = "ctf_colors_skin_" .. tcolor_text .. ".png"
|
||||||
armor:update_player_visuals(player)
|
armor:update_player_visuals(player)
|
||||||
else
|
else
|
||||||
player:set_properties({
|
player:set_properties({
|
||||||
textures = {"ctf_colors_skin_" .. text_color .. ".png"}
|
textures = {"ctf_colors_skin_" .. tcolor_text .. ".png"}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -27,15 +46,18 @@ ctf.hud.register_part(function(player, name, tplayer)
|
|||||||
position = {x = 1, y = 0},
|
position = {x = 1, y = 0},
|
||||||
scale = {x = 100, y = 100},
|
scale = {x = 100, y = 100},
|
||||||
text = "Team " .. tplayer.team,
|
text = "Team " .. tplayer.team,
|
||||||
number = color,
|
number = tcolor_hex,
|
||||||
offset = {x = -20, y = 20},
|
offset = {x = -20, y = 20},
|
||||||
alignment = {x = -1, y = 0}
|
alignment = {x = -1, y = 0}
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
ctf.hud:change(player, "ctf:hud_team", "text", "Team " .. tplayer.team)
|
ctf.hud:change(player, "ctf:hud_team", "text", "Team " .. tplayer.team)
|
||||||
ctf.hud:change(player, "ctf:hud_team", "number", color)
|
ctf.hud:change(player, "ctf:hud_team", "number", tcolor_hex)
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
|
|
||||||
|
ctf.hud.register_part(ctf_colors.update)
|
||||||
|
|
||||||
--[[if minetest.global_exists("armor") and armor.get_player_skin then
|
--[[if minetest.global_exists("armor") and armor.get_player_skin then
|
||||||
print("3d_armor detected!")
|
print("3d_armor detected!")
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
ctf.flag_colors = {
|
-- Supported colors
|
||||||
|
ctf_colors = {}
|
||||||
|
ctf_colors.colors = {
|
||||||
red = "0xFF4444",
|
red = "0xFF4444",
|
||||||
cyan = "0x00FFFF",
|
cyan = "0x00FFFF",
|
||||||
blue = "0x4466FF",
|
blue = "0x4466FF",
|
||||||
@ -12,11 +14,13 @@ ctf.flag_colors = {
|
|||||||
orange = "0xFFA500",
|
orange = "0xFFA500",
|
||||||
gold = "0x808000"
|
gold = "0x808000"
|
||||||
}
|
}
|
||||||
|
ctf.flag_colors = ctf_colors.colors
|
||||||
|
|
||||||
ctf.register_on_init(function()
|
ctf.register_on_init(function()
|
||||||
ctf.log("colors", "Initialising...")
|
ctf.log("colors", "Initialising...")
|
||||||
ctf._set("colors.skins", false)
|
ctf._set("colors.skins", false)
|
||||||
ctf._set("colors.nametag", true)
|
ctf._set("colors.nametag", true)
|
||||||
|
ctf._set("colors.nametag.tcolor", false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
dofile(minetest.get_modpath("ctf_colors") .. "/hud.lua")
|
dofile(minetest.get_modpath("ctf_colors") .. "/hud.lua")
|
||||||
|
@ -50,6 +50,15 @@ function ctf_flag.collect_claimed()
|
|||||||
return claimed
|
return claimed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ctf_flag.get_claimed_by_player(name)
|
||||||
|
local claimed = ctf_flag.collect_claimed()
|
||||||
|
for _, flag in pairs(claimed) do
|
||||||
|
if flag.claimed.player == name then
|
||||||
|
return name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function ctf_flag.player_drop_flag(name)
|
function ctf_flag.player_drop_flag(name)
|
||||||
if not name then
|
if not name then
|
||||||
return
|
return
|
||||||
|
@ -114,6 +114,24 @@ ctf_flag.register_on_pick_up(function(attname, flag)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Change nametag color
|
||||||
|
local oldntc = ctf_colors.get_nametag_color
|
||||||
|
function ctf_colors.get_nametag_color(name, tplayer, tcolor_text, tcolor_hex)
|
||||||
|
if ctf_flag.get_claimed_by_player(name) then
|
||||||
|
return "0xFFFF0000"
|
||||||
|
else
|
||||||
|
return oldntc(name, tplayer, tcolor_text, tcolor_hex)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ctf_flag.register_on_pick_up(function(attname, flag)
|
||||||
|
ctf_colors.update(nil, attname, ctf.player(attname))
|
||||||
|
end)
|
||||||
|
|
||||||
|
ctf_flag.register_on_drop(function(attname, flag)
|
||||||
|
ctf_colors.update(nil, attname, ctf.player(attname))
|
||||||
|
end)
|
||||||
|
|
||||||
-- Drop after time
|
-- Drop after time
|
||||||
local pickup_times = {}
|
local pickup_times = {}
|
||||||
ctf_flag.register_on_pick_up(function(attname, flag)
|
ctf_flag.register_on_pick_up(function(attname, flag)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user