add /mtimer help chat command

Issue: https://github.com/dsohler/mtimer/issues/1
This commit is contained in:
Dirk Sohler 2017-07-29 21:41:24 +02:00
parent 43c633732e
commit ba2f0c9147

@ -2,6 +2,10 @@
--
-- Colorizes a string in a given hexadecimal color coded color. The string will
-- be returned including a reset color escape (assumably white text color)
--
-- @param color The hexadecimal value for the color you want to use
-- @param string The string that has to be colorized
-- @return string The colorized string
local colorize = function (color, string)
local c = minetest.get_color_escape_sequence('#'..string.upper(color))
local r = minetest.get_color_escape_sequence('#FFFFFF')
@ -9,6 +13,27 @@ local colorize = function (color, string)
end
-- Show help to the player
--
-- @param player The player to show the help to
local show_help = function (player)
local help = colorize('729fcf', 'Mtimer Help')..'\n'
local name = player:get_player_name()
help = help..' '..colorize('73d216', '/mtimer help')..' = '
help = help..'Show this messaget\n'
help = help..' '..colorize('73d216', '/mtimer show')..' = '
help = help..'List the current configuration\n'
help = help..' '..colorize('73d216', '/mtimer set setting value')..' = '
help = help..'Set '..colorize('73d216', 'setting')..' to '
help = help..colorize('73d216', 'value')
minetest.chat_send_player(name, help)
end
-- Show the configuration to the player
--
-- Gathers all settable variables and prints them to the player
@ -16,7 +41,7 @@ end
-- @param player The player object of the player to print to
local show_configuration = function (player)
local name = player:get_player_name()
local result_string = colorize('729fcf', 'MTimer configuration')..'\n'
local result_string = colorize('729fcf', 'MTimer Configuration')..'\n'
local font_color = player:get_attribute('mtimer:font_color')
local configuration = {
@ -56,8 +81,8 @@ minetest.register_chatcommand('mtimer', {
local player = minetest.get_player_by_name(name)
local action = parameters:match('%a+')
local payload = parameters:gsub('^%a+ ', '')
if action == 'show' then show_configuration(player) end
if action == 'help' then show_help(player) end
if action == 'show' then show_configuration(player) end
if action == 'set' and payload ~= nil then set(player, payload) end
end
})