2016-04-05 16:19:03 +00:00
|
|
|
local hud = hudkit()
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
hud.players[player:get_player_name()] = nil
|
|
|
|
end)
|
|
|
|
|
|
|
|
local NUM_EVT = 6
|
|
|
|
|
|
|
|
ctf_events = {
|
|
|
|
events = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ctf_events.post(action, one, two)
|
|
|
|
table.insert(ctf_events.events, 1, {
|
|
|
|
action = action,
|
|
|
|
one = one,
|
|
|
|
two = two
|
|
|
|
})
|
|
|
|
|
|
|
|
while #ctf_events.events > NUM_EVT do
|
|
|
|
table.remove(ctf_events.events, #ctf_events.events)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ctf_events.update_row(i, player, name, tplayer, evt)
|
|
|
|
local idx = "ctf_events:" .. i .. "_one"
|
|
|
|
local idxa = "ctf_events:" .. i .. "_action"
|
|
|
|
local idx2 = "ctf_events:" .. i .. "_two"
|
|
|
|
|
|
|
|
if not evt then
|
|
|
|
hud:remove(player, idx)
|
|
|
|
hud:remove(player, idxa)
|
|
|
|
hud:remove(player, idx2)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local y_pos = i * 20
|
|
|
|
|
|
|
|
-- One
|
2016-04-05 22:21:50 +00:00
|
|
|
if evt.one then
|
2019-04-09 08:31:18 +00:00
|
|
|
local tcolor = ctf_colors.get_color(ctf.player(evt.one))
|
2016-04-05 22:21:50 +00:00
|
|
|
if hud:exists(player, idx) then
|
|
|
|
hud:change(player, idx, "text", evt.one)
|
2019-04-09 08:31:18 +00:00
|
|
|
hud:change(player, idx, "number", tcolor.hex)
|
2016-04-05 22:21:50 +00:00
|
|
|
else
|
|
|
|
local tmp = {
|
|
|
|
hud_elem_type = "text",
|
|
|
|
position = {x = 0, y = 0.8},
|
|
|
|
scale = {x = 200, y = 100},
|
|
|
|
text = evt.one,
|
2019-04-09 08:31:18 +00:00
|
|
|
number = tcolor.hex,
|
2016-04-05 22:21:50 +00:00
|
|
|
offset = {x = 145, y = -y_pos},
|
|
|
|
alignment = {x = -1, y = 0}
|
|
|
|
}
|
|
|
|
hud:add(player, idx, tmp)
|
|
|
|
end
|
2016-04-05 16:19:03 +00:00
|
|
|
else
|
2016-04-05 22:21:50 +00:00
|
|
|
hud:remove(player, idx)
|
2016-04-05 16:19:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Two
|
|
|
|
if evt.two then
|
2019-04-09 08:31:18 +00:00
|
|
|
local tcolor = ctf_colors.get_color(ctf.player(evt.two))
|
2016-04-05 16:19:03 +00:00
|
|
|
if hud:exists(player, idx2) then
|
|
|
|
hud:change(player, idx2, "text", evt.two)
|
2019-04-09 08:31:18 +00:00
|
|
|
hud:change(player, idx2, "number", tcolor.hex)
|
2016-04-05 16:19:03 +00:00
|
|
|
else
|
|
|
|
local tmp = {
|
|
|
|
hud_elem_type = "text",
|
|
|
|
position = {x = 0, y = 0.8},
|
|
|
|
scale = {x = 200, y = 100},
|
|
|
|
text = evt.two,
|
2019-04-09 08:31:18 +00:00
|
|
|
number = tcolor.hex,
|
2016-04-05 16:19:03 +00:00
|
|
|
offset = {x = 175, y = -y_pos},
|
|
|
|
alignment = {x = 1, y = 0}
|
|
|
|
}
|
|
|
|
hud:add(player, idx2, tmp)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
hud:remove(player, idx2)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Action
|
|
|
|
if evt.action then
|
|
|
|
if hud:exists(player, idxa) then
|
|
|
|
hud:change(player, idxa, "text", "ctf_events_" .. evt.action .. ".png")
|
|
|
|
else
|
|
|
|
local tmp = {
|
|
|
|
hud_elem_type = "image",
|
|
|
|
position = {x = 0, y = 0.8},
|
|
|
|
scale = {x = 1, y = 1},
|
|
|
|
text = "ctf_events_" .. evt.action .. ".png",
|
|
|
|
offset = {x = 160, y = -y_pos},
|
|
|
|
alignment = {x = 0, y = 0}
|
|
|
|
}
|
|
|
|
hud:add(player, idxa, tmp)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
hud:remove(player, idxa)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ctf_events.update(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local tplayer = ctf.player_or_nil(name)
|
|
|
|
if tplayer then
|
|
|
|
for i=1, NUM_EVT do
|
|
|
|
local evt = nil
|
|
|
|
if #ctf_events.events >= i then
|
|
|
|
evt = ctf_events.events[i]
|
|
|
|
end
|
|
|
|
ctf_events.update_row(i, player, name, tplayer, evt)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ctf_events.update_all()
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
ctf_events.update(player)
|
|
|
|
end
|
|
|
|
end
|
2016-04-06 16:45:59 +00:00
|
|
|
|
2019-07-10 10:19:33 +00:00
|
|
|
ctf.register_on_killedplayer(function(victim, killer, stack, tool_caps)
|
2018-12-31 17:00:52 +00:00
|
|
|
local type = "sword"
|
2020-03-15 18:32:33 +00:00
|
|
|
|
|
|
|
if tool_caps.damage_groups.grenade then
|
|
|
|
type = "grenade"
|
|
|
|
elseif tool_caps.damage_groups.rocket then
|
|
|
|
type = "rocket"
|
2020-07-02 19:22:15 +00:00
|
|
|
elseif tool_caps.damage_groups.ranged then
|
2019-07-10 10:19:33 +00:00
|
|
|
type = "bullet"
|
2018-12-31 17:00:52 +00:00
|
|
|
end
|
2019-07-10 10:19:33 +00:00
|
|
|
|
2020-09-19 21:35:32 +00:00
|
|
|
if tool_caps.damage_groups.combat_log then
|
|
|
|
victim = victim .. " (Combat Log)"
|
|
|
|
elseif tool_caps.damage_groups.suicide then
|
|
|
|
victim = victim .. " (Suicide)"
|
|
|
|
end
|
|
|
|
|
2016-04-06 16:45:59 +00:00
|
|
|
ctf_events.post("kill_" .. type, killer, victim)
|
|
|
|
ctf_events.update_all()
|
|
|
|
end)
|
|
|
|
|
2017-10-06 02:02:16 +00:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
ctf_events.update(player)
|
|
|
|
end)
|
|
|
|
|
2018-12-30 23:08:05 +00:00
|
|
|
ctf_match.register_on_new_match(function()
|
2016-04-06 16:45:59 +00:00
|
|
|
ctf_events.events = {}
|
|
|
|
ctf_events.update_all()
|
|
|
|
end)
|