54 lines
1.4 KiB
Lua
54 lines
1.4 KiB
Lua
cmsg = {}
|
|
cmsg.hudids = {}
|
|
cmsg.active_messages = {}
|
|
|
|
cmsg.default_color = 0xFFFFFF
|
|
|
|
cmsg.push_message_player = function(player, text, color)
|
|
local pname = player:get_player_name()
|
|
if color == nil then color = cmsg.default_color end
|
|
if cmsg.hudids[pname] == nil then
|
|
cmsg.hudids[pname] = {}
|
|
cmsg.active_messages[pname] = 0
|
|
else
|
|
-- move older HUD IDs up
|
|
for hudid,tbl in pairs(cmsg.hudids[pname]) do
|
|
minetest.after(0, function()
|
|
tbl.stackpos = tbl.stackpos + 1
|
|
player:hud_change(hudid, "offset", {x=0,y=-128-(18*tbl.stackpos)})
|
|
end)
|
|
end
|
|
end
|
|
local hudid = player:hud_add({
|
|
hud_elem_type = "text",
|
|
text = text,
|
|
number = color,
|
|
position = {x=0.5, y=0.5},
|
|
offset = {x=0,y=-128},
|
|
direction = 0,
|
|
alignment = {x=0,y=0},
|
|
scale = {x=300,y=18},
|
|
})
|
|
|
|
cmsg.hudids[pname][hudid] = {stackpos=0}
|
|
cmsg.active_messages[pname] = cmsg.active_messages[pname] + 1
|
|
|
|
minetest.after(5, function(param)
|
|
local pname = param.player:get_player_name()
|
|
param.player:hud_remove(param.hudid)
|
|
cmsg.hudids[pname][param.hudid] = nil
|
|
cmsg.active_messages[pname] = cmsg.active_messages[pname] - 1
|
|
end, {player=player, hudid = hudid})
|
|
end
|
|
|
|
cmsg.push_message_all = function(text, color)
|
|
local players = minetest.get_connected_players()
|
|
for i=1,#players do
|
|
cmsg.push_message_player(players[i], text, color)
|
|
end
|
|
end
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
cmsg.hudids[player:get_player_name()] = nil
|
|
end)
|