-
Notifications
You must be signed in to change notification settings - Fork 8
/
sethome.lua
50 lines (43 loc) · 1.5 KB
/
sethome.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local S = minetest.get_translator("sethome")
local function set_home(player, name, pos, set_home_func, ...)
-- Don't allow setting home if the player is not allowed to teleport back here
local can_teleport, errmsg = pandorabox.can_teleport(player, pos)
if not can_teleport then
return false, (errmsg and (errmsg .. "\n") or "") .. "Cannot set home!"
end
-- Don't allow setting home in a area owned by another player
if minetest.is_protected(pos, name) then
return false, "Cannot set home in protected area!"
end
if set_home_func(...) ~= false then
return true, S("Home set!")
end
-- This should never be reached, but return an error message anyway
return false, "Error setting home!"
end
-- default sethome mod
-- Override chat command so the error messages are more helpful
minetest.register_chatcommand("sethome", {
description = S("Set your home point"),
privs = {home = true},
func = function(name)
name = name or ""
local player = minetest.get_player_by_name(name)
if not player then
return false, S("Player not found!")
end
local pos = player:get_pos()
return set_home(player, name, pos, sethome.set, name, pos)
end,
})
-- unified inventory home
if minetest.get_modpath("unified_inventory") then
local old_ui_sethome = unified_inventory.set_home
unified_inventory.set_home = function(player, pos)
local name = player:get_player_name()
local set, msg = set_home(player, name, pos, old_ui_sethome, player, pos)
if not set then
minetest.chat_send_player(name, msg)
end
end
end