Add cmsg chat command

master
Wuzzy 2017-02-09 12:43:57 +01:00
parent 066fba7a3c
commit 82abee5669
2 changed files with 33 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# Central Message
## Overview
* Description: Simple API to display short messages at the center of the screen
* Description: Simple API and server command to display short messages at the center of the screen
* Author: Wuzzy
* License of everything: WTFPL
* Shortname: `central_message`
@ -12,6 +12,9 @@ Each message is displayed for a few seconds, then it is removed.
When multiple messages are pushed quickly in succession, the messages will be “stacked”
on the screen.
This mod adds the server command “cmsg” as well as an API for mods to display messages.
The syntax is “`/cmsg <player> <text>`”. If `<player>` is “*”, the message is sent to all players.
This mod can be useful to inform about all sorts of events and is an alternative to use the chat log
to display special events.
@ -21,6 +24,7 @@ Some usage examples:
* Error message directed to a single player
* Informational messages
* Administational messages to warn players about a coming server shutdown
* Show messages by using a command block from Mesecons
## Settings
This mod can be configured via `minetest.conf`.

View File

@ -141,6 +141,34 @@ minetest.register_on_leaveplayer(function(player)
cmsg.hudids[player:get_player_name()] = nil
end)
minetest.register_privilege("announce", {
description = "Can use /cmsg",
give_to_singleplayer = false,
})
minetest.register_chatcommand("cmsg", {
description = "Show message in the center of the screen to player (“*” sends to all players)",
privs = {announce = true},
params = {"<player> <text>"},
func = function(name, params)
local player = minetest.get_player_by_name(name)
local targetname, text = string.match(params, "^(%S+)%s(.+)$")
if not targetname then
return false, "Invalid usage, see /help title"
end
if targetname == "*" then
cmsg.push_message_all(text)
return true, "Message sent."
else
local target = minetest.get_player_by_name(targetname)
if not target then
return false, core.colorize("#FF0000", "The player "..targetname.." is not online.")
end
cmsg.push_message_player(target, text)
return true, "Message sent."
end
end,
})
-- Horrible Workaround code starts here
cmsg.steps = 0
cmsg.last_push = -1