1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-25 18:20:36 +01:00

Undo sethome modifications

- Replacing modified sethome by 0.4.10-release's sethome.
This commit is contained in:
LeMagnesium 2014-11-16 16:55:13 +01:00
parent 22e604f398
commit 5e94b24fca
2 changed files with 20 additions and 78 deletions

View File

@ -1,2 +0,0 @@
default
nether

View File

@ -1,9 +1,8 @@
local real_homes_file = minetest.get_worldpath() .. "/real_homes" local homes_file = minetest.get_worldpath() .. "/homes"
local nether_homes_file = minetest.get_worldpath() .. "/nether_homes" local homepos = {}
local homepos = {real = {},nether = {}}
local function loadhomes() local function loadhomes()
local input = io.open(real_homes_file, "r") local input = io.open(homes_file, "r")
if input then if input then
repeat repeat
local x = input:read("*n") local x = input:read("*n")
@ -13,29 +12,12 @@ local function loadhomes()
local y = input:read("*n") local y = input:read("*n")
local z = input:read("*n") local z = input:read("*n")
local name = input:read("*l") local name = input:read("*l")
homepos.real[name:sub(2)] = {x = x, y = y, z = z} homepos[name:sub(2)] = {x = x, y = y, z = z}
until input:read(0) == nil until input:read(0) == nil
io.close(input) io.close(input)
else else
homepos.real = {} homepos = {}
end end
input = io.open(nether_homes_file, "r")
if input then
repeat
local x = input:read("*n")
if x == nil then
break
end
local y = input:read("*n")
local z = input:read("*n")
local name = input:read("*n")
homepos.nether[name:sub(2)] = {x = x, y = y, z = z}
until input:read(0) == nil
io.close(input)
else
homepos.nether = {}
end
end end
loadhomes() loadhomes()
@ -48,32 +30,16 @@ minetest.register_chatcommand("home", {
description = "Teleport you to your home point", description = "Teleport you to your home point",
privs = {home=true}, privs = {home=true},
func = function(name) func = function(name)
local player = minetest.env:get_player_by_name(name)
local player = minetest.get_player_by_name(name)
local player_pos = player:getpos()
local is_player_in_nether = player_pos.y < -19600
if player == nil then if player == nil then
-- just a check to prevent the server crashing -- just a check to prevent the server crashing
return false return false
end end
if homepos[player:get_player_name()] then
if is_player_in_nether then player:setpos(homepos[player:get_player_name()])
if homepos.nether[name] ~= nil then minetest.chat_send_player(name, "Teleported to home!")
player:setpos(homepos.nether[name]) else
minetest.log("action",name.." teleported with /home to "..homepos.nether[name].x..","..homepos.nether[name].y..","..homepos.nether[name].z..", in the nether.") minetest.chat_send_player(name, "Set a home using /sethome")
core.chat_send_player(name, "Teleported to home in the nether!")
else
core.chat_send_player(name, "Set a home in the nether using /sethome")
end
else
if homepos.real[name] ~= nil then
player:setpos(homepos.real[name])
minetest.log("action",name.." teleported with /home to "..homepos.real[name].x..","..homepos.real[name].y..","..homepos.real[name].z..", in the real world.")
core.chat_send_player(name,"Teleported to home in the real world!")
else
core.chat_send_player(name, "Set a home in the real world using /sethome")
end
end end
end, end,
}) })
@ -82,38 +48,16 @@ minetest.register_chatcommand("sethome", {
description = "Set your home point", description = "Set your home point",
privs = {home=true}, privs = {home=true},
func = function(name) func = function(name)
local player = minetest.env:get_player_by_name(name)
local player_pnt = minetest.get_player_by_name(name) local pos = player:getpos()
local player_pos = player_pnt:getpos() homepos[player:get_player_name()] = pos
local player_is_in_nether = player_pos.y < -19600 minetest.chat_send_player(name, "Home set!")
changed = true
if player_is_in_nether == true then
homepos.nether[name] = pos
minetest.log("action",name.." set its home position to "..player_pos.x..","..player_pos.y..","..player_pos.z..", in the nether.")
core.chat_send_player(name,"Home set in the nether!")
else
homepos.real[name] = pos
minetest.log("action",name.." set its home position to "..player_pos.x..","..player_pos.y..","..player_pos.z..", in the real world.")
core.chat_send_player(name,"Home set in the real world!")
end
changed = true
if changed then if changed then
local output = 0 local output = io.open(homes_file, "w")
for i, v in pairs(homepos) do
if is_in_nether then output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
output = io.open(nether_homes_file, "w") end
if output == 0 then return end -- Had not open the file
for i, v in pairs(homepos.nether) do
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
end
else
output = io.open(real_homes_file, "w")
for i, v in pairs(homepos.real) do
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
end
end
io.close(output) io.close(output)
changed = false changed = false
end end