Extend /summary to show scores of current match as well

Fixes #310
This commit is contained in:
ANAND 2019-03-17 07:07:20 +05:30 committed by rubenwardy
parent 762682ea80
commit 123ed6d1f5
2 changed files with 39 additions and 13 deletions

View file

@ -1,8 +1,13 @@
ctf_stats = {}
local storage = minetest.get_mod_storage()
local prev_match_summary = storage:get_string("prev_match_summary")
local data_to_persist = { "matches", "players" }
function ctf_stats.get_prev_match_summary()
return prev_match_summary
end
function ctf_stats.load_legacy()
local file = io.open(minetest.get_worldpath() .. "/ctf_stats.txt", "r")
if not file then
@ -154,7 +159,6 @@ table.insert(ctf_flag.registered_on_capture, 1, function(name, flag)
winner_player = name
end)
local prev_match_summary = storage:get_string("prev_match_summary")
ctf_match.register_on_winner(function(winner)
ctf.needs_save = true
ctf_stats.matches.wins[winner] = ctf_stats.matches.wins[winner] + 1
@ -220,7 +224,6 @@ ctf_flag.register_on_precapture(function(name, flag)
return true
end)
-- good_weapons now includes all mese and diamond implements, and swords of steel and better
local good_weapons = {
"default:sword_steel",
"default:sword_bronze",
@ -321,15 +324,36 @@ minetest.register_on_dieplayer(function(player)
end)
minetest.register_chatcommand("summary", {
func = function (name, param)
if not prev_match_summary then
return false, "Couldn't find the requested data."
end
func = function(name)
local fs = ctf_stats.get_formspec_match_summary(ctf_stats.current,
winner_team, winner_player, os.time() - ctf_stats.start)
minetest.show_formspec(name, "ctf_stats:prev_match_summary", prev_match_summary)
fs = fs .. "button[6,7.5;4,1;b_prev;<< Previous match]"
minetest.show_formspec(name, "ctf_stats:match_summary", fs)
end
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "ctf_stats:match_summary" then
return
end
local fs
if fields.b_prev then
fs = prev_match_summary
fs = fs .. "button[6,7.5;4,1;b_curr;Current match >>]"
elseif fields.b_curr then
fs = ctf_stats.get_formspec_match_summary(ctf_stats.current,
winner_team, winner_player, os.time() - ctf_stats.start)
fs = fs .. "button[6,7.5;4,1;b_prev;<< Previous match]"
else
return
end
minetest.show_formspec(player:get_player_name(), "ctf_stats:match_summary", fs)
end)
ctf_stats.load()
dofile(minetest.get_modpath("ctf_stats") .. "/gui.lua")

View file

@ -33,7 +33,8 @@ function random_messages.initialize() --Set the interval in minetest.conf.
end
function random_messages.set_interval() --Read the interval from minetest.conf and set it if it doesn't exist
MESSAGE_INTERVAL = tonumber(minetest.settings:get("random_messages_interval")) or random_messages.initialize()
MESSAGE_INTERVAL = tonumber(minetest.settings:get("random_messages_interval"))
or random_messages.initialize()
end
function random_messages.check_params(name,func,params)
@ -69,7 +70,8 @@ function random_messages.read_messages()
"Excessive spawn-killing is a direct violation of the rules - appropriate punishments will be given.",
"Use /r to check your score and rank, and /rankings to see the league tables.",
"Use bandages on team-mates to heal them by 3-4 HP if their health is below 15 HP.",
"Use /m to add a team marker at pointed location, that's visible only to team-mates."
"Use /m to add a team marker at pointed location, that's visible only to team-mates.",
"Use /summary to check scores of the current match or the previous match."
}
end