Add command /tag-color

This commit is contained in:
badgamernl
2020-11-04 00:38:01 +01:00
parent 9e150aff79
commit 61a3f92982
4 changed files with 56 additions and 5 deletions

View File

@@ -7,22 +7,43 @@ local Commands = require 'expcore.commands' --- @dep expcore.commands
local Roles = require 'expcore.roles' --- @dep expcore.roles
require 'config.expcore.command_general_parse'
require 'config.expcore.command_role_parse'
require 'config.expcore.command_color_parse'
--- Stores the tag for a player
local PlayerData = require 'expcore.player_data' --- @dep expcore.player_data
local PlayerTags = PlayerData.Settings:combine('Tag')
local PlayerTagColors = PlayerData.Settings:combine('TagColor')
PlayerTags:set_metadata{
permission = 'command/tag'
}
PlayerTagColors:set_metadata{
permission = 'command/tag-color'
}
local set_tag = function (player, tag, color)
if tag == nil or tag == '' then
player.tag = ''
elseif color then
player.tag = '- [color='.. color ..']'..tag..'[/color]'
else
player.tag = '- '..tag
end
end
--- When your tag is updated then apply the changes
PlayerTags:on_update(function(player_name, player_tag)
local player = game.players[player_name]
if player_tag == nil or player_tag == '' then
player.tag = ''
else
player.tag = '- '..player_tag
end
local player_tag_color = PlayerTagColors:get(player)
set_tag(player, player_tag, player_tag_color)
end)
--- When your tag color is updated then apply the changes
PlayerTagColors:on_update(function(player_name, player_tag_color)
local player = game.players[player_name]
local player_tag = PlayerTags:get(player)
set_tag(player, player_tag, player_tag_color)
end)
--- Sets your player tag.
@@ -35,6 +56,16 @@ Commands.new_command('tag', 'Sets your player tag.')
PlayerTags:set(player, tag)
end)
--- Sets your player tag color.
-- @command tag
-- @tparam string color name.
Commands.new_command('tag-color', 'Sets your player tag color.')
:add_param('color', false, 'color')
:enable_auto_concat()
:register(function(player, color)
PlayerTagColors:set(player, color)
end)
--- Clears your tag. Or another player if you are admin.
-- @command tag-clear
-- @tparam[opt=self] LuaPlayer player the player to remove the tag from, nil will apply to self