1 local homes_file = minetest.get_worldpath() .. "/homes"
4 local function loadhomes()
5 local input = io.open(homes_file, "r")
8 local x = input:read("*n")
12 local y = input:read("*n")
13 local z = input:read("*n")
14 local name = input:read("*l")
15 homepos[name:sub(2)] = {x = x, y = y, z = z}
16 until input:read(0) == nil
25 minetest.register_privilege("home", "Can use /sethome and /home")
29 minetest.register_chatcommand("home", {
30 description = "Teleport you to your home point",
33 local player = minetest.get_player_by_name(name)
35 -- just a check to prevent the server crashing
38 if homepos[player:get_player_name()] then
39 player:setpos(homepos[player:get_player_name()])
40 minetest.chat_send_player(name, "Teleported to home!")
42 minetest.chat_send_player(name, "Set a home using /sethome")
47 minetest.register_chatcommand("sethome", {
48 description = "Set your home point",
51 local player = minetest.get_player_by_name(name)
52 local pos = player:getpos()
53 homepos[player:get_player_name()] = pos
54 minetest.chat_send_player(name, "Home set!")
57 local output = io.open(homes_file, "w")
58 for i, v in pairs(homepos) do
59 output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")