-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
96 lines (79 loc) · 2.08 KB
/
init.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
-- WRITE CHANGES to FILE
local write_gofile = function()
local output = ''
for name, coords in pairs(GONETWORK) do
output = output..name..':'..coords.x..','..coords.y..','..coords.z..';'
end
local f = io.open(minetest.get_worldpath()..'/destinations.go', "w")
f:write(output)
io.close(f)
end
GONETWORK = {}
local gonfile = io.open(minetest.get_worldpath()..'/destinations.go', "r")
if gonfile then
local contents = gonfile:read()
io.close(gonfile)
if contents ~= nil then
local entries = contents:split(";")
for i,entry in pairs(entries) do
local goname, coords = unpack(entry:split(":"))
local p = {}
p.x, p.y, p.z = string.match(
coords, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$"
)
if p.x and p.y and p.z then
GONETWORK[goname] =
{x = tonumber(p.x),y= tonumber(p.y),z = tonumber(p.z)}
end
end
end
end
-- CHAT COMMANDS
minetest.register_chatcommand("setgo", {
params = "<name>",
description = "set /go destination",
privs = {server=true},
func = function(name, param)
local target = minetest.get_player_by_name(name)
if target then
GONETWORK[param] = target:getpos()
write_gofile()
minetest.chat_send_player(name, "/go "..param.." set")
return
end
end,
})
minetest.register_chatcommand("go", {
params = "<goname>",
description = "go to destination",
func = function(name, param)
if GONETWORK[param] == nil then
minetest.chat_send_player(name, "no such destination")
return
end
teleportee = minetest.get_player_by_name(name)
teleportee:setpos(GONETWORK[param])
end,
})
minetest.register_chatcommand("delgo", {
params = "<name>",
description = "delete /go destination",
privs = {server=true},
func = function(name, param)
if GONETWORK[param] then
GONETWORK[param] = nil
write_gofile()
end
end,
})
minetest.register_chatcommand("listgo", {
params = "<goname>",
description = "list all go destinations",
func = function(name, param)
for go, coords in pairs(GONETWORK) do
minetest.chat_send_player(
name, "/go "..go.. ' at '..coords.x..','..coords.y..','..coords.z
)
end
end,
})