Limit # of messages shown at once (default 7)
This commit is contained in:
parent
8b773dbd36
commit
d557b5d4e4
@ -21,6 +21,13 @@ Some usage examples:
|
|||||||
* Informational messages
|
* Informational messages
|
||||||
* Administational messages to warn players about a coming server shutdown
|
* 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
|
## API
|
||||||
### `cmsg.push_message_player(player, message, color)`
|
### `cmsg.push_message_player(player, message, color)`
|
||||||
|
15
init.lua
15
init.lua
@ -1,6 +1,15 @@
|
|||||||
cmsg = {}
|
cmsg = {}
|
||||||
cmsg.hudids = {}
|
cmsg.hudids = {}
|
||||||
cmsg.active_messages = {}
|
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
|
cmsg.default_color = 0xFFFFFF
|
||||||
|
|
||||||
@ -26,9 +35,15 @@ cmsg.push_message_player = function(player, text, color)
|
|||||||
-- move older HUD IDs up
|
-- move older HUD IDs up
|
||||||
for hudid,tbl in pairs(cmsg.hudids[pname]) do
|
for hudid,tbl in pairs(cmsg.hudids[pname]) do
|
||||||
tbl.stackpos = tbl.stackpos + 1
|
tbl.stackpos = tbl.stackpos + 1
|
||||||
|
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)})
|
player:hud_change(hudid, "offset", {x=0,y=-128-(18*tbl.stackpos)})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
local hudid = player:hud_add({
|
local hudid = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
text = text,
|
text = text,
|
||||||
|
Loading…
Reference in New Issue
Block a user