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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
local S = protector.intllib
protector.removal_names = ""
protector.replace_names = ""
minetest.register_chatcommand("protector_remove", {
params = "<names list>",
description = S("Remove Protectors around players (separate names with spaces)"),
privs = {server = true},
func = function(name, param)
if not param or param == "" then
minetest.chat_send_player(name,
"Protector Names to remove: "
.. protector.removal_names)
return
end
if param == "-" then
minetest.chat_send_player(name,
S("Name List Reset"))
protector.removal_names = ""
return
end
protector.removal_names = param
end,
})
minetest.register_chatcommand("protector_replace", {
params = "<owner name> <name to replace with>",
description = S("Replace Protector Owner with name provided"),
privs = {server = true},
func = function(name, param)
if not param or param == "" then
if protector.replace_names ~= "" then
local names = protector.replace_names:split(" ")
minetest.chat_send_player(name,
"Replacing Protector name '" .. names[1]
.. "' with '" .. names[2] .. "'")
return
else
minetest.chat_send_player(name,
"Usage: /protector_replace <owner name> <new owner name>")
return
end
end
if param == "-" then
minetest.chat_send_player(name,
S("Name List Reset"))
protector.replace_names = ""
return
end
protector.replace_names = param
end,
})
minetest.register_abm({
nodenames = {"protector:protect", "protector:protect2"},
interval = 8,
chance = 1,
catch_up = false,
action = function(pos, node)
if protector.removal_names == ""
and protector.replace_names == "" then
return
end
local meta = minetest.get_meta(pos) ; if not meta then return end
local owner = meta:get_string("owner")
--local members = meta:get_string("members")
if protector.removal_names ~= "" then
local names = protector.removal_names:split(" ")
for _, n in pairs(names) do
if n == owner then
minetest.set_node(pos, {name = "air"})
end
end
end
if protector.replace_names ~= "" then
local names = protector.replace_names:split(" ")
if owner == names[1] then
meta:set_string("owner", names[2])
meta:set_string("infotext", "Protection (owned by " .. names[2] .. ")")
end
end
end
})
-- show protection areas of nearby protectors owned by you (thanks agaran)
minetest.register_chatcommand("protector_show", {
params = "",
description = "Show protected areas of your nearby protectors",
privs = {},
func = function(name, param)
local player = minetest.get_player_by_name(name)
local pos = player:getpos()
local r = protector.radius -- max protector range.
-- find the protector nodes
local pos = minetest.find_nodes_in_area(
{x = pos.x - r, y = pos.y - r, z = pos.z - r},
{x = pos.x + r, y = pos.y + r, z = pos.z + r},
{"protector:protect", "protector:protect2"})
local meta, owner
-- show a maximum of 5 protected areas only
for n = 1, math.min(#pos, 5) do
meta = minetest.get_meta(pos[n])
owner = meta:get_string("owner") or ""
if owner == name then
minetest.add_entity(pos[n], "protector:display")
end
end
end
})
|