Add event log, update ctf_pvp_engine
This commit is contained in:
parent
0b8a95ff2f
commit
abcd3c176f
6 changed files with 128 additions and 1 deletions
2
mods/ctf_events/depends.txt
Normal file
2
mods/ctf_events/depends.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
ctf
|
||||
hudkit
|
125
mods/ctf_events/init.lua
Normal file
125
mods/ctf_events/init.lua
Normal file
|
@ -0,0 +1,125 @@
|
|||
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
|
||||
|
||||
ctf.register_on_killedplayer(function(victim, killer, type)
|
||||
ctf_events.post("kill_" .. type, killer, victim)
|
||||
ctf_events.update_all()
|
||||
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
|
||||
local tone_text, tone_hex = ctf_colors.get_color(evt.one, ctf.player(evt.one))
|
||||
if hud:exists(player, idx) then
|
||||
hud:change(player, idx, "text", evt.one)
|
||||
hud:change(player, idx, "number", tone_hex)
|
||||
else
|
||||
local tmp = {
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0, y = 0.8},
|
||||
scale = {x = 200, y = 100},
|
||||
text = evt.one,
|
||||
number = tone_hex,
|
||||
offset = {x = 145, y = -y_pos},
|
||||
alignment = {x = -1, y = 0}
|
||||
}
|
||||
hud:add(player, idx, tmp)
|
||||
end
|
||||
|
||||
-- Two
|
||||
if evt.two then
|
||||
local ttwo_text, ttwo_hex = ctf_colors.get_color(evt.two, ctf.player(evt.two))
|
||||
if hud:exists(player, idx2) then
|
||||
hud:change(player, idx2, "text", evt.two)
|
||||
hud:change(player, idx2, "number", ttwo_hex)
|
||||
else
|
||||
local tmp = {
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0, y = 0.8},
|
||||
scale = {x = 200, y = 100},
|
||||
text = evt.two,
|
||||
number = ttwo_hex,
|
||||
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()
|
||||
print("Updating events log")
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
ctf_events.update(player)
|
||||
end
|
||||
minetest.after(10, ctf_events.update_all)
|
||||
end
|
||||
minetest.after(10, ctf_events.update_all)
|
BIN
mods/ctf_events/textures/ctf_events_kill_bullet.png
Normal file
BIN
mods/ctf_events/textures/ctf_events_kill_bullet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 274 B |
BIN
mods/ctf_events/textures/ctf_events_kill_grenade.png
Normal file
BIN
mods/ctf_events/textures/ctf_events_kill_grenade.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 381 B |
BIN
mods/ctf_events/textures/ctf_events_kill_sword.png
Normal file
BIN
mods/ctf_events/textures/ctf_events_kill_sword.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 168 B |
|
@ -1 +1 @@
|
|||
Subproject commit 386d72965e4c13eac575c2dbed1b32e3724d835d
|
||||
Subproject commit f1bc56f4cda629d3a66147172227f7db57774594
|
Loading…
Reference in a new issue