diff --git a/mods/ctf_stats/gui.lua b/mods/ctf_stats/gui.lua index dabc020..fd3156b 100644 --- a/mods/ctf_stats/gui.lua +++ b/mods/ctf_stats/gui.lua @@ -1,6 +1,3 @@ -local storage = minetest.get_mod_storage() -local prev_match_summary = storage:get_string("prev_match_summary") - -- Formspec element that governs table columns and their attributes local tablecolumns = { "tablecolumns[color;", @@ -86,10 +83,6 @@ function ctf_stats.get_formspec_match_summary(stats, winner_team, winner_player, ret = ret .. "label[12,0.5;" .. render_team_stats(red, blue, "score", true) .. "]" ret = ret .. "label[2,7.75;Tip: type /rankings for league tables]" - -- Set prev_match_summary and write to mod_storage - prev_match_summary = ret - storage:set_string("prev_match_summary", ret) - return ret end @@ -375,14 +368,3 @@ minetest.register_chatcommand("transfer_rankings", { return true, "Stats of '" .. src .. "' have been transferred to '" .. dest .. "'." end }) - -minetest.register_chatcommand("summary", { - description = "Display the scoreboard of the previous match.", - func = function (name, param) - if not prev_match_summary then - return false, "Couldn't find the requested data." - end - - minetest.show_formspec(name, "ctf_stats:prev_match_summary", prev_match_summary) - end -}) diff --git a/mods/ctf_stats/init.lua b/mods/ctf_stats/init.lua index 6c981f2..042167b 100644 --- a/mods/ctf_stats/init.lua +++ b/mods/ctf_stats/init.lua @@ -139,11 +139,6 @@ ctf.register_on_join_team(function(name, tname) } end) -ctf_match.register_on_skip_map(function() - ctf.needs_save = true - ctf_stats.matches.skipped = ctf_stats.matches.skipped + 1 -end) - local winner_team = "-" local winner_player = "-" @@ -159,19 +154,41 @@ ctf_flag.register_on_capture(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 winner_team = winner -end) -ctf_match.register_on_new_match(function() - local fs = ctf_stats.get_formspec_match_summary(ctf_stats.current, winner_team, winner_player, os.time()-ctf_stats.start) - local players = minetest.get_connected_players() - for _, player in pairs(players) do + -- Show match summary + local fs = ctf_stats.get_formspec_match_summary(ctf_stats.current, + winner_team, winner_player, os.time()-ctf_stats.start) + for _, player in pairs(minetest.get_connected_players()) do minetest.show_formspec(player:get_player_name(), "ctf_stats:eom", fs) end + -- Set prev_match_summary and write to mod_storage + prev_match_summary = fs + storage:set_string("prev_match_summary", fs) +end) + +ctf_match.register_on_skip_map(function() + ctf.needs_save = true + ctf_stats.matches.skipped = ctf_stats.matches.skipped + 1 + + -- Show match summary + local fs = ctf_stats.get_formspec_match_summary(ctf_stats.current, + winner_team, winner_player, os.time()-ctf_stats.start) + for _, player in pairs(minetest.get_connected_players()) do + minetest.show_formspec(player:get_player_name(), "ctf_stats:eom", fs) + end + + -- Set prev_match_summary and write to mod_storage + prev_match_summary = fs + storage:set_string("prev_match_summary", fs) +end) + +ctf_match.register_on_new_match(function() ctf_stats.current = { red = {}, blue = {} @@ -291,6 +308,16 @@ minetest.register_on_dieplayer(function(player) end end) +minetest.register_chatcommand("summary", { + func = function (name, param) + if not prev_match_summary then + return false, "Couldn't find the requested data." + end + + minetest.show_formspec(name, "ctf_stats:prev_match_summary", prev_match_summary) + end +}) + ctf_stats.load() dofile(minetest.get_modpath("ctf_stats").."/gui.lua")