More callbacks
This commit is contained in:
parent
dff4eee6c7
commit
d273457d99
@ -244,7 +244,6 @@ minetest.after(10, ctf.check_save)
|
|||||||
|
|
||||||
function ctf.save()
|
function ctf.save()
|
||||||
local file = io.open(minetest.get_worldpath().."/ctf.txt", "w")
|
local file = io.open(minetest.get_worldpath().."/ctf.txt", "w")
|
||||||
ctf.needs_save = false
|
|
||||||
if file then
|
if file then
|
||||||
local out = {
|
local out = {
|
||||||
teams = ctf.teams,
|
teams = ctf.teams,
|
||||||
@ -263,6 +262,7 @@ function ctf.save()
|
|||||||
|
|
||||||
file:write(minetest.serialize(out))
|
file:write(minetest.serialize(out))
|
||||||
file:close()
|
file:close()
|
||||||
|
ctf.needs_save = false
|
||||||
else
|
else
|
||||||
ctf.error("io", "CTF file failed to save!")
|
ctf.error("io", "CTF file failed to save!")
|
||||||
end
|
end
|
||||||
|
@ -8,6 +8,12 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
ctf.hud.players[player:get_player_name()] = nil
|
ctf.hud.players[player:get_player_name()] = nil
|
||||||
end)
|
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)
|
function ctf.hud.update(player)
|
||||||
if not player then
|
if not player then
|
||||||
return
|
return
|
||||||
|
@ -126,6 +126,14 @@ function ctf.remove_player(name)
|
|||||||
end
|
end
|
||||||
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
|
-- Player joins team
|
||||||
-- Called by /join, /team join or auto allocate.
|
-- Called by /join, /team join or auto allocate.
|
||||||
function ctf.join(name, team, force, by)
|
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.log("action", name .. " joined team " .. team)
|
||||||
minetest.chat_send_all(name.." has joined team "..team)
|
minetest.chat_send_all(name.." has joined team "..team)
|
||||||
|
|
||||||
if ctf.setting("hud") then
|
for i = 1, #ctf.registered_on_join_team do
|
||||||
ctf.hud.update(minetest.get_player_by_name(name))
|
ctf.registered_on_join_team[i](name, team)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user