mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-11 18:40:25 +01:00
[spawn & sethome] Reduce calls to action_timers : use the wrapper
This commit is contained in:
parent
892910a2a4
commit
82fb540a59
@ -23,23 +23,7 @@ home.sethome = function(name)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if not action_timers.api.get_timer("sethome_" .. name) then
|
action_timers.wrapper(name, "sethome", "sethome_" .. name, home.time, assign_home, {})
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
home.tohome = function(name)
|
home.tohome = function(name)
|
||||||
@ -61,20 +45,7 @@ home.tohome = function(name)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if not action_timers.api.get_timer("home_" .. name) then
|
action_timers.wrapper(name, "home", "home_" .. name, home.time, go_to_home, {})
|
||||||
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
|
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, "Set a home using /sethome")
|
minetest.chat_send_player(name, "Set a home using /sethome")
|
||||||
return false
|
return false
|
||||||
|
@ -18,21 +18,6 @@ minetest.register_chatcommand("spawn", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Checking timers
|
action_timers.wrapper(name, "spawn", "spawn_" .. name, SPAWN_INTERVAL, go_to_spawn, {})
|
||||||
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
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user