local homepos = {}
local function loadhomes()
- local input, err = io.open(homes_file, "r")
+ local input = io.open(homes_file, "r")
if not input then
- return minetest.log("info", "Could not load player homes file: " .. err)
+ return -- no longer an error
end
-- Iterate over all stored positions in the format "x y z player" for each line
if not player or not pos then
return false
end
+ player:set_attribute("sethome:home", minetest.pos_to_string(pos))
+ -- remove `name` from the old storage file
local data = {}
- local output, err = io.open(homes_file, "w")
+ local output = io.open(homes_file, "w")
if output then
- homepos[name] = pos
+ homepos[name] = nil
for i, v in pairs(homepos) do
table.insert(data, string.format("%.1f %.1f %.1f %s\n", v.x, v.y, v.z, i))
end
io.close(output)
return true
end
- minetest.log("action", "Unable to write to player homes file: " .. err)
- return false
+ return true -- if the file doesn't exist - don't return an error.
end
sethome.get = function(name)
- local pos = homepos[name]
+ local player = minetest.get_player_by_name(name)
+ local pos = minetest.string_to_pos(player:get_attribute("sethome:home"))
+ if pos then
+ return pos
+ end
+
+ -- fetch old entry from storage table
+ pos = homepos[name]
if pos then
return vector.new(pos)
else
end
sethome.go = function(name)
+ local pos = sethome.get(name)
local player = minetest.get_player_by_name(name)
- if player and homepos[name] then
- player:setpos(homepos[name])
+ if player and pos then
+ player:setpos(pos)
return true
end
return false