-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.lua
1121 lines (999 loc) · 46.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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
party = {}
mod_storage = minetest.get_mod_storage()
-- =======================
-- === CUSTOM SETTINGS ===
-- =======================
PARTY_TAG_COLOUR = "lightgrey" -- default colour of party tags
PARTY_PARTY_NAME_LENGTH = 8 -- max length for party name/ tag
PARTY_PARTY_JOIN_MODE = "" -- default join mode for parties <<< empty(open)/ active / request / private >>>
PARTY_SQUAD_NAME_LENGTH = 8 -- max length for squad name/ tag
PARTY_SQUAD_JOIN_MODE = "" -- default join mode for squads <<< empty(open) / private >>>
PARTY_IRC_HIDE = "false" -- if "true" and irc mod is active, party and squad messages are NOT sent to the irc channel. NOTE if true, comment out these few lines; https://github.com/minetest-mods/irc/blob/master/callback.lua#L22-L35 on the irc mod, else there will be double messages.
-- =======================
-- ===== PLAYER LIST =====
-- =======================
-- add new players to the mod storage playerlist - thanks to Amaz
minetest.register_on_newplayer(function(newplayer)
local player_list_l = mod_storage:get_string("playerlist")
if player_list_l == "" then
player_list_t = {}
else player_list_t = minetest.deserialize(player_list_l)
end
player_list_t[#player_list_t+1] = newplayer:get_player_name()
local player_list_s = minetest.serialize(player_list_t)
mod_storage:set_string("playerlist", player_list_s)
end)
-- check if old players are in the playerlist, if not, add them to the list
minetest.register_on_joinplayer(function(player)
local player_list_l = mod_storage:get_string("playerlist")
local name = player:get_player_name()
if player_list_l == "" then
player_list_lt = {}
else player_list_lt = minetest.deserialize(player_list_l)
end
for _,playernames in ipairs(player_list_lt) do
if name == playernames then
return
end
end
if player_list_l == "" then
player_list_e = {}
else player_list_e = minetest.deserialize(player_list_l)
end
player_list_e[#player_list_e+1] = player:get_player_name()
local player_list_s = minetest.serialize(player_list_e)
mod_storage:set_string("playerlist", player_list_s)
end)
-- =======================
-- ======= HELPERS =======
-- =======================
-- group notice
party.send_notice_all = function(name, message)
for _,players in ipairs(minetest.get_connected_players()) do
local names = players:get_player_name()
if mod_storage:get_string(name.."_party") == mod_storage:get_string(names.."_party") then
minetest.chat_send_player(names, minetest.colorize("limegreen", "[Party] = PARTY-NOTICE = ")..""..message)
end
end
end
-- private notice
party.send_notice = function(name, message)
minetest.chat_send_player(name, minetest.colorize("limegreen", "[Party] = NOTICE = ")..""..message)
end
-- chat spy for admins
minetest.register_privilege("pspy", "")
party.chat_spy = function(name, message)
for _,players in ipairs(minetest.get_connected_players()) do
local names = players:get_player_name()
if minetest.check_player_privs(names, {pspy=true}) then
local cparty = mod_storage:get_string(name.."_party")
local csquad = mod_storage:get_string(name.."_squad")
if cparty ~= "" then
if cparty ~= mod_storage:get_string(names.."_party") then
minetest.chat_send_player(names, minetest.colorize("yellow", "[SPY]").." [PARTY:"..mod_storage:get_string(cparty.."_leader").."] <"..name.."> "..message)
elseif cparty == mod_storage:get_string(names.."_party") and csquad ~= mod_storage:get_string(names.."_squad") then
minetest.chat_send_player(names, minetest.colorize("yellow", "[SPY]").." [PARTY:"..mod_storage:get_string(cparty.."_leader").."] [SQUAD:"..csquad.."] <"..name.."> "..message)
end
end
end
end
end
-- check if player is in a party [1], officer or leader [2], leader [3]
-- if not then return true
party.check = function(name, level)
local player = minetest.get_player_by_name(name)
local cparty = mod_storage:get_string(name.."_party")
if level == 1 and cparty == "" then
party.send_notice(name, "You are not in a party!")
return true
elseif level == 2 then
if cparty == "" then
party.send_notice(name, "You are not in a party!")
return true
elseif cparty ~= "" then
local cparty_l = mod_storage:get_string(name.."_leader")
local cparty_o = mod_storage:get_string(name.."_officer")
if cparty_o == "" and cparty_l == "" then
party.send_notice(name, "Not authorized to use this command! You are neither the party leader nor an officer of this party!")
return true
end
end
elseif level == 3 then
local cparty_l = mod_storage:get_string(name.."_leader")
if cparty == "" then
party.send_notice(name, "You are not in a party!")
return true
elseif cparty ~= "" and cparty_l == "" then
party.send_notice(name, "Not authorized to use this command! You are not the party leader!")
return true
end
else
return false
end
end
-- check if party name exists
-- if it exists, return true
party.check_tag = function(name, tag)
local player_list = minetest.deserialize(mod_storage:get_string("playerlist"))
for _,playernames in ipairs(player_list) do
if tag == mod_storage:get_string(playernames.."_leader") then
return true
end
end
end
-- =======================
-- ====== LOAD FILES =====
-- =======================
dofile(minetest.get_modpath("party").."/squad.lua")
-- =======================
-- ===== MORE HELPERS ====
-- =======================
party.join = function(name, partyname)
local cparty_l = mod_storage:get_string(partyname.."_leader")
local player = minetest.get_player_by_name(name)
mod_storage:set_string(name.."_party", partyname)
player:set_attribute("partyinvite", nil)
player:set_attribute("partypending", nil)
local tcolour = mod_storage:get_string(partyname.."_colour")
if tcolour == "" then
tcolour = PARTY_TAG_COLOUR
end
player:set_nametag_attributes({text = minetest.colorize(tcolour, "["..cparty_l.."]").." "..name})
party.send_notice_all(name, name.." has joined "..partyname.."'s party ["..cparty_l.."].")
player:set_attribute("partychat", "party")
end
party.leave = function(name)
local player = minetest.get_player_by_name(name)
local csquad = mod_storage:get_string(name.."_squad")
if csquad ~= "" then
squad.leave(name)
end
mod_storage:set_string(name.."_party", nil)
mod_storage:set_string(name.."_officer", nil)
mod_storage:set_string(name.."_leader", nil)
mod_storage:set_string(name.."_lock", nil)
mod_storage:set_string(name.."_title", nil)
mod_storage:set_string(name.."_home", nil)
mod_storage:set_string(name.."_colour", nil)
player:set_nametag_attributes({text = name})
player:set_attribute("partychat", "main")
end
minetest.register_chatcommand("p", {
description = "Create and join a party. For help, use /p help",
privs = {shout=true},
func = function(name, param)
local paramlist = {}
local index = 1
for param_split in param:gmatch("%S+") do
paramlist[index] = param_split
index = index + 1
end
local param1 = paramlist[1]
local param2 = paramlist[2]
local param3 = paramlist[3]
local player = minetest.get_player_by_name(name)
local cparty = mod_storage:get_string(name.."_party")
local cparty_o = mod_storage:get_string(name.."_officer")
local player_list = minetest.deserialize(mod_storage:get_string("playerlist"))
if param1 == "help" then
party.send_notice(name, minetest.colorize("cyan", "@<message>").." --- Send message to global chat (if you are in a party).")
party.send_notice(name, minetest.colorize("cyan", "/p").." --- List your current party.")
party.send_notice(name, minetest.colorize("cyan", "/p list").." --- List online members of your party.")
party.send_notice(name, minetest.colorize("cyan", "/p list all").." --- List all members of your party.")
party.send_notice(name, minetest.colorize("cyan", "/p list <playername>").." --- List party and squad of a player.")
party.send_notice(name, minetest.colorize("cyan", "/p partylist").." --- Gives full list of parties created.")
party.send_notice(name, minetest.colorize("cyan", "/p create <partyname>").." --- Create a party.")
party.send_notice(name, minetest.colorize("cyan", "/p join <partyname>").." --- Join a party.")
party.send_notice(name, minetest.colorize("cyan", "/p leave").." --- Leave your party.")
party.send_notice(name, minetest.colorize("cyan", "/p home").." --- Teleport to your party home (if your leader has one set).")
party.send_notice(name, minetest.colorize("cyan", "/p chat <main/party/squad>").." --- Switch your chat input. Leave empty to get your current chat input.")
party.send_notice(name, minetest.colorize("cyan", "/p invite <yes/no>").." --- Accept/ reject a party invite.")
party.send_notice(name, minetest.colorize("cyan", "/p noinvite").." --- Toggle noinvites, if on, reject all parties invites automatically.")
party.send_notice(name, minetest.colorize("cyan", "/p pvp").." --- Toggle friendly fire, if two players have friendly fire enabled even though they are in the same party, they can fight.")
party.send_notice(name, " ===== PARTY OFFICERS/ PARTY LEADER COMMANDS: ===== ")
party.send_notice(name, minetest.colorize("cyan", "/p kick <playername>").." --- Kick a player out of your party.")
party.send_notice(name, minetest.colorize("cyan", "/p invite <playername>").." --- Invite a player to join your party.")
party.send_notice(name, minetest.colorize("cyan", "/p <accept/reject> <playername>").." --- Accept/ reject a join request (if joining method is set to [Request Mode]).")
party.send_notice(name, " ===== PARTY LEADER-ONLY COMMANDS: ===== ")
party.send_notice(name, minetest.colorize("cyan", "/p disband").." --- Disband your party.")
party.send_notice(name, minetest.colorize("cyan", "/p rename <new_partyname>").." --- Rename your party.")
party.send_notice(name, minetest.colorize("cyan", "/p sethome").." --- Set your party home.")
party.send_notice(name, minetest.colorize("cyan", "/p sethome remove").." --- Remove your party home.")
party.send_notice(name, minetest.colorize("cyan", "/p colour <colour>").." --- Set the colour of your party tag.")
party.send_notice(name, minetest.colorize("cyan", "/p officer <playername>").." --- Toogle a player's officer position. Officers can kick & invite.")
party.send_notice(name, minetest.colorize("cyan", "/p lock <open/active/request/private>").." --- Toggle joining method for your party.")
party.send_notice(name, minetest.colorize("cyan", "/p title <playername> <title>").." --- Adds a title to a player in party chat.")
party.send_notice(name, " ===== ADMIN COMMANDS: ===== ")
party.send_notice(name, minetest.colorize("cyan", "/p forcedisband <partyname>").." --- Forcefully disband a party (requires 'ban' privilege).")
party.send_notice(name, minetest.colorize("cyan", "/p forcejoin <partyname>").." --- Forcefully let yourself in a party regardless of its lock mode (requires 'ban' privilege).")
party.send_notice(name, minetest.colorize("cyan", "/p forcekick <playername>").." --- Forcefully kick a player from a party (requires 'kick' privilege).")
-- TODO
-- formspecs equivalents
-- party.send_notice(name, "/p ally/enemy/neutral <partyname> --- Toggle diplomacy status with another party. Allied parties will have no friendly fire and there will be ally chat.")
-- party.send_notice(name, "/p ally list --- Ally list.")
-- party.send_notice(name, "/p enemy list --- Enemies list.")
-- party.send_notice(name, "/p motd --- Adds a motd. Player receive this message when they join the game / party. ")
-- =======================
-- === GENERAL COMMANDS ==
-- =======================
elseif param1 == nil then
if party.check(name, 1) == true then
return
end
local cparty_l = mod_storage:get_string(cparty.."_leader")
party.send_notice(name, "You are currently in "..cparty.."'s party ["..cparty_l.."].")
elseif param1 == "list" then
if param2 == "all" then
if party.check(name, 1) == true then
return
end
local listnames = ""
local cparty_l = mod_storage:get_string(cparty.."_leader")
party.send_notice(name, "Full member list of "..cparty.."'s party ["..cparty_l.."]:")
for _,playernames in ipairs(player_list) do
if cparty == mod_storage:get_string(playernames.."_party") then
listnames = listnames .. playernames .. ", "
end
end
party.send_notice(name, listnames)
elseif param2 == "officer" then
if party.check(name, 1) == true then
return
end
local listnames = ""
local cparty_l = mod_storage:get_string(cparty.."_leader")
party.send_notice(name, "List of "..cparty.."'s party ["..cparty_l.."] officers:")
for _,playernames in ipairs(player_list) do
if cparty == mod_storage:get_string(playernames.."_party") then
if mod_storage:get_string(playernames.."_officer") ~= "" or mod_storage:get_string(playernames.."_leader") ~= "" then
listnames = listnames .. playernames .. ", "
end
end
end
party.send_notice(name, listnames)
elseif param2 == nil then
if party.check(name, 1) == true then
return
end
local listnames = ""
local cparty_l = mod_storage:get_string(cparty.."_leader")
party.send_notice(name, "Online member list of "..cparty.."'s party ["..cparty_l.."]:")
for _,players in ipairs(minetest.get_connected_players()) do
local playernames = players:get_player_name()
if cparty == mod_storage:get_string(playernames.."_party") then
listnames = listnames .. playernames .. ", "
end
end
party.send_notice(name, listnames)
elseif param2 ~= nil then
if minetest.player_exists(param2) then
local cparty = mod_storage:get_string(param2.."_party")
if cparty ~= "" and cparty ~= "@" and cparty ~= "#" and cparty ~= "+" and cparty ~= "=" then
local csquad = mod_storage:get_string(param2.."_squad")
local cparty_l = mod_storage:get_string(cparty.."_leader")
if param2 ~= cparty and csquad == "" then
party.send_notice(name, param2.." is currently in "..cparty.."'s party ["..cparty_l.."].")
elseif param2 ~= cparty and csquad ~= "" then
party.send_notice(name, param2.." is currently in "..cparty.."'s party ["..cparty_l.."] and under the ["..csquad.."] squad.")
elseif param2 == cparty and csquad == "" then
party.send_notice(name, param2.." is currently the leader of "..param2.."'s party ["..cparty_l.."].")
elseif param2 == cparty and csquad ~= "" then
party.send_notice(name, param2.." is currently the leader of "..param2.."'s party ["..cparty_l.."] and under the ["..csquad.."] squad.")
end
else party.send_notice(name, param2.." is currently not in any party.")
end
else party.send_notice(name, "Player does not exist!")
end
end
elseif param1 == "partylist" then
local player_list = minetest.deserialize(mod_storage:get_string("playerlist"))
local partylist = ""
for _,playernames in ipairs(player_list) do
local cparty_l = mod_storage:get_string(playernames.."_leader")
if cparty_l ~= "" then
partylist = partylist .. cparty_l .. ", "
end
end
party.send_notice(name, "Full list of parties: ")
party.send_notice(name, partylist)
elseif param1 == "leave" then
if party.check(name, 1) == true then
return
end
local cparty_l = mod_storage:get_string(cparty.."_leader")
if mod_storage:get_string(name.."_leader") == "" then
party.send_notice_all(name, name.." left "..cparty.."'s party ["..cparty_l.."].")
party.leave(name)
else party.send_notice(name, "You cannot leave your own party! Use /p disband instead.")
end
elseif param1 == "create" and param2 ~= nil then
if string.len(param2) > PARTY_PARTY_NAME_LENGTH then
party.send_notice(name, "Nametag is too long! "..PARTY_PARTY_NAME_LENGTH.." is the maximum amount of characters")
return
end
-- check if tag exists
if party.check_tag(name, param2) == true then
party.send_notice(name, "Party name selected already exists. Please choose another one.")
return
end
if cparty == "" then
mod_storage:set_string(name.."_party", name)
mod_storage:set_string(name.."_leader", param2)
mod_storage:set_string(name.."_lock", PARTY_PARTY_JOIN_MODE)
player:set_attribute("partyinvite", nil)
player:set_attribute("partychat", "party")
local tcolour = mod_storage:get_string(name.."_colour")
if tcolour == "" then
tcolour = PARTY_TAG_COLOUR
end
player:set_nametag_attributes({text = minetest.colorize(tcolour, "["..param2.."]").." "..name})
party.send_notice(name, "You created "..name.."'s party ["..param2.."].")
else
local cparty_l = mod_storage:get_string(cparty.."_leader")
party.send_notice(name, "You are already in "..cparty.."'s party ["..cparty_l.."].")
end
-- /p join
elseif param1 == "join" and param2 ~= nil then
if cparty ~= "" then
local cparty_l = mod_storage:get_string(cparty.."_leader")
party.send_notice(name, "You are already in "..cparty.."'s party ["..cparty_l.."].")
return
end
if party.check_tag(name, param2) == true then
local leadername = ""
for _,playernames in ipairs(player_list) do
if param2 == mod_storage:get_string(playernames.."_leader") then
leadername = leadername .. playernames
end
end
local cparty = leadername
local party_m = mod_storage:get_string(cparty.."_lock")
-- active mode, only allow if leader is active
if party_m == "active" then
if minetest.get_player_by_name(cparty) == nil then
party.send_notice(name, "Party leader is offline, try again when the party leader is online!")
else party.join(name, cparty)
end
-- request mode, sends a request if officer/leader are online
elseif party_m == "request" then
if player:get_attribute("partypending") ~= nil then
party.send_notice(name, "You have already requested to join another party. Only one join request is allowed to prevent spamming.")
party.send_notice(name, "Please rejoin the game if you want to make an different request.")
return
end
for _,players in ipairs(minetest.get_connected_players()) do
local names = players:get_player_name()
if cparty == mod_storage:get_string(names.."_party") then
if mod_storage:get_string(names.."_officer") ~= "" or mod_storage:get_string(names.."_leader") ~= "" then
local off_names = players:get_player_name()
party.send_notice(off_names, name.." has requested to join the party. Use '/p accept <playername>' to accept, '/p reject <playername>' to reject.")
end
end
end
party.send_notice(name, "Your request to join "..cparty.."'s party ["..param2.."] has been sent.")
party.send_notice(name, "Pending approval from an officer/leader. If you do not receive a reply soon, it is likely there's no one online to review your request.")
party.send_notice(name, "Please do not leave the game, your join request will be rendered void if you do so.")
player:set_attribute("partypending", cparty)
-- private mode, denies all requests
elseif party_m == "private" then
party.send_notice(name, "Party is private! Public join requests are denied!")
-- public mode, accept all requests
else party.join(name, cparty)
end
else party.send_notice(name, "Party does not exist!")
end
-- /p home
elseif param1 == "home" then
if party.check(name, 1) == true then
return
end
local cparty_home = mod_storage:get_string(cparty.."_home")
if cparty_home ~= "" then
party.send_notice(name, "Teleporting to party home...")
player:set_pos(minetest.deserialize(cparty_home))
else party.send_notice(name, "Party home is not set by leader!")
end
elseif param1 == "chat" then
if party.check(name, 1) == true then
return
end
if (param2 == "main" or param2 == "global") then
player:set_attribute("partychat", "main")
party.send_notice(name, "Chat input set to main chat.")
elseif param2 == "party" then
player:set_attribute("partychat", "party")
party.send_notice(name, "Chat input set to party chat.")
elseif param2 == "squad" then
if mod_storage:get_string(name.."_squad") == "" then
party.send_notice(name, "You are not in a squad!")
return
end
player:set_attribute("partychat", "squad")
party.send_notice(name, "Chat input set to squad chat.")
elseif param2 == nil then
party.send_notice(name, "Current chat input is set to "..player:get_attribute("partychat").." chat.")
end
-- /p noinvite
elseif param1 == "noinvite" then
if cparty == "" then
if player:get_attribute("partynoinvite") == "true" then
player:set_attribute("partynoinvite", nil)
party.send_notice(name, "You have disabled noinvite - You will now receive party invites.")
elseif player:get_attribute("partynoinvite") == nil then
player:set_attribute("partyinvite", nil)
player:set_attribute("partynoinvite", "true")
party.send_notice(name, "You have enabled noinvite - You will now NOT receive party invites.")
end
else party.send_notice(name, "You are already in a party! Invites wouldn't be received when you are in a party!")
end
-- /p pvp
elseif param1 == "pvp" then
if player:get_attribute("partypvp") == "true" then
player:set_attribute("partypvp", nil)
party.send_notice(name, "NO friendly fire is ENABLED.")
elseif player:get_attribute("partypvp") == nil then
player:set_attribute("partypvp", "true")
party.send_notice(name, "Friendly fire is ENABLED.")
end
-- =======================
-- = LEADERSHIP COMMANDS =
-- =======================
-- /p disband
elseif param1 == "disband" then
if party.check(name, 3) == true then
return
end
if cparty == name then
party.send_notice_all(name, name.."'s party ["..mod_storage:get_string(name.."_leader").."] has been disbanded.")
-- remove online players
for _,players in ipairs(minetest.get_connected_players()) do
local names = players:get_player_name()
if mod_storage:get_string(names.."_party") == cparty then
party.leave(names)
end
end
-- mark offline players so they would be notified when they login
for _,playernames in ipairs(player_list) do
if minetest.get_player_by_name(playernames) == nil then
if mod_storage:get_string(playernames.."_party") == cparty then
mod_storage:set_string(playernames.."_party", "@")
-- open up the alliance name for taking
mod_storage:set_string(playernames.."_officer", nil)
mod_storage:set_string(playernames.."_leader", nil)
mod_storage:set_string(playernames.."_lock", nil)
mod_storage:set_string(playernames.."_title", nil)
end
end
end
-- remove leader's powers
mod_storage:set_string(name.."_party", nil)
mod_storage:set_string(name.."_leader", nil)
mod_storage:set_string(name.."_lock", nil)
mod_storage:set_string(name.."_colour", nil)
mod_storage:set_string(name.."_title", nil)
mod_storage:set_string(name.."_home", nil)
player:set_nametag_attributes({text = name})
end
elseif param1 == "rename" and param2 ~= nil then
if party.check(name, 3) == true then
return
end
-- check if new name is too long
if string.len(param2) > PARTY_PARTY_NAME_LENGTH then
party.send_notice(name, "Nametag is too long! "..PARTY_PARTY_NAME_LENGTH.." is the maximum amount of characters")
return
end
if party.check_tag(name, param2) == true then
party.send_notice(name, "Party name selected already exists. Please choose another one.")
return
end
-- if not, apply rename
mod_storage:set_string(name.."_leader", param2)
party.send_notice_all(name, name.." renamed the party tag to ["..param2.."].")
-- update online player nametags
local tcolour = mod_storage:get_string(name.."_colour")
if tcolour == "" then
tcolour = PARTY_TAG_COLOUR
end
for _,players in ipairs(minetest.get_connected_players()) do
local names = players:get_player_name()
local csquad = mod_storage:get_string(names.."_squad")
if mod_storage:get_string(names.."_party") == cparty and csquad == "" then
players:set_nametag_attributes({text = minetest.colorize(tcolour, "["..param2.."]").." "..names})
elseif mod_storage:get_string(names.."_party") == cparty and csquad ~= "" then
players:set_nametag_attributes({text = minetest.colorize(tcolour, "["..param2.."-"..csquad.."]").." "..names})
end
end
elseif param1 == "colour" and param2 ~= nil then
if party.check(name, 3) == true then
return
end
party.send_notice(name, "Party tag colour is set to "..minetest.colorize(param2, param2)..".")
mod_storage:set_string(name.."_colour", param2)
-- update online player nametags
local cparty_l = mod_storage:get_string(cparty.."_leader")
local tcolour = mod_storage:get_string(cparty.."_colour")
if tcolour == "" then
tcolour = PARTY_TAG_COLOUR
end
for _,players in ipairs(minetest.get_connected_players()) do
local names = players:get_player_name()
local csquad = mod_storage:get_string(names.."_squad")
if mod_storage:get_string(names.."_party") == cparty and csquad == "" then
players:set_nametag_attributes({text = minetest.colorize(tcolour, "["..cparty_l.."]").." "..names})
elseif mod_storage:get_string(names.."_party") == cparty and csquad ~= "" then
players:set_nametag_attributes({text = minetest.colorize(tcolour, "["..cparty_l.."-"..csquad.."]").." "..names})
end
end
elseif param1 == "lock" then
if party.check(name, 3) == true then
return
end
local cparty_l = mod_storage:get_string(name.."_leader")
if param2 == "active" then
mod_storage:set_string(name.."_lock", param2)
party.send_notice_all(name, "[Active mode] Public joining (Only if leader is online) is enabled for "..name.."'s party ["..cparty_l.."].")
elseif param2 == "request" then
mod_storage:set_string(name.."_lock", param2)
party.send_notice_all(name, "[Request mode] Join requests is enabled for "..name.."'s party ["..cparty_l.."].")
elseif param2 == "private" then
mod_storage:set_string(name.."_lock", param2)
party.send_notice_all(name, "[Private mode] Public joining is disabled for "..name.."'s party ["..cparty_l.."].")
elseif param2 == "open" then
mod_storage:set_string(name.."_lock", nil)
party.send_notice_all(name, "[Open mode] Public joining is enabled for "..name.."'s party ["..cparty_l.."].")
end
elseif param1 == "sethome" then
if party.check(name, 3) == true then
return
end
if param2 == "remove" then
mod_storage:set_string(cparty.."_home", nil)
party.send_notice(name, "Party home removed!")
else
mod_storage:set_string(cparty.."_home", minetest.serialize(player:get_pos()))
party.send_notice(name, "Party home has been set to "..minetest.serialize(player:get_pos()))
end
-- /p officer
elseif param1 == "officer" and param2 ~= nil then
if party.check(name, 3) == true then
return
end
local cparty_l = mod_storage:get_string(name.."_leader")
if minetest.player_exists(param2) then
local target_party = mod_storage:get_string(param2.."_party")
-- if player is not in same party
if target_party ~= cparty then
party.send_notice(name, "Player "..param2.." does not exist or is not in your party! Case sensitive.")
return
-- if player is in same party then promote/demote accordingly
elseif target_party == cparty then
local target_status = mod_storage:get_string(param2.."_officer")
if target_status == "" then
mod_storage:set_string(param2.."_officer", "true")
party.send_notice_all(name, param2.." has been promoted to an officer!")
elseif target_status ~= "" then
mod_storage:set_string(param2.."_officer", nil)
party.send_notice_all(name, param2.." has been demoted to a member.")
end
end
else party.send_notice(name, "Player "..param2.." does not exist! Case sensitive.")
end
elseif param1 == "title" and param2 ~= nil and param3 ~= nil then
if party.check(name, 3) == true then
return
end
if minetest.player_exists(param2) then
if cparty ~= mod_storage:get_string(param2.."_party") then
party.send_notice(name, "Player "..param2.." is not in your party!")
return
end
if (param3 == "remove" or param3 == "nil") then
mod_storage:set_string(param2.."_title",nil)
party.send_notice(name, "Player "..param2.."'s title has been removed")
else
mod_storage:set_string(param2.."_title",param3)
party.send_notice(name, "Player "..param2.."'s title has been set to "..param3)
end
end
-- /p kick
elseif param1 == "kick" and param2 ~= nil then
if party.check(name, 2) == true then
return
end
if minetest.player_exists(param2) then
local cparty = mod_storage:get_string(param2.."_party")
local self_cparty = mod_storage:get_string(name.."_party")
-- attempt to kick self
if param2 == name then
party.send_notice(name, "You can't kick yourself!")
return
-- attempt to kick someone not from your party
elseif self_cparty ~= cparty then
party.send_notice(name, "Player "..param2.." does not exist or is not in your party! Case sensitive.")
return
-- attempt to kick leader
elseif param2 == cparty then
party.send_notice(name, "You can't kick the leader!")
party.send_notice_all(name, name.." attempted to kick the leader.")
return
-- attempt to kick fellow officer (if officer too)
elseif mod_storage:get_string(name.."_officer") ~= "" and mod_storage:get_string(param2.."_officer") ~= "" then
party.send_notice(name, "You can't kick a fellow officer!")
party.send_notice_all(name, name.." attempted to kick a fellow officer.")
return
end
-- kicking offline player, give a mark to notify player when he logins
if minetest.get_player_by_name(param2) == nil then
party.send_notice_all(name, param2.."[offline] was kicked from "..cparty.."'s party ["..mod_storage:get_string(cparty.."_leader").."] by "..name)
mod_storage:set_string(param2.."_party", "#")
mod_storage:set_string(param2.."_officer", nil)
end
-- kicking online player
if minetest.get_player_by_name(param2) ~= nil then
party.send_notice_all(name, param2.." was kicked from "..cparty.."'s party ["..mod_storage:get_string(cparty.."_leader").."] by "..name)
party.leave(param2)
end
-- if player doesn't exist
else party.send_notice(name, "Player "..param2.." does not exist! Case sensitive.")
end
-- Accept/reject join request
elseif (param1 == "accept" or param1 == "reject") and param2 ~= nil then
if party.check(name, 2) == true then
return
end
if minetest.player_exists(param2) then
-- Reject if player is not online
if minetest.get_player_by_name(param2) == nil then
party.send_notice(name, "Player "..param2.." is not online right now.")
return
end
local target_party = mod_storage:get_string(param2.."_party")
-- Reject if player did not request to join the party
if minetest.get_player_by_name(param2):get_attribute("partypending") ~= cparty then
party.send_notice(name, "Player "..param2.." did not request to join the party!")
return
-- Reject if player is already in a party
elseif target_party ~= "" then
party.send_notice(name, "Player "..param2.." is already in a party!")
return
end
local t_player = minetest.get_player_by_name(param2)
local cparty_l = mod_storage:get_string(cparty.."_leader")
if param1 == "accept" then
t_player:set_attribute("partypending", nil)
party.send_notice(param2, "Your request to join "..cparty.." ["..cparty_l.."] has been accepted!")
party.join(param2, cparty)
elseif param1 == "reject" then
t_player:set_attribute("partypending", nil)
party.send_notice(param2, "Your request to join "..cparty.." ["..cparty_l.."] was denied.")
party.send_notice(name, "You have denied "..param2.."'s request.")
end
else party.send_notice(name, "Player "..param2.." does not exist!")
end
elseif param1 == "invite" and param2 ~= nil then
if cparty ~= "" then
if party.check(name, 2) == true then
return
end
if minetest.player_exists(param2) then
-- reject if player is not online
local target_party = mod_storage:get_string(param2.."_party")
local t_player = minetest.get_player_by_name(param2)
if minetest.get_player_by_name(param2) == nil then
party.send_notice(name, "Player is not online!")
return
-- reject if player is already in a party
elseif target_party ~= "" then
party.send_notice(name, "Player is already in a party!")
return
-- reject if player disabled invites
elseif t_player:get_attribute("partynoinvite") == "true" then
party.send_notice(name, "Player has disabled invites!")
return
end
local cparty_l = mod_storage:get_string(cparty.."_leader")
t_player:set_attribute("partyinvite", name)
party.send_notice(param2, name.." has invited you to "..cparty.."'s party ["..cparty_l.."]! '/p invite yes' to accept or '/p invite no' to decline.")
party.send_notice(name, "You have invited "..param2.." to your party. Awaiting for their response.")
-- player does not exist
else party.send_notice(name, "Player "..param2.." does not exist! Case sensitive.")
end
elseif cparty == "" and param2 == "no" then
if player:get_attribute("partyinvite") ~= nil then
local iname = player:get_attribute("partyinvite")
local iparty = mod_storage:get_string(iname.."_party")
local iparty_l = mod_storage:get_string(iparty.."_leader")
player:set_attribute("partyinvite", nil)
party.send_notice(name, "You have rejected "..iname.."'s invite to join "..iparty.."'s party ["..iparty_l.."].")
-- if player that sent request is online, send him a message.
if minetest.get_player_by_name(iname) ~= nil then
party.send_notice(iname, name.." has denied your invite request.")
end
else party.send_notice(name, "You have not received an invite!")
end
elseif cparty == "" and param2 == "yes" then
if player:get_attribute("partyinvite") ~= nil then
local iname = player:get_attribute("partyinvite")
local iparty = mod_storage:get_string(iname.."_party")
local iparty_l = mod_storage:get_string(iparty.."_leader")
-- if player that sent request is online, send him a message.
if minetest.get_player_by_name(iparty) ~= nil then
party.send_notice(iname, name.." has accepted your invite request.")
end
player:set_attribute("partyinvite", nil)
party.join(name, iparty)
else party.send_notice(name, "You have not received an invite!")
end
else party.send_notice(name, "You are not in a party!")
end
-- =======================
-- ==== ADMIN COMMANDS ===
-- =======================
elseif param1 == "forcedisband" and param2 ~= nil then
if not minetest.check_player_privs(name, {ban=true}) then
party.send_notice(name, "You are not an admin!")
return
end
if party.check_tag(name, param2) == true then
local leadername = ""
for _,playernames in ipairs(player_list) do
if param2 == mod_storage:get_string(playernames.."_leader") then
leadername = leadername .. playernames
end
end
local cparty = leadername
party.send_notice(name, "You have disbanded "..leadername.."'s party ["..param2.."]")
party.send_notice_all(leadername, leadername.."'s party ["..mod_storage:get_string(leadername.."_leader").."] has been disbanded by "..name..", an admin")
-- remove online players
for _,players in ipairs(minetest.get_connected_players()) do
local names = players:get_player_name()
if mod_storage:get_string(names.."_party") == cparty then
party.leave(names)
end
end
-- mark offline players so they would be notified when they login
for _,playernames in ipairs(player_list) do
if minetest.get_player_by_name(playernames) == nil then
if mod_storage:get_string(playernames.."_party") == cparty then
mod_storage:set_string(playernames.."_party", "=")
-- open up the alliance name for taking
mod_storage:set_string(playernames.."_officer", nil)
mod_storage:set_string(playernames.."_leader", nil)
mod_storage:set_string(playernames.."_lock", nil)
end
end
end
else party.send_notice(name, "Party does not exist!")
end
elseif param1 == "forcejoin" and param2 ~= nil then
if not minetest.check_player_privs(name, {ban=true}) then
party.send_notice(name, "You are not an admin!")
return
end
if cparty ~= "" then
local cparty_l = mod_storage:get_string(cparty.."_leader")
party.send_notice(name, "You are already in "..cparty.."'s party ["..cparty_l.."].")
return
end
if party.check_tag(name, param2) == true then
local leadername = ""
for _,playernames in ipairs(player_list) do
if param2 == mod_storage:get_string(playernames.."_leader") then
leadername = leadername .. playernames
end
end
local cparty = leadername
party.join(name, cparty)
end
elseif param1 == "forcekick" and param2 ~= nil then
if not minetest.check_player_privs(name, {kick=true}) then
party.send_notice(name, "You are not a mod!")
return
end
if minetest.player_exists(param2) then
local cparty = mod_storage:get_string(param2.."_party")
-- attempt to kick self
if param2 == name then
party.send_notice(name, "You can't kick yourself!")
return
-- attempt to kick player that doesn't have a party
elseif cparty == "" then
party.send_notice(name, param2.." is not in a party!")
return
-- attempt to kick leader
elseif mod_storage:get_string(param2.."_leader") ~= "" then
party.send_notice(name, "The leader can't be kicked! Use /p forcedisband instead.")
return
end
-- kicking offline player, give a mark to notify player when he logins
if minetest.get_player_by_name(param2) == nil then
party.send_notice_all(param2, param2.."[offline] was kicked from "..cparty.."'s party ["..mod_storage:get_string(cparty.."_leader").."] by an admin, "..name)
mod_storage:set_string(param2.."_party", "+")
mod_storage:set_string(param2.."_officer", nil)
party.send_notice(name, "Kicked "..param2.."[offline] from "..cparty.."'s party ["..mod_storage:get_string(cparty.."_leader").."]")
else
-- check if online player is a squad leader
if mod_storage:get_string(param2.."_squad_leader") ~= "" then
-- disband squad if so
for _,players in ipairs(minetest.get_connected_players()) do
local names = players:get_player_name()
if mod_storage:get_string(names.."_party") == mod_storage:get_string(param2.."_party") and mod_storage:get_string(names.."_squad") == mod_storage:get_string(param2.."_squad") then
squad.leave(names)
end
end
party.send_notice_all(param2, param2.." was kicked from "..cparty.."'s party ["..mod_storage:get_string(cparty.."_leader").."] by an admin, "..name)
party.send_notice(name, "Kicked "..param2.." from "..cparty.."'s party ["..mod_storage:get_string(cparty.."_leader").."]")
party.leave(param2)
-- if not, normal kick
else
party.send_notice_all(param2, param2.." was kicked from "..cparty.."'s party ["..mod_storage:get_string(cparty.."_leader").."] by an admin, "..name)
party.send_notice(name, "Kicked "..param2.." from "..cparty.."'s party ["..mod_storage:get_string(cparty.."_leader").."]")
party.leave(param2)
end
end
end
else party.send_notice(name, "ERROR: Command is invalid! For help, use the command '/p help'")
end
end,
})
minetest.register_on_chat_message(function(name, message)
local player = minetest.get_player_by_name(name)
local cparty = mod_storage:get_string(name.."_party")
local cparty_title = mod_storage:get_string(name.."_title")
local csquad = mod_storage:get_string(name.."_squad")
local cinput = player:get_attribute("partychat")
-- check if player has shout privs
if not minetest.check_player_privs(name, {shout=true}) then
return
end
-- chat logging
if cparty == "" then
minetest.log("action", "CHAT : <"..name.."> : "..message)
elseif cparty ~= "" then
local cparty_l = mod_storage:get_string(cparty.."_leader")
if string.match(message, "^@(.+)") then
minetest.log("action", "CHAT : <"..name.."> : "..string.gsub(message, "^@", ""))
elseif cinput == "main" then
minetest.log("action", "CHAT : <"..name.."> : "..string.gsub(message, "^@", ""))
else minetest.log("action", "CHAT [PARTY:"..cparty_l.."] : <"..name.."> : "..message)
end
end
for _,players in ipairs(minetest.get_connected_players()) do
local names = players:get_player_name()
-- Main chat
if cparty == "" then
minetest.chat_send_player(names, "<"..name.."> " ..message)
end
-- Main chat (@)
if string.match(message, "^@(.+)") and cparty ~= "" then
local cparty_l = mod_storage:get_string(cparty.."_leader")
minetest.chat_send_player(names, "<Party:"..cparty_l.." | "..name.."> "..string.gsub(message, "^@", ""))
end
-- Main chat (chat input)
if cinput == "main" and cparty ~= "" and not string.match(message, "^@(.+)") then
local cparty_l = mod_storage:get_string(cparty.."_leader")
minetest.chat_send_player(names, "<Party:"..cparty_l.." | "..name.."> "..message)
end
-- Party Chat
if cparty == mod_storage:get_string(names.."_party") and cinput == "party" and not string.match(message, "^@(.+)") then
if cparty_title ~= "" then
minetest.chat_send_player(names, minetest.colorize("limegreen", "[Party]").." <"..minetest.colorize("lightgrey", cparty_title).." "..name.."> " ..message)
elseif cparty_title == "" then
minetest.chat_send_player(names, minetest.colorize("limegreen", "[Party]").." <"..name.."> " ..message)
end
-- Squad chat
elseif cparty == mod_storage:get_string(names.."_party") and csquad == mod_storage:get_string(names.."_squad") and cinput == "squad" and not string.match(message, "^@(.+)") then
if cparty_title ~= "" then
minetest.chat_send_player(names, minetest.colorize("orange", "[Squad]").." <"..minetest.colorize("lightgrey", cparty_title).." "..name.."> " ..message)
elseif cparty_title == "" then
minetest.chat_send_player(names, minetest.colorize("orange", "[Squad]").." <"..name.."> " ..message)