1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-25 02:00:37 +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",
["nether"] = minetest.get_worldpath() .. "/netherhomes"}
home.homepos = {["real"] = {}, ["nether"] = {}}
home.timers = {}
home.HOME_INTERVAL = 20*60
home.g_timers = {}
home.s_timers = {}
home.GET_HOME_INTERVAL = 20*60
home.SET_HOME_INTERVAL = 20*60
home.sethome = function(name)
local player = minetest.env:get_player_by_name(name)
local pos = player:getpos()
local player = minetest.env:get_player_by_name(name)
local pos = player:getpos()
local p_status = "real"
if pos.y < -19600 then
p_status = "nether"
end
home.homepos[p_status][player:get_player_name()] = pos
minetest.chat_send_player(name, "Home set!")
local CHANGED = true
if changed then
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)
changed = false
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
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
home.tohome = function(name)
@ -36,20 +48,20 @@ home.tohome = function(name)
if player:getpos().y < -19600 then
p_status = "nether"
end
if home.homepos[p_status][name] then
if home.timers[name] ~= nil then
local timer_player = os.difftime(os.time(),home.timers[name])
if timer_player < home.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, "Retry in: ".. home.HOME_INTERVAL-timer_player .." seconds.")
if home.homepos[p_status][name] then
if home.g_timers[name] ~= nil then
local timer_player = os.difftime(os.time(),home.g_timers[name])
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.GET_HOME_INTERVAL .." seconds ago.")
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.")
return false
end
end
player:setpos(home.homepos[p_status][player:get_player_name()])
minetest.chat_send_player(name, "Teleported to home!")
minetest.log("action","Player ".. name .." teleported to home. Last teleportation allowed in ".. home.HOME_INTERVAL .." seconds.")
home.timers[name] = os.time()
minetest.log("action","Player ".. name .." teleported to home. Last teleportation allowed in ".. home.GET_HOME_INTERVAL .." seconds.")
home.g_timers[name] = os.time()
return true
else
minetest.chat_send_player(name, "Set a home using /sethome")
@ -82,8 +94,6 @@ loadhomes()
minetest.register_privilege("home", "Can use /sethome and /home")
local changed = false
minetest.register_chatcommand("home", {
description = "Teleport you to your home point",
privs = {home=true},

View File

@ -47,9 +47,10 @@ unified_inventory.register_button("home_gui_set", {
image = "ui_sethome_icon.png",
tooltip = S("Set home position"),
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})
home.sethome(player:get_player_name())
end
end,
})