mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-25 02:00:37 +01:00
[action_timers & pclasses] Limit class switch to one per houre
- Create a wrapper for the action_timers - Limit the use of class switch orbs to one use per hour - Related to #183
This commit is contained in:
parent
ea16f89ac8
commit
0091be67ac
@ -38,10 +38,8 @@ function action_timers.api.do_action(name, func, params)
|
|||||||
|
|
||||||
action_timers.timers[name] = action_timers.limits[name]
|
action_timers.timers[name] = action_timers.limits[name]
|
||||||
if not params then
|
if not params then
|
||||||
print("func()")
|
|
||||||
return func()
|
return func()
|
||||||
else
|
else
|
||||||
print("func(unpack(params))")
|
|
||||||
return func(unpack(params))
|
return func(unpack(params))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -60,3 +58,21 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.log("action", "[ACTimers] Loaded")
|
minetest.log("action", "[ACTimers] Loaded")
|
||||||
|
|
||||||
|
|
||||||
|
function action_timers.wrapper(pname, name, timername, value, func, params)
|
||||||
|
if not action_timers.api.get_timer(timername) then
|
||||||
|
action_timers.api.register_timer(timername, value)
|
||||||
|
return func(unpack(params))
|
||||||
|
else
|
||||||
|
local res = action_timers.api.do_action(timername, func, params)
|
||||||
|
if tonumber(res) then
|
||||||
|
minetest.chat_send_player(pname, "Please retry later, you used " .. name .. " last time less than " .. value .. " seconds ago.")
|
||||||
|
minetest.chat_send_player(pname, "Retry in: " .. math.floor(res) .. " seconds.")
|
||||||
|
minetest.log("action", "[action_timers] Player " .. pname .. " tried to use'" .. name .. "' within forbidden interval.")
|
||||||
|
return false
|
||||||
|
elseif res == true then
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -42,7 +42,14 @@ minetest.register_entity("pclasses:item", {
|
|||||||
self.object:set_properties(prop)
|
self.object:set_properties(prop)
|
||||||
end,
|
end,
|
||||||
on_rightclick = function(self, clicker)
|
on_rightclick = function(self, clicker)
|
||||||
pclasses.api.set_player_class(clicker:get_player_name(), self.class)
|
action_timers.wrapper(
|
||||||
|
clicker:get_player_name(),
|
||||||
|
"class switch",
|
||||||
|
"class_switch_" .. clicker:get_player_name(),
|
||||||
|
3600,
|
||||||
|
pclasses.api.set_player_class,
|
||||||
|
{clicker:get_player_name(), self.class}
|
||||||
|
)
|
||||||
end,
|
end,
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata)
|
||||||
local tab = minetest.deserialize(staticdata)
|
local tab = minetest.deserialize(staticdata)
|
||||||
|
Loading…
Reference in New Issue
Block a user