1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-01-12 19:10:26 +01:00

Merge pull request #19 by crabman77

"debug et ajout du timer dans sethome"
Branch : http://github.com/crabman77/minetest-minetestforfun-server/tree/master
This commit is contained in:
LeMagnesium 2015-02-12 17:36:10 +01:00
commit 7af8ece667
2 changed files with 38 additions and 27 deletions

View File

@ -3,8 +3,10 @@ home = {}
home.homes_file = {["real"] = minetest.get_worldpath() .. "/realhomes", home.homes_file = {["real"] = minetest.get_worldpath() .. "/realhomes",
["nether"] = minetest.get_worldpath() .. "/netherhomes"} ["nether"] = minetest.get_worldpath() .. "/netherhomes"}
home.homepos = {["real"] = {}, ["nether"] = {}} home.homepos = {["real"] = {}, ["nether"] = {}}
home.timers = {} home.g_timers = {}
home.HOME_INTERVAL = 20*60 home.s_timers = {}
home.GET_HOME_INTERVAL = 20*60
home.SET_HOME_INTERVAL = 20*60
home.sethome = function(name) home.sethome = function(name)
local player = minetest.env:get_player_by_name(name) local player = minetest.env:get_player_by_name(name)
@ -13,17 +15,27 @@ home.sethome = function(name)
if pos.y < -19600 then if pos.y < -19600 then
p_status = "nether" p_status = "nether"
end end
if home.s_timers[name] ~= nil then
local timer_player = os.difftime(os.time(),home.s_timers[name])
if timer_player < home.SET_HOME_INTERVAL then -- less than x minutes
minetest.chat_send_player(name, "Please retry later, you used sethome last time less than ".. home.SET_HOME_INTERVAL .." seconds ago.")
minetest.chat_send_player(name, "Retry in: ".. home.SET_HOME_INTERVAL-timer_player .." seconds.")
minetest.log("action","Player ".. name .." tried to sethome within forbidden interval.")
return false
end
end
if home.homepos[p_status][player:get_player_name()] ~= pos then
home.s_timers[name] = os.time()
home.homepos[p_status][player:get_player_name()] = pos home.homepos[p_status][player:get_player_name()] = pos
minetest.chat_send_player(name, "Home set!") minetest.chat_send_player(name, "Home set!")
local CHANGED = true
if changed then
local output = io.open(home.homes_file[p_status], "w") local output = io.open(home.homes_file[p_status], "w")
for i, v in pairs(home.homepos[p_status]) do for i, v in pairs(home.homepos[p_status]) do
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n") output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
end end
io.close(output) io.close(output)
changed = false return true
end end
return false
end end
home.tohome = function(name) home.tohome = function(name)
@ -37,19 +49,19 @@ home.tohome = function(name)
p_status = "nether" p_status = "nether"
end end
if home.homepos[p_status][name] then if home.homepos[p_status][name] then
if home.timers[name] ~= nil then if home.g_timers[name] ~= nil then
local timer_player = os.difftime(os.time(),home.timers[name]) local timer_player = os.difftime(os.time(),home.g_timers[name])
if timer_player < home.HOME_INTERVAL then -- less than x minutes if timer_player < home.GET_HOME_INTERVAL then -- less than x minutes
minetest.chat_send_player(name, "Please retry later, you used home last time less than ".. home.HOME_INTERVAL .." seconds ago.") minetest.chat_send_player(name, "Please retry later, you used home last time less than ".. home.GET_HOME_INTERVAL .." seconds ago.")
minetest.chat_send_player(name, "Retry in: ".. home.HOME_INTERVAL-timer_player .." seconds.") minetest.chat_send_player(name, "Retry in: ".. home.GET_HOME_INTERVAL-timer_player .." seconds.")
minetest.log("action","Player ".. name .." tried to teleport home within forbidden interval.") minetest.log("action","Player ".. name .." tried to teleport home within forbidden interval.")
return false return false
end end
end end
player:setpos(home.homepos[p_status][player:get_player_name()]) player:setpos(home.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.HOME_INTERVAL .." seconds.") minetest.log("action","Player ".. name .." teleported to home. Last teleportation allowed in ".. home.GET_HOME_INTERVAL .." seconds.")
home.timers[name] = os.time() home.g_timers[name] = os.time()
return true return true
else else
minetest.chat_send_player(name, "Set a home using /sethome") minetest.chat_send_player(name, "Set a home using /sethome")
@ -82,8 +94,6 @@ loadhomes()
minetest.register_privilege("home", "Can use /sethome and /home") minetest.register_privilege("home", "Can use /sethome and /home")
local changed = false
minetest.register_chatcommand("home", { minetest.register_chatcommand("home", {
description = "Teleport you to your home point", description = "Teleport you to your home point",
privs = {home=true}, privs = {home=true},

View File

@ -47,9 +47,10 @@ unified_inventory.register_button("home_gui_set", {
image = "ui_sethome_icon.png", image = "ui_sethome_icon.png",
tooltip = S("Set home position"), tooltip = S("Set home position"),
action = function(player) action = function(player)
if home.sethome(player:get_player_name()) == true then
minetest.sound_play("dingdong", minetest.sound_play("dingdong",
{to_player=player:get_player_name(), gain = 1.0}) {to_player=player:get_player_name(), gain = 1.0})
home.sethome(player:get_player_name()) end
end, end,
}) })