-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
executable file
·500 lines (350 loc) · 13.2 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
local chathelp = {}
local ch = chathelp
-- Options for Print_Message
chathelp.log = 0
chathelp.green = '#00FF00'
chathelp.red = '#FF0000'
chathelp.orange = '#FF6700'
chathelp.blue = '#0000FF'
chathelp.yellow = '#FFFF00'
chathelp.purple = '#FF00FF'
chathelp.pink = '#FFAAFF'
chathelp.white = '#FFFFFF'
chathelp.black = '#000000'
chathelp.grey = '#888888'
chathelp.light_blue = '#8888FF'
chathelp.light_green = '#88FF88'
chathelp.light_red = '#FF8888'
chathelp.none = 99
local spawnpoint = minetest.settings:get("chathelp.static_spawnpoint") or "0,0,0"
local jail = minetest.settings:get("chathelp.jail") or "-1000,-1000,-1000"
ch.spawnpoint = "(" .. spawnpoint .. ")"
ch.jail = "(" .. jail .. ")"
-- Registered Commands for Chathelp
minetest.register_chatcommand("who", {
params = "",
description = "List all connected players.",
func = function(name)
chathelp.who(name)
end
})
minetest.register_chatcommand("where_is", {
params = "Playername",
description = "Show's the Position of the Player.",
func = function(name, playername)
chathelp.where(name, playername)
end
})
minetest.register_chatcommand("show_ip", {
params = "Playername",
description = "Show's the IP of the Player.",
privs = {server = true},
func = function(name, playername)
chathelp.show_ip(name, playername)
end
})
minetest.register_chatcommand("bring", {
params = "Playername",
description = "Teleports to Player.",
privs = {teleport = true},
func = function(name, playername)
chathelp.teleport_to(name, playername)
end
})
minetest.register_chatcommand("summon", {
params = "Playername",
description = "Summons a Player.",
privs = {bring = true},
func = function(name, playername)
chathelp.summon(name, playername)
end
})
minetest.register_chatcommand("set_hp", {
params = "Playername, Hitpoints",
description = "Set's the HP of a Player.",
privs = {kick = true},
func = function(name, arg)
chathelp.set_hp(name, arg)
end
})
minetest.register_chatcommand("add_hp", {
params = "Playername, Hitpoints",
description = "Adds Hitpoints to a Player.",
privs = {kick = true},
func = function(name, arg)
chathelp.add_hp(name, arg)
end
})
minetest.register_chatcommand("sub_hp", {
params = "Playername, Hitpoints",
description = "Removes Hitpoints to a Player.",
privs = {kick = true},
func = function(name, arg)
chathelp.sub_hp(name, arg)
end
})
minetest.register_chatcommand("get_hp", {
params = "Playername",
description = "Shows the Hitpoints to a Player.",
func = function(name, playername)
chathelp.get_hp(name, playername)
end
})
minetest.register_chatcommand("spawn", {
params = "Playername",
description = "Moves you to Spawn.",
privs = {interact = true},
func = function(name)
local spawnpoint = chathelp.spawnpoint
if(spawnpoint ~= "") then
local player = minetest.get_player_by_name(name)
player:setpos(minetest.string_to_pos(spawnpoint))
else
ch.print(name, "No Spawnpoint set, contact the Admin.", chathelp.red)
end
end
})
minetest.register_chatcommand("jail", {
params = "<Player>",
description = "Moves Player into jail.",
privs = {kick = true},
func = function(name, param)
local jail = ch.jail
if(jail ~= "") then
local player = minetest.get_player_by_name(param)
if(not player) then
minetest.chat_send_player(name,
minetest.colorize(ch.red, "Unknown Player: ") ..
minetest.colorize(ch.orange, param)
)
return
end
player:setpos(minetest.string_to_pos(jail))
minetest.chat_send_all( minetest.colorize(ch.green,name) ..
minetest.colorize(ch.red," has teleported ") ..
minetest.colorize(ch.orange,param) ..
minetest.colorize(ch.red," into Jail!")
)
else
ch.print(name, "No Jailpos set, contact the Admin.", ch.red)
end
end
})
-- Commands for chathelp
-- who - Shows you all Players are online.
function chathelp.who(name)
connected_players_string = 'Players online: '
for _,player in ipairs(minetest.get_connected_players()) do
connected_players_string = connected_players_string ..
player:get_player_name() ..
','
end -- for _,player
chathelp.print(name, connected_players_string, chathelp.green)
--minetest.chat_send_player(name, connected_players_string)
return true
end -- who()
-- whereis searches for the Player, if the Player is online,
-- it show's you the current Coordinates of the Playername.
function chathelp.where(name, playername)
-- empty or invalid Nameparameter?
if(not chathelp.check_name) then
chathelp.print(name, "Invalid Playername \"\" or nil", chathelp.red)
return
end -- (if(check_name)
if(not chathelp.player_exists(playername)) then
chathelp.print(name, "Player " .. playername .. " are unknown.", chathelp.red)
return
end -- if(minetest.player_exists)
if(not chathelp.is_online(playername)) then
chathelp.print(name, "Player " .. playername .. " is not online.", chathelp.red)
return
end -- if(is_online
-- GetPlayerobject
local player = minetest.get_player_by_name(playername)
-- all ok, get Position and report it
local pos = minetest.pos_to_string(player:getpos())
chathelp.print(name, "You can find Player: " .. playername .. " at Pos: " .. pos, chathelp.green)
end -- whereis()
-- check_online(name) returns true, if the given playername is online
function chathelp.is_online(name)
for _,player in ipairs(minetest.get_connected_players()) do
if name == player:get_player_name() then
return true
end -- if(name == player.get_name()
end -- for _,player
-- Player is not online
return false
end -- is_online()
-- check if player is known? false = unknown
function chathelp.player_exists(name)
-- is the player in auth.txt?
if(minetest.player_exists(name)) then
return true -- yeahh, found
end -- if(player_exists)
return false -- not found, Player unknown
end -- player_exists()
-- check_name, returns true, if the name is valid
function chathelp.check_name(name)
if(name == "" or name == nil) then
return false
end
return true
end -- check_name()
-- Shows the IP of a Player, need Server-Priv
function chathelp.show_ip(name, playername)
if( chathelp.is_online(playername) ) then
local ip = minetest.get_player_ip(playername)
chathelp.print(name, "The IP from " .. playername .. " is: " .. ip, chathelp.green)
else
if( chathelp.player_exists(playername) )then
chathelp.print(name, "The Player " .. playername .. " isn't online.", chathelp.orange)
else
chathelp.print(name, "Player " .. playername .. " is unknown.", chathelp.red)
end -- if(player_exist)
end -- if(player_is_online)
end -- chathelp.show_ip()
-- Teleports me to the Position of the Playername
function chathelp.teleport_to(name, playername)
if( chathelp.is_online(playername) )then -- is Player online?
local player = minetest.get_player_by_name(playername)
chathelp.print(name, "Player " .. player:get_player_name() .. " is at Pos: " .. minetest.pos_to_string(player:get_pos()), chathelp.green)
chathelp.print(name, "Teleporting ..", chathelp.orange)
local me = minetest.get_player_by_name(name) -- Own Playerobject
me:set_pos(player:getpos()) -- Teleport
-- Log the Teleport
chathelp.print(name, name .. " teleported to " .. player:get_player_name() .. " at Pos: " .. minetest.pos_to_string(player:getpos()), chathelp.log)
else
chathelp.print(name, "Player " .. playername .. " isn't online.", chathelp.red)
end -- if(is_online
end -- chathelp.teleport_to
-- Brings a Player to me
function chathelp.summon(name, playername)
if( chathelp.is_online(playername) )then -- is Player online?
local player = minetest.get_player_by_name(playername)
local player_pos = minetest.pos_to_string(player:get_pos())
chathelp.print(name, "Player " .. player:get_player_name() .. " is at Pos: " .. player_pos, chathelp.green)
chathelp.print(name, "Summoning ..", chathelp.orange)
local me = minetest.get_player_by_name(name) -- Own Playerobject
player:set_pos(me:getpos()) -- Teleport
-- Log the Teleport
chathelp.print(name, name .. " summoned " .. player:get_player_name() .. " from Pos: " .. player_pos, chathelp.log)
else
chathelp.print(name, "Player " .. playername .. " isn't online.", chathelp.red)
end -- if(is_online
end -- chathelp.summon()
-- Shows the HP of an Player
function chathelp.get_hp(name, playername)
if( string.len(playername) == 0 ) then
chathelp.print(name, "No Playername given.", chathelp.red)
return false
end
if( chathelp.is_online(playername) )then -- is Player online?
local player = minetest.get_player_by_name(playername)
local hp = player:get_hp()
chathelp.print(name, player:get_player_name() .. " has " .. hp .. " Hitpoints.", chathelp.green)
if(hp > 0) then
chathelp.print(name, "This are " .. hp / 2 .. " Hearts.", chathelp.green)
else
chathelp.print(name, "Is dead.", chathelp.green)
end -- if(hp > 0)
else
chathelp.print(name, "Player " .. playername .. " isn't online.", chathelp.red)
end -- if(is_online
end -- chathelp.get_hp()
-- Sets the HP of an Player
function chathelp.set_hp(name, arg)
local playername
local hitpoints
if( string.find(arg, ",") == nil) then
chathelp.print(name, "Wrong Parameter (No Hitpoints).", chathelp.red)
return false
end
-- Split the Argument
playername = chathelp.trim(string.sub(arg,1, string.find(arg, ",")-1))
local hp = chathelp.trim(string.sub(arg, string.find(arg, ",") + 1, -1))
if(string.len(hp) == 0) then
chathelp.print(name, "No Number of Hitpoints given.", chathelp.red)
else
hitpoints = tonumber(hp)
end -- if(string.len)
if( chathelp.is_online(playername) )then -- is Player online?
local player = minetest.get_player_by_name(playername)
chathelp.print(name, "Hitpoints of " .. playername .. " set to " .. hitpoints, chathelp.green)
player:set_hp(hitpoints) -- Sets the Hitpoints
chathelp.print(name, "Has setted the Hitpoints of " .. playername .. " to " .. hitpoints, chathelp.log)
else
chathelp.print(name, "Player " .. playername .. " isn't online.", chathelp.red)
end -- if(is_online
end -- chathelp.set_hp()
-- Adds HP to the Player
function chathelp.add_hp(name, arg)
local playername
local hitpoints
if( string.find(arg, ",") == nil) then
chathelp.print(name, "Wrong Parameter (No Hitpoints).", chathelp.red)
return false
end
-- Split the Argument
playername = chathelp.trim(string.sub(arg,1, string.find(arg, ",")-1))
local hp = chathelp.trim(string.sub(arg, string.find(arg, ",") + 1, -1))
if(string.len(hp) == 0) then
chathelp.print(name, "No Number of Hitpoints given.", chathelp.red)
else
hitpoints = tonumber(hp)
end -- if(string.len)
if( chathelp.is_online(playername) )then -- is Player online?
local player = minetest.get_player_by_name(playername)
chathelp.print(name, hitpoints .. " Hitpoints add to " .. playername, chathelp.green)
player:set_hp(player:get_hp() + hitpoints) -- Add Hitpoints
chathelp.print(name, name .. " has added " .. hitpoints .. " Hitpoints to " .. playername, chathelp.log)
else
chathelp.print(name, "Player " .. playername .. " isn't online.", chathelp.red)
end -- if(is_online
end -- chathelp.add_hp()
-- Removes HP to the Player
function chathelp.sub_hp(name, arg)
local playername
local hitpoints
if( string.find(arg, ",") == nil) then
chathelp.print(name, "Wrong Parameter (No Hitpoints).", chathelp.red)
return false
end
-- Split the Argument
playername = chathelp.trim(string.sub(arg,1, string.find(arg, ",")-1))
local hp = chathelp.trim(string.sub(arg, string.find(arg, ",") + 1, -1))
if(string.len(hp) == 0) then
chathelp.print(name, "No Number of Hitpoints given.", chathelp.red)
else
hitpoints = tonumber(hp)
end -- if(string.len)
if( chathelp.is_online(playername) )then -- is Player online?
local player = minetest.get_player_by_name(playername)
chathelp.print(name, hitpoints .. " Hitpoints removed from " .. playername, chathelp.green)
player:set_hp(player:get_hp() - hitpoints) -- Add Hitpoints
chathelp.print(name, name .. " has removed " .. hitpoints .. " Hitpoints from " .. playername, chathelp.log)
else
chathelp.print(name, "Player " .. playername .. " isn't online.", chathelp.red)
end -- if(is_online
end -- chathelp.sub_hp()
-- Trims a String
function chathelp.trim(myString)
return (string.gsub(myString, "^%s*(.-)%s*$", "%1"))
end -- chathelp.trim()
-- Writes a Message in a specific color or Logs it
function chathelp.print(name, message, color)
error = error or chathelp.none -- No Error given, set it to 99 (none)
-- Logs a Message
if(color == chathelp.log) then
minetest.log("action","[CHATHELP] "..name .. " : " .. message)
return
else
if(color ~= chathelp.none) then
minetest.chat_send_player(name, core.colorize(color, message))
return
else
minetest.chat_send_player(name, message)
return
end -- if(error ~=none)
end -- if(error == log)
end -- print_message()
print("[MOD] " .. minetest.get_current_modname() .. " loaded.")