Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flag attempt streaks #1196

Merged
merged 9 commits into from
Jun 7, 2024
44 changes: 44 additions & 0 deletions mods/ctf/ctf_modebase/flags/taking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,49 @@ function ctf_modebase.flag_on_punch(puncher, nodepos, node)
table.insert(ctf_modebase.taken_flags[pname], target_team)
ctf_modebase.flag_taken[target_team] = {p=pname, t=pteam}


if ctf_modebase.flag_attempt_history[pname] == nil then
ctf_modebase.flag_attempt_history[pname] = {}
end
table.insert(ctf_modebase.flag_attempt_history[pname], os.time())

-- this is table of streaks.
-- mega streak means 4 or 5 attempt in less than 10 minutes
local streaks = {
[3] = "three",
[4] = "four",
[5] = "mega",
[7] = "mega",
[8] = "giga",
[10] = "giga",
[12] = "tera",
[14] = "EXA",
}

local number_of_attempts = 0
local total_time = 0 -- should be less than 60*10 = 10 minutes
local prev_time = nil
for i = #ctf_modebase.flag_attempt_history[pname], 1, -1 do
local time = ctf_modebase.flag_attempt_history[i]
if prev_time then
total_time = math.abs(prev_time - time)
else
prev_time = time
end
number_of_attempts = number_of_attempts + 1
if total_time >= 60*10 then
-- if total_time was more than 10min...
break
end
end
local streak = streaks[number_of_attempts]
if number_of_attempts >= 10 then
streak = "EXA"
end
if streak then
minetest.chat_send_all(pname .. " is on a " .. streak .. " attempt streak!")
end

player_api.set_texture(puncher, 2,
"default_wood.png^([combine:16x16:4,0=wool_white.png^[colorize:"..ctf_teams.team[target_team].color..":200)"
)
Expand Down Expand Up @@ -122,6 +165,7 @@ ctf_api.register_on_match_end(function()
ctf_modebase.taken_flags = {}
ctf_modebase.flag_taken = {}
ctf_modebase.flag_captured = {}
ctf_modebase.flag_attempt_history = {}
end)

ctf_teams.register_on_allocplayer(function(player, new_team, old_team)
Expand Down
4 changes: 4 additions & 0 deletions mods/ctf/ctf_modebase/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ ctf_modebase = {

--flag_captured[Team name] = true if captured, otherwise nil
flag_captured = {},

flag_attempt_history = {
-- ["player"] = {time0, time1, time2, ...}
},
}

ctf_gui.old_init()
Expand Down