1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-25 18:20:36 +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,27 +3,39 @@ 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)
local pos = player:getpos() local pos = player:getpos()
local p_status = "real" local p_status = "real"
if pos.y < -19600 then if pos.y < -19600 then
p_status = "nether" p_status = "nether"
end end
home.homepos[p_status][player:get_player_name()] = pos if home.s_timers[name] ~= nil then
minetest.chat_send_player(name, "Home set!") local timer_player = os.difftime(os.time(),home.s_timers[name])
local CHANGED = true if timer_player < home.SET_HOME_INTERVAL then -- less than x minutes
if changed then minetest.chat_send_player(name, "Please retry later, you used sethome last time less than ".. home.SET_HOME_INTERVAL .." seconds ago.")
local output = io.open(home.homes_file[p_status], "w") minetest.chat_send_player(name, "Retry in: ".. home.SET_HOME_INTERVAL-timer_player .." seconds.")
for i, v in pairs(home.homepos[p_status]) do minetest.log("action","Player ".. name .." tried to sethome within forbidden interval.")
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n") return false
end end
io.close(output) end
changed = false if home.homepos[p_status][player:get_player_name()] ~= pos then
end home.s_timers[name] = os.time()
home.homepos[p_status][player:get_player_name()] = pos
minetest.chat_send_player(name, "Home set!")
local output = io.open(home.homes_file[p_status], "w")
for i, v in pairs(home.homepos[p_status]) do
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
end
io.close(output)
return true
end
return false
end end
home.tohome = function(name) home.tohome = function(name)
@ -36,20 +48,20 @@ home.tohome = function(name)
if player:getpos().y < -19600 then if player:getpos().y < -19600 then
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)
minetest.sound_play("dingdong", if home.sethome(player:get_player_name()) == true then
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,
}) })