ctf_stats: Add ctf_stats.request_save
This functionality allows mods to request a save (not immediate) if they modify player stats.
This commit is contained in:
parent
f1a2006ec5
commit
181b13d1d0
4 changed files with 17 additions and 6 deletions
|
@ -91,6 +91,14 @@ ctf.register_on_killedplayer(function(victim, killer)
|
||||||
match.score = match.score + bounty_score
|
match.score = match.score + bounty_score
|
||||||
main.bounty_kills = main.bounty_kills + 1
|
main.bounty_kills = main.bounty_kills + 1
|
||||||
match.bounty_kills = match.bounty_kills + 1
|
match.bounty_kills = match.bounty_kills + 1
|
||||||
|
|
||||||
|
ctf_stats.request_save()
|
||||||
|
|
||||||
|
hud_score.new(killer, {
|
||||||
|
name = "ctf_bounty:prize",
|
||||||
|
color = 0x4444FF,
|
||||||
|
value = bounty_score
|
||||||
|
})
|
||||||
end
|
end
|
||||||
bountied_player = nil
|
bountied_player = nil
|
||||||
|
|
||||||
|
@ -102,11 +110,6 @@ ctf.register_on_killedplayer(function(victim, killer)
|
||||||
minetest.colorize("#fff326", " and received " .. bounty_score .. " points!")
|
minetest.colorize("#fff326", " and received " .. bounty_score .. " points!")
|
||||||
minetest.log("action", minetest.strip_colors(msg))
|
minetest.log("action", minetest.strip_colors(msg))
|
||||||
minetest.chat_send_all(msg)
|
minetest.chat_send_all(msg)
|
||||||
hud_score.new(killer, {
|
|
||||||
name = "ctf_bounty:prize",
|
|
||||||
color = 0x4444FF,
|
|
||||||
value = bounty_score
|
|
||||||
})
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_privilege("bounty_admin")
|
minetest.register_privilege("bounty_admin")
|
||||||
|
|
|
@ -91,6 +91,8 @@ minetest.override_item("ctf_bandages:bandage", {
|
||||||
color = "0x00FF00",
|
color = "0x00FF00",
|
||||||
value = reward
|
value = reward
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ctf_stats.request_save()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -161,6 +161,7 @@ minetest.register_chatcommand("reset_rankings", {
|
||||||
|
|
||||||
ctf_stats.players[reset_name] = nil
|
ctf_stats.players[reset_name] = nil
|
||||||
ctf_stats.player(reset_name)
|
ctf_stats.player(reset_name)
|
||||||
|
ctf_stats.request_save()
|
||||||
|
|
||||||
if reset_name == name then
|
if reset_name == name then
|
||||||
minetest.log("action", name .. " reset their rankings")
|
minetest.log("action", name .. " reset their rankings")
|
||||||
|
@ -198,6 +199,8 @@ minetest.register_chatcommand("transfer_rankings", {
|
||||||
ctf_stats.players[dest] = ctf_stats.players[src]
|
ctf_stats.players[dest] = ctf_stats.players[src]
|
||||||
ctf_stats.players[src] = nil
|
ctf_stats.players[src] = nil
|
||||||
|
|
||||||
|
ctf_stats.request_save()
|
||||||
|
|
||||||
minetest.log("action", name .. " transferred stats of " .. src .. " to " .. dest)
|
minetest.log("action", name .. " transferred stats of " .. src .. " to " .. dest)
|
||||||
return true, "Stats of '" .. src .. "' have been transferred to '" .. dest .. "'."
|
return true, "Stats of '" .. src .. "' have been transferred to '" .. dest .. "'."
|
||||||
end
|
end
|
||||||
|
|
|
@ -110,7 +110,10 @@ local function check_if_save_needed()
|
||||||
end
|
end
|
||||||
minetest.after(13, check_if_save_needed)
|
minetest.after(13, check_if_save_needed)
|
||||||
|
|
||||||
minetest.after(13, ctf_stats.save)
|
-- API function to allow other mods to request a save
|
||||||
|
-- TODO: This should be done automatically once a proper API is in place
|
||||||
|
function ctf_stats.request_save()
|
||||||
|
_needs_save = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function ctf_stats.player_or_nil(name)
|
function ctf_stats.player_or_nil(name)
|
||||||
|
|
Loading…
Reference in a new issue