1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-24 17:50:37 +01:00

[spawn & sethome] Reduce calls to action_timers : use the wrapper

This commit is contained in:
LeMagnesium 2015-10-17 13:16:03 +02:00
parent 892910a2a4
commit 82fb540a59
2 changed files with 3 additions and 47 deletions

View File

@ -23,23 +23,7 @@ home.sethome = function(name)
return true
end
if not action_timers.api.get_timer("sethome_" .. name) then
if home.homepos[p_status][name] ~= pos then
home.homepos[p_status][name] = pos
end
action_timers.api.register_timer("sethome_" .. name, home.time)
return assign_home()
else
local res = action_timers.api.do_action("sethome_" .. name, assign_home)
if tonumber(res) then
minetest.chat_send_player(name, "Please retry later, you used sethome last time less than ".. home.time .." seconds ago.")
minetest.chat_send_player(name, "Retry in: ".. math.floor(res) .." seconds.")
minetest.log("action","Player ".. name .." tried to sethome within forbidden interval.")
return false
elseif res == true then
return res
end
end
action_timers.wrapper(name, "sethome", "sethome_" .. name, home.time, assign_home, {})
end
home.tohome = function(name)
@ -61,20 +45,7 @@ home.tohome = function(name)
return true
end
if not action_timers.api.get_timer("home_" .. name) then
action_timers.api.register_timer("home_" .. name, home.time)
return go_to_home()
else
local res = action_timers.api.do_action("home_" .. name, go_to_home)
if tonumber(res) then
minetest.chat_send_player(name, "Please retry later, you used home last time less than ".. home.time .." seconds ago.")
minetest.chat_send_player(name, "Retry in: ".. math.floor(res) .." seconds.")
minetest.log("action","Player ".. name .." tried to teleport home within forbidden interval.")
return false
elseif res == true then
return res
end
end
action_timers.wrapper(name, "home", "home_" .. name, home.time, go_to_home, {})
else
minetest.chat_send_player(name, "Set a home using /sethome")
return false

View File

@ -18,21 +18,6 @@ minetest.register_chatcommand("spawn", {
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
action_timers.wrapper(name, "spawn", "spawn_" .. name, SPAWN_INTERVAL, go_to_spawn, {})
end
})