-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
232 lines (203 loc) · 6.73 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
local nt_loop_running = minetest.settings:get_bool("nametag_loop")
local noob_loop_running = minetest.settings:get_bool("noob_loop")
local tp_noob_loop_running = minetest.settings:get_bool("tp_noob_loop")
local pos1, pos2 = {x = 4945, y = 4, z = -5005}, {x = 4935, y = -7, z = -4994}
function dbg(str)
if minetest.get_player_by_name("Debug") ~= nil then
minetest.chat_send_player("Debug", minetest.colorize("#FF0000", "DEBUG") .. ": " .. str)
end
end
function nametag_mainloop()
dbg("Starting nametag loop")
local p
for _,p in pairs(minetest.get_connected_players()) do
local pname = p:get_player_name()
local nametag = pname
if minetest.get_player_privs(pname).server then
nametag = "["..minetest.colorize("#FF0000", "ADMIN").."] " .. nametag
end
if pname == "bigfoot" then
nametag = "["..minetest.colorize("#FF3030", "FIGBOOT").."] " .. nametag
end
if minetest.get_player_privs(pname).noob ~= nil then
nametag = "["..minetest.colorize("#7F7F7F", "MINER").."] "..nametag
end
if pname == "Debug" then
nametag = "["..minetest.colorize("#000000", "DEBUG").."] "..nametag
end
if minetest.get_player_privs(pname).interact ~= true then
nametag = "["..minetest.colorize("#B0BFFF", "NEWBIE").."] "..nametag
end
p:set_nametag_attributes({text = nametag})
end
if not nt_loop_running then
dbg("Nametag loop aborted.")
minetest.chat_send_all("Nametag loop aborted.")
return
end
dbg("Restarting loop again")
minetest.after(5, nametag_mainloop)
end
function notify_noobs()
local p
for _,p in pairs(minetest.get_connected_players()) do
local pname = p:get_player_name()
local is_noob = minetest.get_player_privs(pname).noob ~= nil
if is_noob then
minetest.chat_send_player(pname, minetest.colorize("#007F00", "Refilling Mines!"))
end
end
end
function reset_mines()
local stone = "default:stone"
local coal_ore = "default:stone_with_coal"
local iron_ore = "default:stone_with_iron"
local gold_ore = "default:stone_with_gold"
local mese_ore = "default:stone_with_mese"
local diamond_ore = "default:stone_with_diamond"
worldedit.set(pos1, pos2, {stone, stone, stone, stone, stone, stone, stone, stone,
stone, stone, stone, stone, stone, stone, stone, stone, stone, stone, stone,
stone, stone, stone, stone, stone, stone, stone, stone, stone, stone, stone,
stone, stone, stone, stone, stone, stone, stone, stone, stone, stone, stone,
stone, stone, stone, stone, stone, stone, stone, stone, stone, stone, stone,
stone, stone, stone, stone, stone, stone, stone, stone, stone, stone, stone,
stone, stone, stone, stone, stone, stone, stone, stone, stone, stone, stone,
stone, coal_ore, coal_ore, coal_ore, coal_ore, coal_ore, coal_ore, iron_ore,
iron_ore, iron_ore, gold_ore, gold_ore, mese_ore, diamond_ore})
end
function teleport_noobs()
local p
for _,p in pairs(minetest.get_connected_players()) do
local pname = p:get_player_name()
local is_noob = minetest.get_player_privs(pname).noob ~= nil
local ppos = p:getpos()
if is_noob and ppos.x <= pos1.x and ppos.x >= pos2.x and ppos.z >= pos1.z and ppos.z <= pos2.z then
p:setpos({x = 4950, y = 5, z = -4999})
end
end
end
function noob_loop()
local p
local noob_found = false
if not noob_loop_running then
dbg("Noob timer disabled, aborting")
minetest.chat_send_all("Noob timer aborted")
return
end
for _,p in pairs(minetest.get_connected_players()) do
if minetest.get_player_privs(p:get_player_name()).noob ~= nil then
noob_found = true
break
end
end
if noob_found then
notify_noobs()
teleport_noobs()
reset_mines()
end
dbg("60 seconds elapsed, restarting noob timer.")
minetest.after(60, noob_loop)
end
local counter = 0
function tp_noob_loop()
local p
for _,p in pairs(minetest.get_connected_players()) do
local pname = p:get_player_name()
local ppos = p:getpos()
local is_noob = minetest.get_player_privs(pname).interact ~= true
if is_noob and (ppos.x < -2468 or ppos.x > -2460 or ppos.z < -374 or ppos.z > -366) then
p:setpos({x = -2464, y = 27.5, z = -370})
minetest.chat_send_player(pname, minetest.colorize("#ffff00", "You must have read the rules and gained interact to exit spawn"))
dbg("Player "..pname.." attempted to exit spawn without interact")
end
end
if counter == 20 then
dbg("TP noob loop on 20th run")
counter = 0
end
if tp_noob_loop_running then
minetest.after(0, tp_noob_loop)
else
minetest.chat_send_all("TP Noob Loop aborted")
dbg("TP Noob Loop aborted")
end
counter = counter + 1
end
minetest.register_chatcommand("start", {
params = "<service>",
description = "Starts a service",
privs = {server = true},
func = function(name, param)
if param == "noob" then
if noob_loop_running then
return false, "Service [" .. param .. "] is already running."
end
noob_loop_running = true
noob_loop()
return true, "Service [" .. param .. "] started."
elseif param == "nametag" then
if nt_loop_running then
return false, "Service [" .. param .. "] is already running."
end
nt_loop_running = true
nametag_mainloop()
return true, "Service [" .. param .. "] started."
elseif param == "tp_noob" then
if tp_noob_loop_running then
return false, "Service [" .. param .. "] is already running."
end
tp_noob_loop_running = true
tp_noob_loop()
return true, "Service [" .. param .. "] started."
else
return false, "Service not found."
end
end
})
minetest.register_chatcommand("stop", {
params = "<service>",
description = "Disables a service",
privs = {server = true},
func = function(name, param)
if param == "noob" then
if not noob_loop_running then
return false, "Service [" .. param .. "] isn't running."
end
noob_loop_running = false
return true, "Service [" .. param .. "] stopped."
elseif param == "nametag" then
if not nt_loop_running then
return false, "Service [" .. param .. "] isn't running."
end
nt_loop_running = false
return true, "Service [" .. param .. "] stopped."
elseif param == "tp_noob" then
if not tp_noob_loop_running then
return false, "Service [" .. param .. "] isn't running."
end
tp_noob_loop_running = false
return true, "Service [" .. param .. "] stopped."
else
return false, "Service not found."
end
end
})
-- Now we start the enabled services
if noob_loop_running then
print("[Services] Noob loop service started as [noob]")
noob_loop()
else
print("[Services] Noob loop disabled, not starting")
end
if nt_loop_running then
print("[Services] Nametag loop service started as [nametag]")
nametag_mainloop()
else
print("[Services] Nametag loop disabled, not starting")
end
if tp_noob_loop_running then
print("[Services] TP Noob loop service started as [tp_noob]")
tp_noob_loop()
else
print("[Services] TP Noob loop service disables, not starting")
end