Skip to content
This repository has been archived by the owner on Aug 29, 2019. It is now read-only.

Commit

Permalink
Alerts via HUD who has a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Sep 8, 2015
1 parent 60e4e06 commit 43e4d7f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
15 changes: 0 additions & 15 deletions ctf/hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ function ctf.hud.update(player)
end
end

ctf.hud.register_part(function(player, name, tplayer)
if not ctf.hud:exists(player, "ctf:hud_team") then
ctf.hud:add(player, "ctf:hud_team", {
hud_elem_type = "text",
position = {x = 1, y = 0},
scale = {x = 100, y = 100},
text = tplayer.team,
number = "0x000000",
offset = {x=-100, y = 20}
})
else
ctf.hud:change(player, "ctf:hud_team", "text", tplayer.team)
end
end)

function ctf.hud.updateAll()
if not ctf.setting("hud") then
return
Expand Down
3 changes: 2 additions & 1 deletion ctf_colors/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ ctf.hud.register_part(function(player, name, tplayer)
scale = {x = 100, y = 100},
text = tplayer.team,
number = color,
offset = {x=-100, y = 20}
offset = {x = -20, y = 20},
alignment = {x = -1, y = 0}
})
else
ctf.hud:change(player, "ctf:hud_team", "number", color)
Expand Down
2 changes: 2 additions & 0 deletions ctf_flag/flag_func.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ local function do_capture(attname, flag, returned)
player = attname
}

ctf.hud.updateAll()

ctf_flag.update(flag)

for i = 1, #ctf_flag.registered_on_pick_up do
Expand Down
31 changes: 31 additions & 0 deletions ctf_flag/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ ctf.hud.register_part(function(player, name, tplayer)
end
end)

ctf.hud.register_part(function(player, name, tplayer)
local alert = nil
local team = ctf.team(tplayer.team)
for _, flag in pairs(team.flags) do
if flag.claimed then
alert = "Kill " .. flag.claimed.player .. ", they have your flag!"
break
end
end

if alert then
if ctf.hud:exists(player, "ctf:hud_team_alert") then
ctf.hud:change(player, "ctf:hud_team_alert", "text", alert)
else
ctf.hud:add(player, "ctf:hud_team_alert", {
hud_elem_type = "text",
position = {x = 1, y = 0},
scale = {x = 100, y = 100},
text = alert,
number = "0xFF0000",
offset = {x = -10, y = 50},
alignment = {x = -1, y = 0}
})
end
else
ctf.hud:remove(player, "ctf:hud_team_alert")
end
end)

dofile(minetest.get_modpath("ctf_flag") .. "/gui.lua")
dofile(minetest.get_modpath("ctf_flag") .. "/flag_func.lua")

Expand Down Expand Up @@ -127,6 +156,8 @@ function ctf_flag.player_drop_flag(name)
end
flag_name = flag.team .. "'s " .. flag_name .. "flag"

ctf.hud.updateAll()

ctf.action("flag", name .. " dropped " .. flag_name)
minetest.chat_send_all(flag_name.." has returned.")
end
Expand Down

0 comments on commit 43e4d7f

Please sign in to comment.