mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-06-04 21:10:04 -04:00
Tweaks sethome
This commit is contained in:
parent
09d910efcb
commit
28f08be995
1 changed files with 45 additions and 49 deletions
|
@ -2,64 +2,60 @@ local homes_file = minetest.get_worldpath() .. "/homes"
|
||||||
local homepos = {}
|
local homepos = {}
|
||||||
|
|
||||||
local function loadhomes()
|
local function loadhomes()
|
||||||
local input = io.open(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")
|
||||||
if x == nil then
|
if not x then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
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[name:sub(2)] = {x = x, y = y, z = z}
|
homepos[name:sub(2)] = vector.new(x, y, z)
|
||||||
until input:read(0) == nil
|
until not input:read(0)
|
||||||
io.close(input)
|
io.close(input)
|
||||||
else
|
end
|
||||||
homepos = {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
loadhomes()
|
loadhomes()
|
||||||
|
|
||||||
|
minetest.register_on_shutdown(function()
|
||||||
|
local output = io.open(homes_file, "w")
|
||||||
|
for i, v in pairs(homepos) do
|
||||||
|
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
|
||||||
|
end
|
||||||
|
io.close(output)
|
||||||
|
end)
|
||||||
|
|
||||||
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},
|
||||||
func = function(name)
|
func = function(name)
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
if player == nil then
|
if not player then
|
||||||
-- just a check to prevent the server crashing
|
return false
|
||||||
return false
|
end
|
||||||
end
|
if homepos[name] then
|
||||||
if homepos[player:get_player_name()] then
|
player:setpos(homepos[name])
|
||||||
player:setpos(homepos[player:get_player_name()])
|
return "Teleported to home!"
|
||||||
minetest.chat_send_player(name, "Teleported to home!")
|
else
|
||||||
else
|
return "Set a home using /sethome"
|
||||||
minetest.chat_send_player(name, "Set a home using /sethome")
|
end
|
||||||
end
|
end
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("sethome", {
|
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.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local pos = player:getpos()
|
if not player then
|
||||||
homepos[player:get_player_name()] = pos
|
return false
|
||||||
minetest.chat_send_player(name, "Home set!")
|
end
|
||||||
changed = true
|
homepos[name] = player:getpos()
|
||||||
if changed then
|
return "Home set!"
|
||||||
local output = io.open(homes_file, "w")
|
end
|
||||||
for i, v in pairs(homepos) do
|
|
||||||
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
|
|
||||||
end
|
|
||||||
io.close(output)
|
|
||||||
changed = false
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue