]> git.lizzy.rs Git - dragonfireclient.git/blob - clientmods/warp/init.lua
Added EntitySpeed
[dragonfireclient.git] / clientmods / warp / init.lua
1 warp = {}
2
3 local storage = minetest.get_mod_storage()
4
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 .. "."
10 end
11
12 function warp.set_here(param)
13         local success, message = warp.set(param, vector.round(minetest.localplayer:get_pos()))
14         return success, message
15 end
16
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)
22 end
23
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 .. "."
28 end
29
30 minetest.register_chatcommand("setwarp", {
31         params = "<warp>",
32         description = "Set a warp to your current position.",
33         func = warp.set_here,
34 })
35
36 minetest.register_chatcommand("readwarp", {
37         params = "<warp>",
38         description = "Print the coordinates of a warp.",
39         func = warp.get,
40 })
41
42 minetest.register_chatcommand("deletewarp", {
43         params = "<warp>",
44         description = "Delete a warp.",
45         func = warp.delete,
46 })
47
48 local function do_warp(param)
49         if param == "" then return false, "Missing parameter." end
50         local success, pos = minetest.parse_pos(param)
51         if not success then
52                 local msg
53                 success, msg, pos = warp.get(param)
54                 if not success then
55                         return false, msg
56                 end
57         end
58         minetest.localplayer:set_pos(pos)
59         return true, "Warped to " .. minetest.pos_to_string(pos)
60 end
61
62 minetest.register_chatcommand("warp", {
63         params = "<pos>|<warp>",
64         description = "Warp to a set warp or a position.",
65         func = do_warp
66 })
67
68 minetest.register_chatcommand("warpandexit", {
69         params = "<pos>|<warp>",
70         description = "Warp to a set warp or a position and exit.",
71         func = function(param)
72                 local s, m = do_warp(param)
73                 if s then
74                         minetest.disconnect()
75                 end
76                 return s,m 
77         end
78 })