Merge branch 'master' of https://github.com/MT-CTF/capturetheflag
This commit is contained in:
commit
4a2d298828
5 changed files with 63 additions and 39 deletions
|
@ -1,3 +1,4 @@
|
|||
name = Capture the Flag
|
||||
description = Use swords, guns, and grenades to combat the enemy and capture their flag before they capture yours.
|
||||
allowed_mapgens = singlenode
|
||||
min_minetest_version = 5.3
|
||||
|
|
|
@ -103,9 +103,9 @@ function ctf.error(area, msg)
|
|||
end
|
||||
function ctf.log(area, msg)
|
||||
if area and area ~= "" then
|
||||
minetest.log("[CTF | " .. area .. "] " .. msg)
|
||||
minetest.log("info", "[CTF | " .. area .. "] " .. msg)
|
||||
else
|
||||
minetest.log("[CTF]" .. msg)
|
||||
minetest.log("info", "[CTF]" .. msg)
|
||||
end
|
||||
end
|
||||
function ctf.action(area, msg)
|
||||
|
|
|
@ -52,7 +52,7 @@ minetest.register_chatcommand("ctf_respawn", {
|
|||
|
||||
local restart_on_next_match = false
|
||||
local restart_on_next_match_by = nil
|
||||
minetest.register_chatcommand("ctf_queue_restart", {
|
||||
minetest.register_chatcommand("restart", {
|
||||
description = "Queue server restart",
|
||||
privs = {
|
||||
server = true
|
||||
|
@ -65,7 +65,7 @@ minetest.register_chatcommand("ctf_queue_restart", {
|
|||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("ctf_unqueue_restart", {
|
||||
minetest.register_chatcommand("unqueue_restart", {
|
||||
description = "Unqueue server restart",
|
||||
privs = {
|
||||
server = true
|
||||
|
|
|
@ -1,44 +1,68 @@
|
|||
if not minetest.global_exists("prometheus") then
|
||||
if not minetest.create_metric then
|
||||
return
|
||||
end
|
||||
|
||||
local kill_counter = 0
|
||||
local storage = minetest.get_mod_storage()
|
||||
local function counter(name, help)
|
||||
local metric = minetest.create_metric("counter", name, help)
|
||||
metric:increment(tonumber(storage:get(name) or 0))
|
||||
return {
|
||||
get = function()
|
||||
return metric:get()
|
||||
end,
|
||||
|
||||
increment = function(_, value)
|
||||
metric:increment(value)
|
||||
storage:set_string(name, tostring(metric:get()))
|
||||
end,
|
||||
}
|
||||
end
|
||||
local function gauge(name, help)
|
||||
return minetest.create_metric("gauge", name, help)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Kills
|
||||
--
|
||||
local kill_counter = counter("ctf_kills", "Total kills")
|
||||
ctf.register_on_killedplayer(function(victim, killer, type)
|
||||
kill_counter = kill_counter + 1
|
||||
kill_counter:increment()
|
||||
end)
|
||||
|
||||
local function step()
|
||||
prometheus.post("minetest_kills", kill_counter)
|
||||
kill_counter = 0
|
||||
|
||||
--
|
||||
-- Damage
|
||||
--
|
||||
local punch_counter = counter("ctf_punches", "Total punches")
|
||||
local damage_counter = counter("ctf_damage_given", "Total damage given")
|
||||
ctf.register_on_attack(function(_, _, _, _, _, damage)
|
||||
punch_counter:increment()
|
||||
damage_counter:increment(damage)
|
||||
end)
|
||||
|
||||
--
|
||||
-- Digs / places
|
||||
--
|
||||
local dig_counter = counter("ctf_digs", "Total digs")
|
||||
local place_counter = counter("ctf_places", "Total digs")
|
||||
minetest.register_on_dignode(function()
|
||||
dig_counter:increment()
|
||||
end)
|
||||
minetest.register_on_placenode(function()
|
||||
place_counter:increment()
|
||||
end)
|
||||
|
||||
|
||||
local online_score = gauge("ctf_online_score", "Total score of online players")
|
||||
local match_time = gauge("ctf_match_play_time", "Current time in match")
|
||||
minetest.register_globalstep(function()
|
||||
local sum = 0
|
||||
local avg = 0
|
||||
local bins = { r050=0, r200=0, r5000=0, rest=0 }
|
||||
if #minetest.get_connected_players() > 0 then
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local total, _ = ctf_stats.player(player:get_player_name())
|
||||
sum = sum + total.score
|
||||
end
|
||||
online_score:set(sum)
|
||||
|
||||
if total.score > 174000 then
|
||||
bins.r050 = bins.r050 + 1
|
||||
elseif total.score > 10000 then
|
||||
bins.r200 = bins.r200 + 1
|
||||
elseif total.score > 1000 then
|
||||
bins.r5000 = bins.r5000 + 1
|
||||
else
|
||||
bins.rest = bins.rest + 1
|
||||
end
|
||||
end
|
||||
avg = sum / #minetest.get_connected_players()
|
||||
end
|
||||
|
||||
for key, value in pairs(bins) do
|
||||
prometheus.post("minetest_ctf_score_bins{rank=\"" .. key .. "\"}", value)
|
||||
end
|
||||
|
||||
prometheus.post("minetest_ctf_score_total", sum)
|
||||
prometheus.post("minetest_ctf_score_avg", avg)
|
||||
|
||||
minetest.after(15, step)
|
||||
end
|
||||
minetest.after(15, step)
|
||||
match_time:set(ctf_match.get_match_duration() or 0)
|
||||
end)
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
name = ctf_metrics
|
||||
depends = ctf, ctf_stats
|
||||
optional_depends = prometheus
|
||||
|
|
Loading…
Reference in a new issue