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 = {} ctf_stats = {}
local storage = minetest.get_mod_storage() local storage = minetest.get_mod_storage()
local prev_match_summary = storage:get_string("prev_match_summary")
local data_to_persist = { "matches", "players" } local data_to_persist = { "matches", "players" }
function ctf_stats.get_prev_match_summary()
return prev_match_summary
end
function ctf_stats.load_legacy() function ctf_stats.load_legacy()
local file = io.open(minetest.get_worldpath() .. "/ctf_stats.txt", "r") local file = io.open(minetest.get_worldpath() .. "/ctf_stats.txt", "r")
if not file then if not file then
@ -154,7 +159,6 @@ table.insert(ctf_flag.registered_on_capture, 1, function(name, flag)
winner_player = name winner_player = name
end) end)
local prev_match_summary = storage:get_string("prev_match_summary")
ctf_match.register_on_winner(function(winner) ctf_match.register_on_winner(function(winner)
ctf.needs_save = true ctf.needs_save = true
ctf_stats.matches.wins[winner] = ctf_stats.matches.wins[winner] + 1 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 return true
end) end)
-- good_weapons now includes all mese and diamond implements, and swords of steel and better
local good_weapons = { local good_weapons = {
"default:sword_steel", "default:sword_steel",
"default:sword_bronze", "default:sword_bronze",
@ -274,7 +277,7 @@ local function calculateKillReward(victim, killer)
end end
-- Half if no good weapons -- Half if no good weapons
local inv = minetest.get_inventory({ type="player", name = victim }) local inv = minetest.get_inventory({ type = "player", name = victim })
if not invHasGoodWeapons(inv) then if not invHasGoodWeapons(inv) then
ctf.log("ctf_stats", "Player " .. victim .. " has no good weapons") ctf.log("ctf_stats", "Player " .. victim .. " has no good weapons")
reward = reward * 0.5 reward = reward * 0.5
@ -321,15 +324,36 @@ minetest.register_on_dieplayer(function(player)
end) end)
minetest.register_chatcommand("summary", { minetest.register_chatcommand("summary", {
func = function (name, param) func = function(name)
if not prev_match_summary then local fs = ctf_stats.get_formspec_match_summary(ctf_stats.current,
return false, "Couldn't find the requested data." winner_team, winner_player, os.time() - ctf_stats.start)
end
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 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() ctf_stats.load()
dofile(minetest.get_modpath("ctf_stats").."/gui.lua") dofile(minetest.get_modpath("ctf_stats") .. "/gui.lua")

View file

@ -27,17 +27,18 @@ function table.random( t ) -- luacheck: ignore
end end
function random_messages.initialize() --Set the interval in minetest.conf. function random_messages.initialize() --Set the interval in minetest.conf.
minetest.settings:set("random_messages_interval",60) minetest.settings:set("random_messages_interval", 60)
minetest.settings:write(); minetest.settings:write();
return 60 return 60
end end
function random_messages.set_interval() --Read the interval from minetest.conf and set it if it doesn't exist 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 end
function random_messages.check_params(name,func,params) function random_messages.check_params(name,func,params)
local stat,msg = func(params) local stat, msg = func(params)
if not stat then if not stat then
minetest.chat_send_player(name,msg) minetest.chat_send_player(name,msg)
return false return false
@ -69,7 +70,8 @@ function random_messages.read_messages()
"Excessive spawn-killing is a direct violation of the rules - appropriate punishments will be given.", "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 /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 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 end