3 local storage = minetest.get_mod_storage()
5 function warp.set(warp, pos)
6 if warp == "" or not pos then return false, "Missing parameter." end
7 local posstr = minetest.pos_to_string(pos)
8 storage:set_string(warp, posstr)
9 return true, "Warp " .. warp .. " set to " .. posstr .. "."
12 function warp.set_here(param)
13 local success, message = warp.set(param, vector.round(minetest.localplayer:get_pos()))
14 return success, message
17 function warp.get(param)
18 if param == "" then return false, "Missing parameter." end
19 local pos = storage:get_string(param)
20 if pos == "" then return false, "Warp " .. param .. " not set." end
21 return true, "Warp " .. param .. " is set to " .. pos .. ".", minetest.string_to_pos(pos)
24 function warp.delete(param)
25 if param == "" then return false, "Missing parameter." end
26 storage:set_string(param, "")
27 return true, "Deleted warp " .. param .. "."
30 minetest.register_chatcommand("setwarp", {
32 description = "Set a warp to your current position.",
36 minetest.register_chatcommand("readwarp", {
38 description = "Print the coordinates of a warp.",
42 minetest.register_chatcommand("deletewarp", {
44 description = "Delete a warp.",
48 minetest.register_chatcommand("listwarps", {
49 description = "List all warps.",
51 local warps = storage:to_table().fields
53 for warp in pairs(warps) do
54 table.insert(warplist, warp)
57 return true, table.concat(warplist, ", ")
59 return false, "No warps set."
64 local function do_warp(param)
65 if param == "" then return false, "Missing parameter." end
66 local success, pos = minetest.parse_pos(param)
69 success, msg, pos = warp.get(param)
74 minetest.localplayer:set_pos(pos)
75 return true, "Warped to " .. minetest.pos_to_string(pos)
78 minetest.register_chatcommand("warp", {
79 params = "<pos>|<warp>",
80 description = "Warp to a set warp or a position.",
84 minetest.register_chatcommand("warpandexit", {
85 params = "<pos>|<warp>",
86 description = "Warp to a set warp or a position and exit.",
87 func = function(param)
88 local s, m = do_warp(param)