mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-06-28 06:11:47 +02:00
Merged all command timers in a single mod : action_timers
- Merged all command timers in a single mod - Activated mod - Updated news.txt
This commit is contained in:
62
mods/action_timers/init.lua
Executable file
62
mods/action_timers/init.lua
Executable file
@ -0,0 +1,62 @@
|
||||
-------------------------------
|
||||
-- Action timers
|
||||
-- Mod handling action timers
|
||||
--
|
||||
|
||||
action_timers = {}
|
||||
action_timers.timers = {}
|
||||
action_timers.limits = {}
|
||||
|
||||
action_timers.api = {}
|
||||
|
||||
|
||||
function action_timers.api.register_timer(name, limit)
|
||||
if action_timers.timers[name] then
|
||||
minetest.log("error", "[ACTimers] Cannot register timer " .. name .. " a second time")
|
||||
return
|
||||
elseif not limit then
|
||||
minetest.log("error", "[ACTimers] Cannot register timer " .. name .. " without limit")
|
||||
return
|
||||
end
|
||||
|
||||
action_timers.timers[name] = limit
|
||||
action_timers.limits[name] = limit
|
||||
minetest.log("action", "[ACTimers] Timer " .. name .. " registered with time limit " .. limit)
|
||||
end
|
||||
|
||||
function action_timers.api.do_action(name, func, params)
|
||||
if not action_timers.timers[name] then
|
||||
minetest.log("error", "[ACTimers] Timer " .. name .. " doesn't exist")
|
||||
return
|
||||
elseif not func then
|
||||
minetest.log("error", "[ACTimers] Function passed to time checker for " .. name .. " is nil")
|
||||
return
|
||||
elseif action_timers.timers[name] > 0 then
|
||||
minetest.log("error", "[ACTimers] Timer " .. name .. " is still up to 0")
|
||||
return action_timers.timers[name]
|
||||
end
|
||||
|
||||
action_timers.timers[name] = action_timers.limits[name]
|
||||
if not params then
|
||||
print("func()")
|
||||
return func()
|
||||
else
|
||||
print("func(unpack(params))")
|
||||
return func(unpack(params))
|
||||
end
|
||||
end
|
||||
|
||||
function action_timers.api.get_timer(name)
|
||||
return action_timers.timers[name]
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for name, _ in pairs(action_timers.timers) do
|
||||
action_timers.timers[name] = action_timers.timers[name] - dtime
|
||||
if action_timers.timers[name] < 0 then
|
||||
action_timers.timers[name] = 0
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.log("action", "[ACTimers] Loaded")
|
@ -1,5 +1,4 @@
|
||||
irc.whereis_timer = {}
|
||||
irc.whereis_timer_max_limit = 120
|
||||
local whereis_interval = 120
|
||||
irc.bot_commands = {}
|
||||
|
||||
function irc:check_botcmd(msg)
|
||||
@ -117,19 +116,28 @@ irc:register_bot_command("whereis", {
|
||||
if not player then
|
||||
return false, "There is no player named '"..args.."'"
|
||||
end
|
||||
if irc.whereis_timer[user.nick] ~= nil then
|
||||
local timer_player = os.difftime(os.time(),irc.whereis_timer[user.nick])
|
||||
if timer_player < irc.whereis_timer_max_limit then
|
||||
|
||||
local function say_where_is()
|
||||
local fmt = "Player %s is at (%.2f,%.2f,%.2f)"
|
||||
local pos = player:getpos()
|
||||
minetest.log("action","IRC user ".. user.nick.."!"..user.username.."@"..user.host.." asked for position of player "..player:get_player_name())
|
||||
minetest.chat_send_player(player:get_player_name(),"IRC user ".. user.nick.."!"..user.username.."@"..user.host.." asked for your position")
|
||||
return true, fmt:format(args, pos.x, pos.y, pos.z)
|
||||
end
|
||||
|
||||
if not action_timers.api.get_timer("whereis_" .. user.nick) then
|
||||
action_timers.api.register_timer("whereis_" .. user.nick, whereis_interval)
|
||||
return say_where_is()
|
||||
else
|
||||
local res = action_timers.api.do_action("whereis_" .. user.nick, say_where_is)
|
||||
if tonumber(res) then
|
||||
local answer = "Command used too often, retry in %d seconds."
|
||||
return false,answer:format(irc.whereis_timer_max_limit - timer_player)
|
||||
return false,answer:format(math.floor(res))
|
||||
else
|
||||
print(res)
|
||||
return res
|
||||
end
|
||||
end
|
||||
local fmt = "Player %s is at (%.2f,%.2f,%.2f)"
|
||||
local pos = player:getpos()
|
||||
irc.whereis_timer[user.nick] = os.time()
|
||||
minetest.log("action","IRC user ".. user.nick.."!"..user.username.."@"..user.host.." asked for position of player "..player:get_player_name())
|
||||
minetest.chat_send_player(player:get_player_name(),"IRC user ".. user.nick.."!"..user.username.."@"..user.host.." asked for your position")
|
||||
return true, fmt:format(args, pos.x, pos.y, pos.z)
|
||||
end
|
||||
})
|
||||
|
||||
|
1
mods/irc/depends.txt
Executable file
1
mods/irc/depends.txt
Executable file
@ -0,0 +1 @@
|
||||
action_timers
|
1
mods/spawn/depends.txt
Executable file
1
mods/spawn/depends.txt
Executable file
@ -0,0 +1 @@
|
||||
action_timers
|
@ -1,32 +1,38 @@
|
||||
local timers = {}
|
||||
local SPAWN_INTERVAL = 5*60
|
||||
|
||||
|
||||
minetest.register_on_chat_message(function(name, message, playername, player)
|
||||
local cmd = "/spawn"
|
||||
if message:sub(0, #cmd) == cmd then
|
||||
if message == '/spawn' then
|
||||
local player = minetest.get_player_by_name(name)
|
||||
|
||||
-- Checking timers
|
||||
local timer_player = os.difftime(os.time(),timers[name])
|
||||
if timer_player ~= nil and timer_player < SPAWN_INTERVAL then -- less than x minutes
|
||||
minetest.chat_send_player(name, "Please retry later, you used spawn last time less than ".. SPAWN_INTERVAL .." seconds ago.")
|
||||
minetest.chat_send_player(name, "Retry in: ".. SPAWN_INTERVAL-timer_player .." seconds.")
|
||||
minetest.log("action","Player ".. name .." tried to respawn within forbidden interval.")
|
||||
return false
|
||||
end
|
||||
minetest.register_chatcommand("spawn", {
|
||||
description = "Teleport a player to the defined spawnpoint",
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
|
||||
local function go_to_spawn()
|
||||
if minetest.setting_get_pos("static_spawnpoint") then
|
||||
minetest.chat_send_player(player:get_player_name(), "Teleporting to spawn...")
|
||||
player:setpos(minetest.setting_get_pos("static_spawnpoint"))
|
||||
minetest.log("action","Player ".. name .." respawned. Next allowed respawn in ".. SPAWN_INTERVAL .." seconds.")
|
||||
timers[name] = os.time()
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_player(player:get_player_name(), "ERROR: No spawn point is set on this server!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Checking timers
|
||||
if not action_timers.api.get_timer("spawn_" .. name) then
|
||||
action_timers.api.register_timer("spawn_" .. name, SPAWN_INTERVAL)
|
||||
return go_to_spawn()
|
||||
else
|
||||
local res = action_timers.api.do_action("spawn_" .. name, go_to_spawn)
|
||||
print(res)
|
||||
if tonumber(res) then
|
||||
minetest.chat_send_player(name, "Please retry later, you used spawn last time less than ".. SPAWN_INTERVAL .." seconds ago.")
|
||||
minetest.chat_send_player(name, "Retry in: ".. math.floor(res) .." seconds.")
|
||||
minetest.log("action","Player ".. name .." tried to respawn within forbidden interval.")
|
||||
return false
|
||||
else
|
||||
return res
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
})
|
||||
|
Reference in New Issue
Block a user