ctf_stats: Improve /makepro chat-command (#638)

This commit is contained in:
ANAND 2020-05-30 20:37:57 +05:30 committed by GitHub
parent a978d8457f
commit 3db5696889
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -179,9 +179,9 @@ minetest.register_chatcommand("transfer_rankings", {
privs = {ctf_admin = true}, privs = {ctf_admin = true},
func = function(name, param) func = function(name, param)
if not param then if not param then
return false, "Invalid syntax. Provide source and destination player names." return false, "Invalid usage, see /help transfer_rankings"
end end
param = param:trim()
local src, dest = param:trim():match("([%a%d_-]+) ([%a%d_-]+)") local src, dest = param:trim():match("([%a%d_-]+) ([%a%d_-]+)")
if not src or not dest then if not src or not dest then
return false, "Invalid usage, see /help transfer_rankings" return false, "Invalid usage, see /help transfer_rankings"
@ -208,19 +208,34 @@ minetest.register_chatcommand("transfer_rankings", {
minetest.register_chatcommand("makepro", { minetest.register_chatcommand("makepro", {
description = "Make self a pro", params = "[player_name]",
description = "Make player a pro",
privs = {ctf_admin = true}, privs = {ctf_admin = true},
func = function(name, param) func = function(name, param)
local stats, _ = ctf_stats.player(name) -- Check if param is specified, else target the caller
param = param:trim()
if param == "" then
param = name
end
if stats.kills < 1.5 * (stats.deaths + 1) then local modified = false
stats.kills = 1.51 * (stats.deaths + 1) local stats = ctf_stats.player(param)
local deaths = math.max(stats.deaths, 1)
if stats.kills < 1.5 * deaths then
stats.kills = math.ceil(1.51 * deaths)
modified = true
end end
if stats.score < 10000 then if stats.score < 10000 then
stats.score = 10000 stats.score = 10000
modified = true
end end
return true, "Done" if modified then
return true, "Made " .. param .. " a pro!"
else
return false, param .. " is already a pro!"
end
end end
}) })