1 local init
= os
.clock()
4 -- ["MATCH"] = {"FORMAT" COLOR PRIV}, --
5 ["#(.+)"] = {"*** %s: %s ***", 0xFFFF00, "server"},
7 DEFAULT_FORMAT
= "%s: %s"
8 DEFAULT_COLOR
= 0xEEF3EE
10 MESSAGES_ON_SCREEN
= 10
20 function addMessage(player
, new_text
, new_color
)
24 for id
= firsthud
, (firsthud
+MESSAGES_ON_SCREEN
-1) do
25 hud
= player
:hud_get(id
)
26 if hud
and hud
.name
== "chat" then
28 temp_color
= hud
.number
29 player
:hud_change(id
, "number", new_color
)
30 player
:hud_change(id
, "text", new_text
)
32 new_color
= temp_color
37 function sendMessage(player
, message
, color
)
39 while message
:len() > MAX_LENGTH
do
40 splitter
= string.find (message
, " ", MAX_LENGTH
)
41 if splitter
== nil then
44 addMessage(player
, message
:sub(0,splitter
), color
)
45 message
= message
:sub(splitter
+1)
47 addMessage(player
, message
, color
)
50 minetest
.register_on_joinplayer(function(player
)
51 minetest
.after(2, function(player
)
52 for i
= 1, MESSAGES_ON_SCREEN
do
53 local hud_id
= player
:hud_add({
54 hud_elem_type
= "text",
56 position
= {x
= LEFT_INDENT
, y
= TOP_INDENT
},
58 scale
= {x
=500, y
=50},
62 alignment
= {x
=1, y
=0},
63 offset
= {x
=0, y
=-i
*FONT_HEIGHT
}
73 minetest
.register_on_chat_message(function(name
, message
)
76 pl
= minetest
.get_player_by_name(name
)
77 pls
= minetest
.get_connected_players()
78 -- formats (see config zone)
79 for m
, f
in pairs(formats
) do
80 submes
= string.match(message
, m
)
82 if not f
[3] then -- if PRIV==nil
86 elseif minetest
.check_player_privs(name
, {[f
[3]]
=true}) then
99 if minetest
.check_player_privs(name
, {["server"]=true,}) then
100 name
= GM_PREFIX
.. name
104 sendMessage(pls
[i
], string.format(fmt
, name
, submes
), color
)
109 local time_to_load
= os
.clock() - init
110 print(string.format("[MOD] "..minetest
.get_current_modname().." loaded in %.4f s", time_to_load
))