2021-10-12 20:57:13 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019-2021 Joachim Stolberg
|
|
|
|
|
|
|
|
AGPL v3
|
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
Count techage commands player related
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-10-12 20:57:13 +03:00
|
|
|
]]--
|
|
|
|
|
|
|
|
local PlayerName
|
|
|
|
local PlayerPoints = {}
|
2021-10-24 22:15:19 +03:00
|
|
|
local LastPlayerPoints = {}
|
|
|
|
local S = techage.S
|
|
|
|
|
|
|
|
local MAX_POINTS = tonumber(minetest.settings:get("techage_command_limit")) or 1200
|
2021-10-12 20:57:13 +03:00
|
|
|
|
|
|
|
function techage.counting_start(player_name)
|
|
|
|
PlayerName = player_name
|
|
|
|
PlayerPoints[PlayerName] = PlayerPoints[PlayerName] or 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function techage.counting_stop()
|
|
|
|
PlayerName = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function techage.counting_hit()
|
|
|
|
if PlayerName then
|
|
|
|
PlayerPoints[PlayerName] = PlayerPoints[PlayerName] + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
function techage.counting_add(player_name, points)
|
|
|
|
PlayerPoints[player_name] = (PlayerPoints[player_name] or 0) + points
|
|
|
|
end
|
|
|
|
|
2021-10-12 20:57:13 +03:00
|
|
|
local function output()
|
|
|
|
for name, val in pairs(PlayerPoints) do
|
2021-10-24 22:15:19 +03:00
|
|
|
if val > MAX_POINTS then
|
|
|
|
local obj = minetest.get_player_by_name(name)
|
|
|
|
if obj then
|
2022-01-03 23:40:31 +03:00
|
|
|
minetest.chat_send_player(name,
|
2021-10-24 22:15:19 +03:00
|
|
|
S("[techage] The limit for 'number of commands per minute' has been exceeded.") ..
|
|
|
|
" " .. string.format(MAX_POINTS .. " " .. S("is allowed. Current value is") .. " " .. val));
|
2022-01-03 23:40:31 +03:00
|
|
|
minetest.log("action", "[techage] " .. name ..
|
2021-10-24 22:15:19 +03:00
|
|
|
" exceeds the limit for commands per minute. value = " .. val)
|
|
|
|
local factor = 100 / (obj:get_armor_groups().fleshy or 100)
|
|
|
|
obj:punch(obj, 1.0, {full_punch_interval=1.0, damage_groups = {fleshy=factor * 5}})
|
|
|
|
end
|
|
|
|
end
|
2021-10-12 20:57:13 +03:00
|
|
|
end
|
2021-10-24 22:15:19 +03:00
|
|
|
LastPlayerPoints = table.copy(PlayerPoints)
|
2021-10-12 20:57:13 +03:00
|
|
|
PlayerPoints = {}
|
|
|
|
minetest.after(60, output)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.after(60, output)
|
|
|
|
|
2021-10-24 22:15:19 +03:00
|
|
|
|
|
|
|
minetest.register_chatcommand("ta_limit", {
|
|
|
|
description = "Get your current techage command limit value",
|
|
|
|
func = function(name)
|
|
|
|
local num = LastPlayerPoints[name] or 0
|
2022-01-03 23:40:31 +03:00
|
|
|
return true, S("Your current value is") .. " " .. num .. " " .. S("per minute") .. ". " ..
|
2021-10-24 22:15:19 +03:00
|
|
|
MAX_POINTS .. " " .. S("is allowed")
|
|
|
|
end
|
|
|
|
})
|