-
Notifications
You must be signed in to change notification settings - Fork 18
/
init.c
1111 lines (879 loc) · 31 KB
/
init.c
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
void main()
{
//INIT WEATHER BEFORE ECONOMY INIT------------------------
Weather weather = g_Game.GetWeather();
weather.MissionWeather(false); // false = use weather controller from Weather.c
weather.GetOvercast().Set( Math.RandomFloatInclusive(0.4, 0.6), 1, 0);
weather.GetRain().Set( 0, 0, 1);
weather.GetFog().Set( Math.RandomFloatInclusive(0.05, 0.1), 1, 0);
//INIT ECONOMY--------------------------------------
Hive ce = CreateHive();
if ( ce )
ce.InitOffline();
//DATE RESET AFTER ECONOMY INIT-------------------------
int year, month, day, hour, minute;
int reset_month = 9, reset_day = 20;
GetGame().GetWorld().GetDate(year, month, day, hour, minute);
if ((month == reset_month) && (day < reset_day))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
else
{
if ((month == reset_month + 1) && (day > reset_day))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
else
{
if ((month < reset_month) || (month > reset_month + 1))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
}
}
}
class CustomMission: MissionServer
{
// SteamIDs of all admin players stored here
private ref TStringArray m_admins;
// Players that have God Mode enabled, listed here
private ref TIntArray m_gods;
// Keep track of internal call queue limit to prevent overloads
private int m_calls;
// Limit the number of function calls
// TODO: figure out proper limit when the performance starts to degrade
// TODO make constant
private int CALLS_LIMIT;
override void OnInit()
{
super.OnInit();
// Initialize needed class members here
m_calls = 0;
CALLS_LIMIT = 50;
m_admins = new TStringArray;
m_gods = new TIntArray;
LoadAdmins();
}
void LoadAdmins()
{
string path = "$profile:admins.txt";
FileHandle file = OpenFile(path, FileMode.READ);
// If file doesnt exist, create it
if ( file == 0 ) {
file = OpenFile(path, FileMode.WRITE);
FPrintln(file, "// This file contains SteamID64 of all server admins. Add them below.");
FPrintln(file, "// Line starting with // means a comment line.");
CloseFile(file);
return;
}
string line;
while ( FGets( file, line ) > 0 )
{
if (line.Length() < 2) continue;
if (line.Get(0) + line.Get(1) == "//") continue;
m_admins.Insert(line);
}
CloseFile(file);
}
bool Command(PlayerBase player, string command)
{
const string helpMsg = "Available commands: /help /car /warp /kill /give /gear /ammo /say /info /heal /god /suicide /here /there";
// Split command message into args
TStringArray args = new TStringArray;
MySplit(command, " ", args);
string arg;
PlayerBase target;
int dist;
switch (args[0])
{
case "/car":
if ( args.Count() != 2 ) {
SendPlayerMessage(player, "Syntax: /car [TYPE] - Spawn a vehicle");
SpawnCar(player, "help");
return false;
}
SpawnCar(player, args[1]);
break;
case "/warp":
if ( args.Count() < 3 ) {
SendPlayerMessage(player, "Syntax: /warp [X] [Z] - Teleport to [X, Z]");
return false;
}
string pos = args[1] + " " + "0" + " " + args[2];
SafeSetPos(player, pos);
SendPlayerMessage(player, "Teleported to: " + pos);
break;
case "/heal":
if ( args.Count() != 1 ) {
SendPlayerMessage(player, "Syntax: /heal - Set all health statuses to max");
return false;
}
RestoreHealth(player);
break;
case "/gear":
if ( args.Count() != 2 ) {
SendPlayerMessage(player, "Syntax: /gear [TYPE] - Spawn item loadout to self");
SpawnGear(player, "help");
return false;
}
if (SpawnGear(player, args[1])) {
SendPlayerMessage(player, "Gear spawned.");
}
break;
case "/ammo":
// Args count: 2 <= x <= 3
if ( args.Count() < 2 || args.Count() > 3 ) {
SendPlayerMessage(player, "Syntax: /ammo [FOR_WEAPON] (AMOUNT) - Spawn mags and ammo for weapon");
SpawnAmmo(player, "help");
return false;
}
if ( args.Count() == 3 && SpawnAmmo(player, args[1], args[2].ToInt()) ) {
SendPlayerMessage(player, "Ammo spawned.");
}
else if ( args.Count() == 2 && SpawnAmmo(player, args[1]) ) {
SendPlayerMessage(player, "Ammo spawned.");
}
break;
case "/info":
if ( args.Count() < 1 || args.Count() > 2 ) {
SendPlayerMessage(player, "Syntax: /info (0/1) - Get information about players on the server or set continuous info on/off");
return false;
}
if (args.Count() == 2) {
arg = args[1];
arg.ToLower();
if (arg.ToInt() == 1) {
GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(this.PlayerInfo, 20000, true, player);
SendPlayerMessage(player, "Continuous info mode enabled.");
break;
}
else if (arg.ToInt() == 0) {
GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Remove(this.PlayerInfo);
SendPlayerMessage(player, "Continuous info mode disabled.");
}
}
else {
PlayerInfo(player);
}
break;
case "/say":
if ( args.Count() < 2 ) {
SendPlayerMessage(player, "Syntax: /say [MESSAGE] - Global announcement to all players");
return false;
}
// Form the message string from the command text and send to all players
string msg = command.Substring( 5, command.Length() - 5 );
SendGlobalMessage(msg);
break;
case "/spawn":
return false;
case "/god":
if ( args.Count() != 2 ) {
SendPlayerMessage(player, "Syntax: /god [0-1] - Enable or disable semi god mode (BEWARE: huge damage in short timespan can still kill you!)");
return false;
}
int setGod = args[1].ToInt();
int pId = player.GetID();
// Add player to gods, call godmode function every 1 sec
if (setGod == 1) {
if ( m_gods.Find(pId) != -1 ) {
SendPlayerMessage(player, "You are already god.");
return false;
}
// Here we only need to add the new call to queue
// However make sure we are within safe limits
// TODO: Figure out more robust system to ensure performance does not degrade over time
if (m_calls < CALLS_LIMIT) {
m_gods.Insert( pId );
GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(this.GodMode, 1000, true, player);
m_calls += 1;
SendPlayerMessage(player, "God mode enabled.");
} else {
SendPlayerMessage(player, "ERROR: Call queue limit reached. Please try again later.");
}
}
// Do vice versa except for other gods
else if (setGod == 0) {
// Remove player id from gods list if found
int godIdx = m_gods.Find( pId );
if (godIdx == -1) {
SendPlayerMessage(player, "God mode not currently enabled for player.");
return false;
}
else {
m_gods.Remove(godIdx);
}
// The problem is we cant remove the interval function call for a specific player
// We also dont want to check for all god players in a single fucntion call => too slow
// Thus we need to re-queue the function call for each god player separately (serverside)
// Remove godmode function from call queue but add again for remaining gods
RefreshGodQueue();
SendPlayerMessage(player, "Godmode disabled.");
}
else {
SendPlayerMessage(player, "ERROR: Invalid argument given. Argument should be: 0-1");
return false;
}
break;
case "/give":
if ( args.Count() < 2 || args.Count() > 3 ) {
SendPlayerMessage(player, "Syntax: /give [ITEM_NAME] (AMOUNT) - Spawn item on ground, default amount is 1");
return false;
}
EntityAI item = player.SpawnEntityOnGroundPos(args[1], player.GetPosition());
if (!item) {
SendPlayerMessage(player, "ERROR: Could not create item.");
return false;
}
if ( args.Count() == 3 ) {
int itemCount = args[2].ToInt();
if (itemCount <= 0) {
SendPlayerMessage(player, "ERROR: Invalid count.");
return false;
}
// Spawn the rest of the items if count was specified and valid
for (int i = 0; i < itemCount - 1; i++) {
player.SpawnEntityOnGroundPos(args[1], player.GetPosition());
}
}
SendPlayerMessage(player, "Item(s) spawned.");
break;
case "/here":
if ( args.Count() < 2 ) {
SendPlayerMessage(player, "Syntax: /here '[PLAYER IDENTITY]' (DISTANCE) - Moves a player to self, remember to use single quotes around identity");
return false;
}
PrepareTeleport(command, args, target, dist);
if (!target) {
SendPlayerMessage(player, "Could not found target player.");
return false;
}
if (dist < 1) {
SendPlayerMessage(player, "Invalid distance.");
return false;
}
TeleportPlayer(target, player, dist);
break;
case "/there":
if ( args.Count() < 2 ) {
SendPlayerMessage(player, "Syntax: /there '[PLAYER IDENTITY]' (DISTANCE) - Moves self to a player");
return false;
}
PrepareTeleport(command, args, target, dist);
if (!target) {
SendPlayerMessage(player, "Could not found target player.");
return false;
}
if (dist < 1) {
SendPlayerMessage(player, "Invalid distance.");
return false;
}
TeleportPlayer(player, target, dist);
break;
case "/suicide":
if ( args.Count() != 1 ) {
SendPlayerMessage(player, "Syntax: /suicide - Commit a suicide");
return false;
}
// Use SteamID here for sake of certainty
if (!KillPlayer( player.GetIdentity().GetPlainId() )) {
SendPlayerMessage(player, "Could not commit suicide.");
}
break;
case "/kill":
if ( args.Count() < 2 ) {
SendPlayerMessage(player, "Syntax: /kill '[PLAYER IDENTITY]' - Kills a player by given identity, use single quotes around");
return false;
}
arg = MyTrim(command, "'");
if (!KillPlayer(arg)) {
SendPlayerMessage(player, "Error: Could not kill player.");
}
break;
case "/help":
SendPlayerMessage(player, helpMsg);
return false;
default:
SendPlayerMessage(player, "Unknown command!");
SendPlayerMessage(player, helpMsg);
return false;
}
return true;
}
void PrepareTeleport(string cmd, TStringArray args, out PlayerBase target, out int distance)
{
// Parse target player name: "...stuff 'input' stuff..." -> "input"
string name = MyTrim(cmd, "'");
distance = args[args.Count() - 1].ToInt();
target = GetPlayer(name, Identity.ANY);
}
bool SpawnAmmo(PlayerBase player, string type, int amount = 1)
{
type.ToLower();
const string helpMsg = "Available ammo types: svd, m4, akm, fx45";
vector pos = player.GetPosition();
pos[0] = pos[0] + 1;
pos[1] = pos[1] + 1;
pos[2] = pos[2] + 1;
string mag;
string ammo;
switch (type)
{
case "svd":
mag = "Mag_SVD_10Rnd";
ammo = "AmmoBox_762x54Tracer_20Rnd";
break;
case "m4":
mag = "Mag_STANAG_30Rnd";
ammo = "AmmoBox_556x45Tracer_20Rnd";
break;
case "akm":
mag = "Mag_AKM_30Rnd";
ammo = "AmmoBox_762x39Tracer_20Rnd";
break;
case "fx45":
mag = "Mag_FNX45_15Rnd";
ammo = "AmmoBox_45ACP_25rnd";
break;
case "help":
SendPlayerMessage(player, helpMsg);
return false;
default:
SendPlayerMessage(player, "Invalid ammo type.");
SendPlayerMessage(player, helpMsg);
return false;
}
for (int i = 0; i < amount; i++)
{
player.SpawnEntityOnGroundPos(mag, pos);
player.SpawnEntityOnGroundPos(ammo, pos);
}
return true;
}
// Just keep track of the active calls, no boundary checks here
void RefreshGodQueue()
{
GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Remove(this.GodMode);
m_calls = 0;
foreach (int pId : m_gods)
{
PlayerBase godPlayer = GetPlayer(pId.ToString(), Identity.PID);
if (!godPlayer) {
m_gods.Remove( pId );
continue;
}
GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(this.GodMode, 1000, true, godPlayer);
m_calls += 1;
}
}
void GodMode(PlayerBase player)
{
// // if we only had the PID
// PlayerBase player = GetPlayer(pId.ToString(), Identity.PID);
// If invalid player
if (!player) {
// Make sure this function call gets removed from the queue
// So the function call queue does not get overloaded
// Refresh call takes care of removing invalid PIDs
RefreshGodQueue();
return;
}
int pId = player.GetID();
// If player is not god, do nothing
if (m_gods.Find( pId ) == -1) {
// Refresh at this point to get the pid removed from the list
RefreshGodQueue();
return;
}
// If player already dead, make sure godmode gets disabled
if (player.GetHealth("", "") <= 0.0) {
// We have just checked pid is in the list, so manually remove the pid and refresh
m_gods.Remove( pId );
RefreshGodQueue();
return;
}
// Set all health statuses to maximum
RestoreHealth(player);
}
void RestoreHealth(PlayerBase player)
{
if (!player) return;
player.SetHealth("GlobalHealth", "Blood", player.GetMaxHealth("GlobalHealth", "Blood"));
player.SetHealth("GlobalHealth", "Health", player.GetMaxHealth("GlobalHealth", "Health"));
player.SetHealth("GlobalHealth", "Shock", player.GetMaxHealth("GlobalHealth", "Shock"));
}
bool SpawnCar(PlayerBase player, string type)
{
type.ToLower();
const string helpMsg = "Available types: offroad, olga, olgablack, sarka, gunter";
// Set car pos near player
vector pos = player.GetPosition();
pos[0] = pos[0] + 3;
pos[1] = pos[1] + 3;
pos[2] = pos[2] + 3;
Car car;
switch (type)
{
case "offroad":
// Spawn and build the car
car = GetGame().CreateObject("OffroadHatchback", pos);
car.GetInventory().CreateAttachment("HatchbackTrunk");
car.GetInventory().CreateAttachment("HatchbackHood");
car.GetInventory().CreateAttachment("HatchbackDoors_CoDriver");
car.GetInventory().CreateAttachment("HatchbackDoors_Driver");
car.GetInventory().CreateAttachment("HatchbackWheel");
car.GetInventory().CreateAttachment("HatchbackWheel");
car.GetInventory().CreateAttachment("HatchbackWheel");
car.GetInventory().CreateAttachment("HatchbackWheel");
SendPlayerMessage(player, "OffroadHatchback spawned.");
break;
case "olga":
// Spawn and build the car
car = GetGame().CreateObject("CivilianSedan", pos);
car.GetInventory().CreateAttachment("CivSedanHood");
car.GetInventory().CreateAttachment("CivSedanTrunk");
car.GetInventory().CreateAttachment("CivSedanDoors_Driver");
car.GetInventory().CreateAttachment("CivSedanDoors_CoDriver");
car.GetInventory().CreateAttachment("CivSedanDoors_BackLeft");
car.GetInventory().CreateAttachment("CivSedanDoors_BackRight");
car.GetInventory().CreateAttachment("CivSedanWheel");
car.GetInventory().CreateAttachment("CivSedanWheel");
car.GetInventory().CreateAttachment("CivSedanWheel");
car.GetInventory().CreateAttachment("CivSedanWheel");
SendPlayerMessage(player, "CivSedan spawned.");
break;
case "olgablack":
// Spawn and build the car
car = GetGame().CreateObject("CivilianSedan_Black", pos);
car.GetInventory().CreateAttachment("CivSedanHood_Black");
car.GetInventory().CreateAttachment("CivSedanTrunk_Black");
car.GetInventory().CreateAttachment("CivSedanDoors_Driver_Black");
car.GetInventory().CreateAttachment("CivSedanDoors_CoDriver_Black");
car.GetInventory().CreateAttachment("CivSedanDoors_BackLeft_Black");
car.GetInventory().CreateAttachment("CivSedanDoors_BackRight_Black");
car.GetInventory().CreateAttachment("CivSedanWheel");
car.GetInventory().CreateAttachment("CivSedanWheel");
car.GetInventory().CreateAttachment("CivSedanWheel");
car.GetInventory().CreateAttachment("CivSedanWheel");
SendPlayerMessage(player, "CivSedan_Black spawned.");
break;
case "sarka":
// Spawn and build the car
car = GetGame().CreateObject("Sedan_02", pos);
car.GetInventory().CreateAttachment("Sedan_02_Hood");
car.GetInventory().CreateAttachment("Sedan_02_Trunk");
car.GetInventory().CreateAttachment("Sedan_02_Door_1_1");
car.GetInventory().CreateAttachment("Sedan_02_Door_1_2");
car.GetInventory().CreateAttachment("Sedan_02_Door_2_1");
car.GetInventory().CreateAttachment("Sedan_02_Door_2_2");
car.GetInventory().CreateAttachment("Sedan_02_Wheel");
car.GetInventory().CreateAttachment("Sedan_02_Wheel");
car.GetInventory().CreateAttachment("Sedan_02_Wheel");
car.GetInventory().CreateAttachment("Sedan_02_Wheel");
SendPlayerMessage(player, "Sedan_02 spawned.");
break;
case "gunter":
// Spawn and build the car
car = GetGame().CreateObject("Hatchback_02", pos);
car.GetInventory().CreateAttachment("Hatchback_02_Hood");
car.GetInventory().CreateAttachment("Hatchback_02_Trunk");
car.GetInventory().CreateAttachment("Hatchback_02_Door_1_1");
car.GetInventory().CreateAttachment("Hatchback_02_Door_1_2");
car.GetInventory().CreateAttachment("Hatchback_02_Door_2_1");
car.GetInventory().CreateAttachment("Hatchback_02_Door_2_2");
car.GetInventory().CreateAttachment("Hatchback_02_Wheel");
car.GetInventory().CreateAttachment("Hatchback_02_Wheel");
car.GetInventory().CreateAttachment("Hatchback_02_Wheel");
car.GetInventory().CreateAttachment("Hatchback_02_Wheel");
SendPlayerMessage(player, "Hatchback_02 spawned.");
break;
case "help":
SendPlayerMessage(player, helpMsg);
return false;
default:
SendPlayerMessage(player, "ERROR: Car type invalid.");
SendPlayerMessage(player, helpMsg);
return false;
}
// A car was spawned, so we do some common car configuration
// Do general car building matching all car types
car.GetInventory().CreateAttachment("CarRadiator");
car.GetInventory().CreateAttachment("CarBattery");
car.GetInventory().CreateAttachment("SparkPlug");
car.GetInventory().CreateAttachment("HeadlightH7");
car.GetInventory().CreateAttachment("HeadlightH7");
// Fill all the fluids
car.Fill(CarFluid.FUEL, car.GetFluidCapacity(CarFluid.FUEL));
car.Fill(CarFluid.OIL, car.GetFluidCapacity(CarFluid.OIL));
car.Fill(CarFluid.BRAKE, car.GetFluidCapacity(CarFluid.BRAKE));
car.Fill(CarFluid.COOLANT, car.GetFluidCapacity(CarFluid.COOLANT));
// Set neutral gear
car.GetController().ShiftTo(CarGear.NEUTRAL);
return true;
}
void SafeSetPos(PlayerBase player, string pos)
{
// Safe conversion
vector p = pos.ToVector();
// Check that position is a valid coordinate
// 0 0 0 wont be accepted even though valid
if (p) {
// Get safe surface value for Y coordinate in that position
p[1] = GetGame().SurfaceY(p[0], p[2]);
player.SetPosition(p);
return;
}
SendPlayerMessage(player, "Invalid coordinates.");
}
void PlayerInfo(PlayerBase player)
{
if (!player) {
GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Remove(this.PlayerInfo);
return;
}
// Clear chat history first
for (int x = 0; x < 15; x++) {
SendPlayerMessage(player, " ");
}
ref array<Man> players = new array<Man>;
GetGame().GetPlayers( players );
// Send player count
SendPlayerMessage(player, "Players on server: " + players.Count());
// Maximum amount of single line entries that fit in the chat history: 12
int max = 10;
if ( players.Count() < max )
max = players.Count();
PlayerBase p;
for ( int i = 0; i < max; ++i )
{
//if (i > 0)
// SendPlayerMessage(player, "*");
Class.CastTo(p, players.Get(i));
string info = "Player {" + string.ToString(i, false, false, false) + "}";
info = info + " " + "Name: " + p.GetIdentity().GetName();
info = info + " " + "Pos: " + p.GetPosition().ToString();
info = info + " " + "Health: " + p.GetHealth("GlobalHealth", "Health");
info = info + " " + "Blood: " + p.GetHealth("GlobalHealth", "Blood");
info = info + " " + "Shock: " + p.GetHealth("GlobalHealth", "Shock");
info = info + " " + "PlayerID: " + p.GetID();
info = info + " " + "SteamID64: " + p.GetIdentity().GetPlainId();
SendPlayerMessage(player, info);
}
SendPlayerMessage(player, " ");
}
bool SpawnGear(PlayerBase player, string type)
{
type.ToLower();
const string helpMsg = "Available types: mil, ghillie, medic, nv, svd, m4, akm, fx45";
vector pos = player.GetPosition();
pos[0] = pos[0] + 1;
pos[1] = pos[1] + 1;
pos[2] = pos[2] + 1;
// DONT spawn a mag as attachment, is buggy ingame, spawn mags in ground instead
EntityAI item;
EntityAI subItem;
switch (type)
{
case "mil":
// Head
item = player.SpawnEntityOnGroundPos("Mich2001Helmet", pos);
subItem = item.GetInventory().CreateAttachment("NVGoggles");
subItem.GetInventory().CreateAttachment("Battery9V");
subItem = item.GetInventory().CreateAttachment("UniversalLight");
subItem.GetInventory().CreateAttachment("Battery9V");
player.SpawnEntityOnGroundPos("GP5GasMask", pos);
// Vest
item = player.SpawnEntityOnGroundPos("SmershVest", pos);
item.GetInventory().CreateAttachment("SmershBag");
// Body
player.SpawnEntityOnGroundPos("TTsKOJacket_Camo", pos);
player.SpawnEntityOnGroundPos("TTSKOPants", pos);
player.SpawnEntityOnGroundPos("OMNOGloves_Gray", pos);
// Waist
item = player.SpawnEntityOnGroundPos("MilitaryBelt", pos);
item.GetInventory().CreateAttachment("Canteen");
item.GetInventory().CreateAttachment("PlateCarrierHolster");
subItem = item.GetInventory().CreateAttachment("NylonKnifeSheath");
subItem.GetInventory().CreateAttachment("CombatKnife");
// Legs
item = player.SpawnEntityOnGroundPos("MilitaryBoots_Black", pos);
item.GetInventory().CreateAttachment("CombatKnife");
// Back
player.SpawnEntityOnGroundPos("AliceBag_Camo", pos);
break;
case "ghillie":
player.SpawnEntityOnGroundPos("GhillieAtt_Woodland", pos);
player.SpawnEntityOnGroundPos("GhillieAtt_Woodland", pos);
player.SpawnEntityOnGroundPos("GhillieBushrag_Woodland", pos);
player.SpawnEntityOnGroundPos("GhillieHood_Woodland", pos);
player.SpawnEntityOnGroundPos("GhillieSuit_Woodland", pos);
player.SpawnEntityOnGroundPos("GhillieTop_Woodland", pos);
break;
case "svd":
item = player.SpawnEntityOnGroundPos("SVD", pos);
item.GetInventory().CreateAttachment("AK_Suppressor");
subItem = item.GetInventory().CreateAttachment("PSO1Optic");
subItem.GetInventory().CreateAttachment("Battery9V");
item = player.SpawnEntityOnGroundPos("KazuarOptic", pos);
item.GetInventory().CreateAttachment("Battery9V");
player.SpawnEntityOnGroundPos("Mag_SVD_10Rnd", pos);
player.SpawnEntityOnGroundPos("Mag_SVD_10Rnd", pos);
player.SpawnEntityOnGroundPos("Mag_SVD_10Rnd", pos);
player.SpawnEntityOnGroundPos("Mag_SVD_10Rnd", pos);
break;
case "m4":
item = player.SpawnEntityOnGroundPos("M4A1", pos);
item.GetInventory().CreateAttachment("M4_Suppressor");
item.GetInventory().CreateAttachment("M4_OEBttstck");
item.GetInventory().CreateAttachment("M4_RISHndgrd");
subItem = item.GetInventory().CreateAttachment("ReflexOptic");
subItem.GetInventory().CreateAttachment("Battery9V");
subItem = item.GetInventory().CreateAttachment("UniversalLight");
subItem.GetInventory().CreateAttachment("Battery9V");
player.SpawnEntityOnGroundPos("Mag_STANAG_30Rnd", pos);
player.SpawnEntityOnGroundPos("Mag_STANAG_30Rnd", pos);
player.SpawnEntityOnGroundPos("Mag_STANAG_30Rnd", pos);
player.SpawnEntityOnGroundPos("ACOGOptic", pos);
break;
case "akm":
item = player.SpawnEntityOnGroundPos("AKM", pos);
item.GetInventory().CreateAttachment("AK_Suppressor");
item.GetInventory().CreateAttachment("AK_WoodBttstck");
item.GetInventory().CreateAttachment("AK_RailHndgrd");
subItem = item.GetInventory().CreateAttachment("KobraOptic");
subItem.GetInventory().CreateAttachment("Battery9V");
subItem = item.GetInventory().CreateAttachment("UniversalLight");
subItem.GetInventory().CreateAttachment("Battery9V");
item = player.SpawnEntityOnGroundPos("PSO1Optic", pos);
item.GetInventory().CreateAttachment("Battery9V");
player.SpawnEntityOnGroundPos("Mag_AKM_30Rnd", pos);
player.SpawnEntityOnGroundPos("Mag_AKM_30Rnd", pos);
player.SpawnEntityOnGroundPos("Mag_AKM_Drum75Rnd", pos);
break;
case "fx45":
item = player.SpawnEntityOnGroundPos("FNX45", pos);
item.GetInventory().CreateAttachment("PistolSuppressor");
subItem = item.GetInventory().CreateAttachment("FNP45_MRDSOptic");
subItem.GetInventory().CreateAttachment("Battery9V");
subItem = item.GetInventory().CreateAttachment("TLRLight");
subItem.GetInventory().CreateAttachment("Battery9V");
player.SpawnEntityOnGroundPos("Mag_FNX45_15Rnd", pos);
player.SpawnEntityOnGroundPos("Mag_FNX45_15Rnd", pos);
player.SpawnEntityOnGroundPos("Mag_FNX45_15Rnd", pos);
break;
case "nv":
item = player.SpawnEntityOnGroundPos("NVGHeadstrap", pos);
subItem = item.GetInventory().CreateAttachment("NVGoggles");
subItem.GetInventory().CreateAttachment("Battery9V");
break;
case "medic":
player.SpawnEntityOnGroundPos("BandageDressing", pos);
player.SpawnEntityOnGroundPos("BandageDressing", pos);
player.SpawnEntityOnGroundPos("BandageDressing", pos);
player.SpawnEntityOnGroundPos("BandageDressing", pos);
player.SpawnEntityOnGroundPos("SalineBagIV", pos);
player.SpawnEntityOnGroundPos("Morphine", pos);
player.SpawnEntityOnGroundPos("Epinephrine", pos);
break;
case "mosin":
break;
case "sks":
break;
case "help":
SendPlayerMessage(player, helpMsg);
return false;
default:
SendPlayerMessage(player, "Invalid gear type.");
SendPlayerMessage(player, helpMsg);
return false;
}
return true;
}
void TeleportPlayer(PlayerBase from, PlayerBase to, int distance)
{
if (!from) return;
if (!to) return;
vector toPos = to.GetPosition();
float pos_x = toPos[0] + distance;
float pos_z = toPos[2] + distance;
float pos_y = GetGame().SurfaceY(pos_x, pos_z);
vector pos = Vector(pos_x, pos_y, pos_z);
from.SetPosition(pos);
}
bool KillPlayer(string tag)
{
PlayerBase p = GetPlayer(tag, Identity.ANY);
if (!p) return false;
p.SetHealth("", "", -1);
return true;
}
override void OnEvent(EventType eventTypeId, Param params)
{
switch(eventTypeId)
{
// Handle user command
case ChatMessageEventTypeID:
ChatMessageEventParams chatParams;
Class.CastTo(chatParams, params);
// Remove those stupid ' ' => Substring: x, false, false, quotes = false
// Check that input was a command (contains forward slash)
string cmd = string.ToString(chatParams.param3, false, false, false);
// command format: /abc def ghi
// if not command, is normal chat message
if ( cmd.Get(0) != "/" ) break;
// Get sender player name as string
string senderName = string.ToString(chatParams.param2, false, false, false);
// Get sender player object
PlayerBase sender = GetPlayer(senderName, Identity.NAME);
// If fails to get the message sender, stop
if (!sender) {
return;
}
// Check that player has sufficient privileges to execute commands
if ( !IsAdmin(sender) ) {
SendPlayerMessage(sender, "Sorry, you are not an admin!");
return;
}
// Execute specified command
Command(sender, cmd);
// Return after execution instead of breaking to prevent normal event handling
return;
}
// Unless chat command was executed, operate normally
// Call super class event handler to handle other events
super.OnEvent(eventTypeId, params);
}
bool IsAdmin(PlayerBase player)
{
return m_admins.Find( player.GetIdentity().GetPlainId() ) != -1;
}
PlayerBase GetPlayer(string tag, Identity type)
{
ref array<Man> players = new array<Man>;
GetGame().GetPlayers( players );
PlayerBase p;
bool nameMatch;
bool steamIdMatch;
bool pidMatch;
for ( int i = 0; i < players.Count(); ++i )
{
Class.CastTo(p, players.Get(i));
// Store matches from different checks
nameMatch = p.GetIdentity().GetName() == tag;
steamIdMatch = p.GetIdentity().GetPlainId() == tag;
pidMatch = p.GetID() == tag.ToInt();
if ( type == Identity.ANY ) {
if ( nameMatch || steamIdMatch || pidMatch )
return p;
}
else if ( type == Identity.NAME ) {
if ( nameMatch )
return p;
}
else if ( type == Identity.STEAMID ) {
if ( steamIdMatch )
return p;
}
else if ( type == Identity.PID ) {
if ( pidMatch )
return p;
}
}
// Player with given parameter not found
return NULL;
}
void SendGlobalMessage(string message)
{
ref array<Man> players = new array<Man>;
GetGame().GetPlayers( players );