diff --git a/mods/ctf/ctf_map/maps b/mods/ctf/ctf_map/maps index 6fb7320571..9d1112fd40 160000 --- a/mods/ctf/ctf_map/maps +++ b/mods/ctf/ctf_map/maps @@ -1 +1 @@ -Subproject commit 6fb7320571a118720f2c69bc2230f33cf35cfc39 +Subproject commit 9d1112fd40b0b5cddc4a695f7597b30eaba71d3a diff --git a/mods/ctf/ctf_modebase/bounties.lua b/mods/ctf/ctf_modebase/bounties.lua index 196fd3a18c..e7ba7d75b8 100644 --- a/mods/ctf/ctf_modebase/bounties.lua +++ b/mods/ctf/ctf_modebase/bounties.lua @@ -4,12 +4,16 @@ local bounties = {} ctf_modebase.bounties = {} -- ^ This is for game's own bounties -ctf_modebase.contributed_bounties = {} +ctf_modebase.contributed_bounties = { +--[[ + ["player_name"] = { + total = score, + contributors = {"player1", "player2", ...} + }, + ... +--]] +} -- ^ This is for user contributed bounties --- Saving format: player_name(str) equals to a table --- The table has "total" which is the total contributed bounty --- on player_name's head and "contributors" is a mapping of donater_name(str) --- to donate_amount(number). local function get_contributors(name) local b = ctf_modebase.contributed_bounties[name] @@ -271,10 +275,10 @@ ctf_core.register_chatcommand_alias("bounty", "b", { amount = math.floor(amount) local bteam = ctf_teams.get(bname) if bteam == nil then - return false, "This player is either not online or not in any team" + return false, "This player is either not online or isn't in a team" end if bteam == ctf_teams.get(name) then - return false, "You cannot put bounty on your teammate's head!" + return false, "You cannot put bounty on your teammate!" end if amount < 5 then return false, "Sorry you must at least donate 15" @@ -300,17 +304,16 @@ ctf_core.register_chatcommand_alias("bounty", "b", { contributors[name] = amount ctf_modebase.contributed_bounties[bname] = { total = amount, contributors = contributors } else - if ctf_modebase.contributed_bounties[bname]["contributors"][name] == nil then - minetest.chat_send_all(name) - ctf_modebase.contributed_bounties[bname]["contributors"][name] = amount - ctf_modebase.contributed_bounties[bname]["total"] = ctf_modebase.contributed_bounties[bname]["total"] + amount + if ctf_modebase.contributed_bounties[bname].contributors[name] == nil then + ctf_modebase.contributed_bounties[bname].contributors[name] = amount else - return false, "You cannot donate for someone's head twice" + ctf_modebase.contributed_bounties[bname].contributors[name] = ctf_modebase.contributed_bounties[bname].contributors[name] + amount end + ctf_modebase.contributed_bounties[bname].total = ctf_modebase.contributed_bounties[bname].total + amount end minetest.chat_send_all( minetest.colorize( CHAT_COLOR, - string.format("%s donated %d for %s's head!", get_contributors(bname), amount, bname))) + string.format("%s put %d bounty on %s!", get_contributors(bname), amount, bname))) end, }) diff --git a/mods/ctf/ctf_rankings/default.lua b/mods/ctf/ctf_rankings/default.lua index 4602b22f90..600fabbf39 100644 --- a/mods/ctf/ctf_rankings/default.lua +++ b/mods/ctf/ctf_rankings/default.lua @@ -1,57 +1,57 @@ return function(top) - local modstorage = assert(minetest.get_mod_storage(), "Can only init rankings at runtime!") +local modstorage = assert(minetest.get_mod_storage(), "Can only init rankings at runtime!") - for k, v in pairs(modstorage:to_table()["fields"]) do - local rank = minetest.parse_json(v) - if rank ~= nil and rank.score then - top:set(k, rank.score) - end +for k, v in pairs(modstorage:to_table()["fields"]) do + local rank = minetest.parse_json(v) + if rank ~= nil and rank.score then + top:set(k, rank.score) end +end - return { - backend = "default", - top = top, - modstorage = modstorage, - - get = function(self, pname) - pname = PlayerName(pname) +return { + backend = "default", + top = top, + modstorage = modstorage, - local rank_str = self.modstorage:get_string(pname) + get = function(self, pname) + pname = PlayerName(pname) - if not rank_str or rank_str == "" then - return false - end + local rank_str = self.modstorage:get_string(pname) - return minetest.parse_json(rank_str) - end, - set = function(self, pname, newrankings, erase_unset) - pname = PlayerName(pname) + if not rank_str or rank_str == "" then + return false + end - if not erase_unset then - local rank = self:get(pname) - if rank then - for k, v in pairs(newrankings) do - rank[k] = v - end + return minetest.parse_json(rank_str) + end, + set = function(self, pname, newrankings, erase_unset) + pname = PlayerName(pname) - newrankings = rank + if not erase_unset then + local rank = self:get(pname) + if rank then + for k, v in pairs(newrankings) do + rank[k] = v end - end - self.top:set(pname, newrankings.score or 0) - self.modstorage:set_string(pname, minetest.write_json(newrankings)) - end, - add = function(self, pname, amounts) - pname = PlayerName(pname) + newrankings = rank + end + end - local newrankings = self:get(pname) or {} + self.top:set(pname, newrankings.score or 0) + self.modstorage:set_string(pname, minetest.write_json(newrankings)) + end, + add = function(self, pname, amounts) + pname = PlayerName(pname) - for k, v in pairs(amounts) do - newrankings[k] = (newrankings[k] or 0) + v - end + local newrankings = self:get(pname) or {} - self.top:set(pname, newrankings.score or 0) - self.modstorage:set_string(pname, minetest.write_json(newrankings)) + for k, v in pairs(amounts) do + newrankings[k] = (newrankings[k] or 0) + v end - } + + self.top:set(pname, newrankings.score or 0) + self.modstorage:set_string(pname, minetest.write_json(newrankings)) + end +} end