Limit # of messages shown at once (default 7)

This commit is contained in:
Wuzzy 2015-07-01 23:59:49 +02:00
parent 8b773dbd36
commit d557b5d4e4
2 changed files with 23 additions and 1 deletions

View File

@ -21,6 +21,13 @@ Some usage examples:
* Informational messages
* Administational messages to warn players about a coming server shutdown
## Settings
This mod can be configured via `minetest.conf`.
Currently, one setting is recognized:
* `central_message_max`: Limit the number of messages displayed at once, by providing a number. Use `inf` here for no limit. Default: 7
## API
### `cmsg.push_message_player(player, message, color)`

View File

@ -1,6 +1,15 @@
cmsg = {}
cmsg.hudids = {}
cmsg.active_messages = {}
cmsg.settings = {}
cmsg.settings.max_messages = 7
local setting = minetest.setting_get("central_message_max")
if type(tonumber(setting)) == "number" then
cmsg.settings.max_messages = tonumber(setting)
elseif setting == "inf" then
cmsg.settings.max_messages = nil
end
cmsg.default_color = 0xFFFFFF
@ -26,7 +35,13 @@ cmsg.push_message_player = function(player, text, color)
-- move older HUD IDs up
for hudid,tbl in pairs(cmsg.hudids[pname]) do
tbl.stackpos = tbl.stackpos + 1
player:hud_change(hudid, "offset", {x=0,y=-128-(18*tbl.stackpos)})
if cmsg.settings.max_messages and tbl.stackpos >= cmsg.settings.max_messages then
player:hud_remove(hudid)
cmsg.hudids[pname][hudid] = nil
cmsg.active_messages[pname] = cmsg.active_messages[pname] - 1
else
player:hud_change(hudid, "offset", {x=0,y=-128-(18*tbl.stackpos)})
end
end
end
local hudid = player:hud_add({