3 cmsg
.active_messages
= {}
5 cmsg
.default_color
= 0xFFFFFF
7 cmsg
.push_message_player
= function(player
, text
, color
)
8 local function push(tbl
)
9 -- Horrible Workaround code starts here
10 if not (cmsg
.last_push
< cmsg
.steps
) then
11 minetest
.after(0, push
, tbl
)
15 local player
= tbl
.player
17 local color
= tbl
.color
18 -- Horrible Workaround code ends here
20 local pname
= player
:get_player_name()
21 if color
== nil then color
= cmsg
.default_color
end
22 if cmsg
.hudids
[pname
] == nil then
23 cmsg
.hudids
[pname
] = {}
24 cmsg
.active_messages
[pname
] = 0
26 -- move older HUD IDs up
27 for hudid
,tbl
in pairs(cmsg
.hudids
[pname
]) do
28 tbl
.stackpos
= tbl
.stackpos
+ 1
29 player
:hud_change(hudid
, "offset", {x
=0,y
=-128-(18*tbl
.stackpos
)})
32 local hudid
= player
:hud_add({
33 hud_elem_type
= "text",
36 position
= {x
=0.5, y
=0.5},
37 offset
= {x
=0,y
=-128},
39 alignment
= {x
=0,y
=0},
43 cmsg
.hudids
[pname
][hudid
] = {stackpos
=0}
44 cmsg
.active_messages
[pname
] = cmsg
.active_messages
[pname
] + 1
46 minetest
.after(5, function(param
)
47 local pname
= param
.player
:get_player_name()
48 param
.player
:hud_remove(param
.hudid
)
49 cmsg
.hudids
[pname
][param
.hudid
] = nil
50 cmsg
.active_messages
[pname
] = cmsg
.active_messages
[pname
] - 1
51 end, {player
=player
, hudid
= hudid
})
53 -- Update timer for Horrible Workaround
54 cmsg
.last_push
= cmsg
.steps
57 if cmsg
.last_push
< cmsg
.steps
then
58 push({player
=player
, text
=text
, color
=color
})
60 minetest
.after(0, push
, {player
=player
, text
=text
, color
=color
})
64 cmsg
.push_message_all
= function(text
, color
)
65 local players
= minetest
.get_connected_players()
67 cmsg
.push_message_player(players
[i
], text
, color
)
71 minetest
.register_on_leaveplayer(function(player
)
72 cmsg
.hudids
[player
:get_player_name()] = nil
75 -- Horrible Workaround code starts here
78 minetest
.register_globalstep(function(dtime
)
79 cmsg
.steps
= cmsg
.steps
+ 1
81 -- Horrible Workaround code ends here