Partially colour nametag

This commit is contained in:
octacian 2017-06-27 18:18:04 -07:00
parent d4d82674e1
commit 358f171a42
4 changed files with 16 additions and 15 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 KiB

View File

@ -1,4 +1,4 @@
![Screenshot](.gh-screenshot.png) ![Screenshot](screenshot.png)
Advanced Ranks [ranks] Advanced Ranks [ranks]
======================= =======================

View File

@ -9,6 +9,17 @@ local default
--- API --- API
--- ---
-- [local function] Get colour
local function get_colour(colour)
if type(colour) == "table" and minetest.rgba then
return minetest.rgba(colour.r, colour.g, colour.b, colour.a)
elseif type(colour) == "string" then
return colour
else
return "#ffffff"
end
end
-- [function] Register rank -- [function] Register rank
function ranks.register(name, def) function ranks.register(name, def)
assert(name ~= "clear", "Invalid name \"clear\" for rank") assert(name ~= "clear", "Invalid name \"clear\" for rank")
@ -144,18 +155,17 @@ function ranks.update_nametag(player)
local rank = ranks.get_rank(player) local rank = ranks.get_rank(player)
if rank then if rank then
local def = ranks.get_def(rank) local def = ranks.get_def(rank)
local colour = def.colour or "#ffffff" local colour = get_colour(def.colour)
local prefix = def.prefix local prefix = def.prefix
if prefix then if prefix then
prefix = prefix.." " prefix = minetest.colorize(colour, prefix).." "
else else
prefix = "" prefix = ""
end end
player:set_nametag_attributes({ player:set_nametag_attributes({
text = prefix..name, text = prefix..name,
color = colour,
}) })
return true return true
@ -235,16 +245,7 @@ minetest.register_on_chat_message(function(name, message)
if rank then if rank then
local def = ranks.get_def(rank) local def = ranks.get_def(rank)
if def.prefix then if def.prefix then
local colour = def.colour or "#ffffff" local colour = get_colour(def.colour)
if type(colour) == "table" then
if minetest.rgba then
colour = minetest.rgba(colour.r, colour.g, colour.b, colour.a)
else
minetest.chat_send_all(def.prefix.." <"..name.."> "..message)
return true
end
end
minetest.chat_send_all(minetest.colorize(colour, def.prefix).. minetest.chat_send_all(minetest.colorize(colour, def.prefix)..
" <"..name.."> "..message) " <"..name.."> "..message)
return true return true
@ -253,7 +254,7 @@ minetest.register_on_chat_message(function(name, message)
end end
end) end)
--[chatcommand] /rank -- [chatcommand] /rank
minetest.register_chatcommand("rank", { minetest.register_chatcommand("rank", {
description = "Set a player's rank", description = "Set a player's rank",
params = "<player> <new rank> / \"list\" | username, rankname / list ranks", params = "<player> <new rank> / \"list\" | username, rankname / list ranks",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 547 KiB

After

Width:  |  Height:  |  Size: 281 KiB