More callbacks

master
rubenwardy 2015-11-29 00:05:20 +00:00
parent dff4eee6c7
commit d273457d99
3 changed files with 17 additions and 4 deletions

View File

@ -244,7 +244,6 @@ minetest.after(10, ctf.check_save)
function ctf.save()
local file = io.open(minetest.get_worldpath().."/ctf.txt", "w")
ctf.needs_save = false
if file then
local out = {
teams = ctf.teams,
@ -263,6 +262,7 @@ function ctf.save()
file:write(minetest.serialize(out))
file:close()
ctf.needs_save = false
else
ctf.error("io", "CTF file failed to save!")
end

View File

@ -8,6 +8,12 @@ minetest.register_on_leaveplayer(function(player)
ctf.hud.players[player:get_player_name()] = nil
end)
ctf.register_on_join_team(function(name, tname)
if ctf.setting("hud") then
ctf.hud.update(minetest.get_player_by_name(name))
end
end)
function ctf.hud.update(player)
if not player then
return

View File

@ -126,6 +126,14 @@ function ctf.remove_player(name)
end
end
ctf.registered_on_join_team = {}
function ctf.register_on_join_team(func)
if ctf._mt_loaded then
error("You can't register callbacks at game time!")
end
table.insert(ctf.registered_on_join_team, func)
end
-- Player joins team
-- Called by /join, /team join or auto allocate.
function ctf.join(name, team, force, by)
@ -184,10 +192,9 @@ function ctf.join(name, team, force, by)
minetest.log("action", name .. " joined team " .. team)
minetest.chat_send_all(name.." has joined team "..team)
if ctf.setting("hud") then
ctf.hud.update(minetest.get_player_by_name(name))
for i = 1, #ctf.registered_on_join_team do
ctf.registered_on_join_team[i](name, team)
end
return true
end