mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-11 18:40:25 +01:00
Added timer to home mod
- Added a time handler to avoid players to use /home too many times - Timer's interval is set by HOME_INTERVAL in minetestforfun_game/mods/home/init.lua - Added debug messages to show in the logs when a player teleport to home or try within the forbidden timer's interval
This commit is contained in:
parent
06d241c10a
commit
696f96b0f0
@ -1,6 +1,8 @@
|
|||||||
local homes_file = {["real"] = minetest.get_worldpath() .. "/realhomes",
|
local homes_file = {["real"] = minetest.get_worldpath() .. "/realhomes",
|
||||||
["nether"] = minetest.get_worldpath() .. "/netherhomes"}
|
["nether"] = minetest.get_worldpath() .. "/netherhomes"}
|
||||||
local homepos = {["real"] = {}, ["nether"] = {}}
|
local homepos = {["real"] = {}, ["nether"] = {}}
|
||||||
|
local timers = {}
|
||||||
|
local HOME_INTERVAL = 30*60
|
||||||
|
|
||||||
local function loadhomes()
|
local function loadhomes()
|
||||||
for key,_ in pairs(homes_file) do
|
for key,_ in pairs(homes_file) do
|
||||||
@ -42,9 +44,20 @@ minetest.register_chatcommand("home", {
|
|||||||
if player:getpos().y < -19600 then
|
if player:getpos().y < -19600 then
|
||||||
p_status = "nether"
|
p_status = "nether"
|
||||||
end
|
end
|
||||||
if homepos[p_status][player:get_player_name()] then
|
if homepos[p_status][name] then
|
||||||
|
if timers[name] ~= nil then
|
||||||
|
local timer_player = os.difftime(os.time(),timers[name])
|
||||||
|
if timer_player < HOME_INTERVAL then -- less than x minutes
|
||||||
|
minetest.chat_send_player(name, "Please retry later, you used home last time less than ".. HOME_INTERVAL .." seconds ago.")
|
||||||
|
minetest.chat_send_player(name, "Retry in: ".. HOME_INTERVAL-timer_player .." seconds.")
|
||||||
|
minetest.log("action","Player ".. name .." tried to teleport home within forbidden interval.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
player:setpos(homepos[p_status][player:get_player_name()])
|
player:setpos(homepos[p_status][player:get_player_name()])
|
||||||
minetest.chat_send_player(name, "Teleported to home!")
|
minetest.chat_send_player(name, "Teleported to home!")
|
||||||
|
minetest.log("action","Player ".. name .." teleported to home. Last teleportation allowed in ".. HOME_INTERVAL .." seconds.")
|
||||||
|
timers[name] = os.time()
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, "Set a home using /sethome")
|
minetest.chat_send_player(name, "Set a home using /sethome")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user