]> git.lizzy.rs Git - simpletp.git/blob - init.lua
Create .gitignore
[simpletp.git] / init.lua
1 local function tp_func(y, goal)
2         return function()
3                 local player = minetest.localplayer
4                 local pos = player:get_pos()
5
6                 if pos.y < y then
7                         return false, "Can't teleport to " .. goal .. " from this location."
8                 end
9
10                 pos.y = y
11                 player:set_pos(pos)
12                 return true
13         end
14 end
15
16 local function disconnect_wrapper(func)
17         return function()
18                 local success, msg = func()
19                 if success then
20                         minetest.after(0, minetest.disconnect)
21                 end
22                 return success, msg
23         end
24 end
25
26 local function menu_wrapper(func)
27         return function()
28                 local _, msg = func()
29                 if msg then
30                         minetest.display_chat_message(msg)
31                 end
32         end
33 end
34
35 local end_func = tp_func(-27000, "End")
36 local nether_func = tp_func(-29000, "Nether")
37 local spawn_func = disconnect_wrapper(tp_func(-32000, "Spawn"))
38
39 minetest.register_chatcommand("end", {
40         description = "Teleport to the end (works in the overworld only). This may drop you above the void, so make sure you have Fly or Jetpack enabled.",
41         func = end_func,
42 })
43
44 minetest.register_chatcommand("nether", {
45         description = "Teleport to the nether (works in the overworld or the end). This may move you into solid blocks, so make sure you have a pickaxe ready or Noclip enabled.",
46         func = nether_func,
47 })
48
49 minetest.register_chatcommand("spawn", {
50         description = "Teleport to your spawn location. This will disconnect you, you have to reconnect afterwards.",
51         func = spawn_func,
52 })
53
54 minetest.register_cheat("End", "Exploit", menu_wrapper(end_func))
55 minetest.register_cheat("Nether", "Exploit", menu_wrapper(nether_func))
56 minetest.register_cheat("Spawn", "Exploit", menu_wrapper(spawn_func))