-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spawn-Loadout-GoldKingZ.cs
532 lines (439 loc) · 24.1 KB
/
Spawn-Loadout-GoldKingZ.cs
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
using Newtonsoft.Json;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Modules.Timers;
using Spawn_Loadout_GoldKingZ.Config;
using Newtonsoft.Json.Linq;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Modules.Entities;
namespace Spawn_Loadout_GoldKingZ;
[MinimumApiVersion(276)]
public class SpawnLoadoutGoldKingZ : BasePlugin
{
public override string ModuleName => "Give Weapons On Spawn (Depend The Map Name + Team Side)";
public override string ModuleVersion => "1.0.7";
public override string ModuleAuthor => "Gold KingZ";
public override string ModuleDescription => "https://github.com/oqyh";
public static SpawnLoadoutGoldKingZ Instance { get; set; } = new();
public Globals g_Main = new();
private readonly PlayerChat _PlayerChat = new();
public override void Load(bool hotReload)
{
Instance = this;
Configs.Load(ModuleDirectory);
Configs.Shared.CookiesModule = ModuleDirectory;
Configs.Shared.StringLocalizer = Localizer;
_ = Task.Run(async () =>
{
await Helper.DownloadMissingFiles();
});
Configs.Shared.CustomFunctions = new CustomGameData();
Helper.SetValuesToGlobals();
RegisterEventHandler<EventPlayerSpawn>(OnEventPlayerSpawn, HookMode.Post);
RegisterEventHandler<EventGrenadeThrown>(OnEventGrenadeThrown, HookMode.Post);
RegisterEventHandler<EventPlayerDeath>(OnEventPlayerDeath);
RegisterEventHandler<EventPlayerDisconnect>(OnPlayerDisconnect);
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterListener<Listeners.OnMapEnd>(OnMapEnd);
RegisterEventHandler<EventRoundStart>(OnEventRoundStart);
RegisterEventHandler<EventRoundPrestart>(OnEventRoundPrestart, HookMode.Pre);
AddCommandListener("say", OnPlayerChat, HookMode.Post);
AddCommandListener("say_team", OnPlayerChatTeam, HookMode.Post);
}
public void OnMapStart(string mapname)
{
Helper.SetValuesToGlobals();
bool GetBoolServerCommands = g_Main.ForceRemoveServerCommands? true : false;
bool GetBoolClientCommands = g_Main.ForceRemoveClientCommands? true : false;
Helper.ClearMapCommands(GetBoolServerCommands,GetBoolClientCommands);
}
private HookResult OnPlayerChat(CCSPlayerController? player, CommandInfo info)
{
if (player == null || !player.IsValid)return HookResult.Continue;
_PlayerChat.OnPlayerChat(player, info, false);
return HookResult.Continue;
}
private HookResult OnPlayerChatTeam(CCSPlayerController? player, CommandInfo info)
{
if (player == null || !player.IsValid)return HookResult.Continue;
_PlayerChat.OnPlayerChat(player, info, true);
return HookResult.Continue;
}
public HookResult OnEventGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info)
{
if (@event == null) return HookResult.Continue;
var player = @event.Userid;
if (player == null || !player.IsValid) return HookResult.Continue;
var nadename = @event.Weapon;
if (nadename == null) return HookResult.Continue;
var playerpawn = player.PlayerPawn;
if (playerpawn == null || !playerpawn.IsValid) return HookResult.Continue;
var playerpawnvalue = playerpawn.Value;
if (playerpawnvalue == null || !playerpawnvalue.IsValid) return HookResult.Continue;
var playerWeaponServices = playerpawnvalue.WeaponServices;
if (playerWeaponServices == null) return HookResult.Continue;
var playerMyWeapons = playerWeaponServices.MyWeapons;
if (playerMyWeapons == null) return HookResult.Continue;
var jsonValues = g_Main.GetJsonValues();
if (jsonValues == null || jsonValues.Count == 0) return HookResult.Continue;
foreach (var loadout in jsonValues)
{
dynamic loadoutValue = loadout.Value;
if (loadoutValue is JObject)
{
string key = loadout.Key;
string loadoutName = loadoutValue.Name;
string HasFlag = loadoutValue.ContainsKey("Flags") && loadoutValue["Flags"] != null
? loadoutValue["Flags"].ToString()
: null!;
string ctREFILENades = loadoutValue.ContainsKey("CT_Refill_Nades") && loadoutValue["CT_Refill_Nades"] != null
? loadoutValue["CT_Refill_Nades"].ToString()
: null!;
string tREFILENades = loadoutValue.ContainsKey("T_Refill_Nades") && loadoutValue["T_Refill_Nades"] != null
? loadoutValue["T_Refill_Nades"].ToString()
: null!;
int ctRefillTime = loadoutValue.ContainsKey("CT_Refill_Time_InSec") && loadoutValue["CT_Refill_Time_InSec"] != null
? (int)loadoutValue["CT_Refill_Time_InSec"]
: 0;
int tRefillTime = loadoutValue.ContainsKey("T_Refill_Time_InSec") && loadoutValue["T_Refill_Time_InSec"] != null
? (int)loadoutValue["T_Refill_Time_InSec"]
: 0;
int giveOncePerRound = loadoutValue.ContainsKey("Give_This_LoadOut_PerRound_Only") && loadoutValue["Give_This_LoadOut_PerRound_Only"] != null
? (int)loadoutValue["Give_This_LoadOut_PerRound_Only"]
: 0;
if (HasFlag != null && !string.IsNullOrEmpty(HasFlag) && !Helper.IsPlayerInGroupPermission(player, HasFlag)) continue;
if (giveOncePerRound == 1 || giveOncePerRound == 2)
{
if (!Helper.IsWarmup() || giveOncePerRound == 2)
{
if (!g_Main.loadoutsGivenPerPlayer.ContainsKey(player))
{
g_Main.loadoutsGivenPerPlayer[player] = new HashSet<string>();
}
if (g_Main.loadoutsGivenPerPlayer[player].Contains(loadoutName))
{
Helper.AdvancedPlayerPrintToChat(player, Configs.Shared.StringLocalizer!["PrintChatToPlayer.Got.Loadout"]);
continue;
}
else
{
g_Main.loadoutsGivenPerPlayer[player].Add(loadoutName);
}
}
}
if(player.TeamNum == (byte)CsTeam.CounterTerrorist && ctREFILENades != null)
{
var ctRefillNadesArray = ctREFILENades.Split(',');
foreach (var grenade in ctRefillNadesArray)
{
if ("weapon_" + nadename == grenade.Trim())
{
Server.NextFrame(() =>
{
AddTimer(ctRefillTime, () =>
{
if(player != null && player.IsValid && player.PawnIsAlive && player.TeamNum == (byte)CsTeam.CounterTerrorist)
{
Helper.GiveWeaponsToPlayer(player, "weapon_" + nadename);
}
}, TimerFlags.STOP_ON_MAPCHANGE);
});
}
}
}else if(player.TeamNum == (byte)CsTeam.Terrorist && tREFILENades != null)
{
var tRefillNadesArray = tREFILENades.Split(',');
foreach (var grenade in tRefillNadesArray)
{
if ("weapon_" + nadename == grenade.Trim())
{
Server.NextFrame(() =>
{
AddTimer(ctRefillTime, () =>
{
if(player != null && player.IsValid && player.PawnIsAlive && player.TeamNum == (byte)CsTeam.Terrorist)
{
Helper.GiveWeaponsToPlayer(player, "weapon_" + nadename);
}
}, TimerFlags.STOP_ON_MAPCHANGE);
});
}
}
}
}
}
return HookResult.Continue;
}
private HookResult OnEventPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
if (@event == null) return HookResult.Continue;
var player = @event.Userid;
if (player == null || !player.IsValid) return HookResult.Continue;
var playerpawn = player.PlayerPawn;
if (playerpawn == null || !playerpawn.IsValid) return HookResult.Continue;
var playerpawnvalue = playerpawn.Value;
if (playerpawnvalue == null || !playerpawnvalue.IsValid) return HookResult.Continue;
var playerWeaponServices = playerpawnvalue.WeaponServices;
if (playerWeaponServices == null) return HookResult.Continue;
var playerMyWeapons = playerWeaponServices.MyWeapons;
if (playerMyWeapons == null) return HookResult.Continue;
var jsonValues = g_Main.GetJsonValues();
if (jsonValues == null || jsonValues.Count == 0) return HookResult.Continue;
Server.NextFrame(() =>
{
Helper.GivePlayerHealthNArmor(player);
});
foreach (var loadout in jsonValues)
{
dynamic loadoutValue = loadout.Value;
if (loadoutValue is JObject)
{
string key = loadout.Key;
string loadoutName = loadoutValue.Name;
string HasFlag = loadoutValue.ContainsKey("Flags") && loadoutValue["Flags"] != null
? loadoutValue["Flags"].ToString()
: null!;
string ctWeapons = loadoutValue.ContainsKey("CT") && loadoutValue["CT"] != null
? loadoutValue["CT"].ToString()
: null!;
string tWeapons = loadoutValue.ContainsKey("T") && loadoutValue["T"] != null
? loadoutValue["T"].ToString()
: null!;
int giveOncePerRound = loadoutValue.ContainsKey("Give_This_LoadOut_PerRound_Only") && loadoutValue["Give_This_LoadOut_PerRound_Only"] != null
? (int)loadoutValue["Give_This_LoadOut_PerRound_Only"]
: 0;
if (HasFlag != null && !string.IsNullOrEmpty(HasFlag) && !Helper.IsPlayerInGroupPermission(player, HasFlag)) continue;
if (giveOncePerRound == 1 || giveOncePerRound == 2)
{
if (!Helper.IsWarmup() || giveOncePerRound == 2)
{
if (!g_Main.loadoutsGivenPerPlayer.ContainsKey(player))
{
g_Main.loadoutsGivenPerPlayer[player] = new HashSet<string>();
}
if (g_Main.loadoutsGivenPerPlayer[player].Contains(loadoutName))
{
Helper.AdvancedPlayerPrintToChat(player, Configs.Shared.StringLocalizer!["PrintChatToPlayer.Got.Loadout"]);
continue;
}
else
{
g_Main.loadoutsGivenPerPlayer[player].Add(loadoutName);
}
}
}
if(player.TeamNum == (byte)CsTeam.CounterTerrorist && ctWeapons != null)
{
var weaponsCTSet = new HashSet<string>(ctWeapons.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(w => w.Trim()));
if(g_Main.ForceStripPlayers)
{
if (!g_Main.PlayerCleanUp.ContainsKey(player))
{
CounterStrikeSharp.API.Modules.Timers.Timer? timerz = AddTimer(0.1f, () => Helper.CleanUpPlayerWeapons(player), TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
g_Main.PlayerCleanUp.Add(player, new Globals.GetPlayerWeapons(player,timerz,null!,weaponsCTSet));
}
if (g_Main.PlayerCleanUp.ContainsKey(player))
{
g_Main.PlayerCleanUp[player].Player = player;
g_Main.PlayerCleanUp[player].Timer?.Kill();
g_Main.PlayerCleanUp[player].Timer = null!;
g_Main.PlayerCleanUp[player].Timer = AddTimer(0.1f, () => Helper.CleanUpPlayerWeapons(player), TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
var newWeapons = weaponsCTSet.Except(g_Main.PlayerCleanUp[player].WeaponsNeeded).ToHashSet();
g_Main.PlayerCleanUp[player].WeaponsNeeded.UnionWith(newWeapons);
g_Main.PlayerCleanUp[player].KillTheTimer?.Kill();
g_Main.PlayerCleanUp[player].KillTheTimer = AddTimer(3.0f, () =>
{
if (player != null && player.IsValid && g_Main.PlayerCleanUp.ContainsKey(player) && g_Main.PlayerCleanUp[player].Timer != null)
{
g_Main.PlayerCleanUp[player].Timer?.Kill();
g_Main.PlayerCleanUp[player].Timer = null!;
}
}, TimerFlags.STOP_ON_MAPCHANGE);
}
}else
{
foreach (var playerMyWeaponst in playerMyWeapons)
{
var weaponsValue = playerMyWeaponst.Value;
if (weaponsValue == null || !weaponsValue.IsValid)
continue;
var weaponsDesignerName = weaponsValue.DesignerName;
if (string.IsNullOrWhiteSpace(weaponsDesignerName))
continue;
if (weaponsDesignerName.Contains("weapon_knife") && !g_Main.RemoveKnife ||
weaponsDesignerName.Contains("weapon_bayonet") && !g_Main.RemoveKnife ||
weaponsDesignerName.Contains("weapon_c4"))
continue;
if (!weaponsCTSet.Contains(weaponsDesignerName))
{
Helper.RemoveWeaponByName(player, weaponsDesignerName);
}
}
}
if (g_Main.ForceRemoveGroundWeapons == 1 || g_Main.ForceRemoveGroundWeapons == 2)
{
if (Helper.IsWarmup() || g_Main.ForceRemoveGroundWeapons == 2)
{
Helper.ClearGroundWeapons();
}
}
foreach (var weaponCT in weaponsCTSet.Where(w => !string.IsNullOrWhiteSpace(w)))
{
Server.NextFrame(() =>
{
AddTimer(g_Main.DelayGiveLoadOut, () =>
{
Helper.GiveWeaponsToPlayer(player, weaponCT);
},TimerFlags.STOP_ON_MAPCHANGE);
});
}
}else if(player.TeamNum == (byte)CsTeam.Terrorist && tWeapons != null)
{
var weaponsTSet = new HashSet<string>(tWeapons.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(w => w.Trim()));
if(g_Main.ForceStripPlayers)
{
if (!g_Main.PlayerCleanUp.ContainsKey(player))
{
CounterStrikeSharp.API.Modules.Timers.Timer? timerz = AddTimer(0.1f, () => Helper.CleanUpPlayerWeapons(player), TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
g_Main.PlayerCleanUp.Add(player, new Globals.GetPlayerWeapons(player,timerz,null!,weaponsTSet));
}
if (g_Main.PlayerCleanUp.ContainsKey(player))
{
g_Main.PlayerCleanUp[player].Player = player;
g_Main.PlayerCleanUp[player].Timer?.Kill();
g_Main.PlayerCleanUp[player].Timer = null!;
g_Main.PlayerCleanUp[player].Timer = AddTimer(0.1f, () => Helper.CleanUpPlayerWeapons(player), TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
var newWeapons = weaponsTSet.Except(g_Main.PlayerCleanUp[player].WeaponsNeeded).ToHashSet();
g_Main.PlayerCleanUp[player].WeaponsNeeded.UnionWith(newWeapons);
g_Main.PlayerCleanUp[player].KillTheTimer?.Kill();
g_Main.PlayerCleanUp[player].KillTheTimer = AddTimer(3.0f, () =>
{
if (player != null && player.IsValid && g_Main.PlayerCleanUp.ContainsKey(player) && g_Main.PlayerCleanUp[player].Timer != null)
{
g_Main.PlayerCleanUp[player].Timer?.Kill();
g_Main.PlayerCleanUp[player].Timer = null!;
}
}, TimerFlags.STOP_ON_MAPCHANGE);
}
}else
{
foreach (var playerMyWeaponst in playerMyWeapons)
{
var weaponsValue = playerMyWeaponst.Value;
if (weaponsValue == null || !weaponsValue.IsValid)
continue;
var weaponsDesignerName = weaponsValue.DesignerName;
if (string.IsNullOrWhiteSpace(weaponsDesignerName))
continue;
if (weaponsDesignerName.Contains("weapon_knife") && !g_Main.RemoveKnife ||
weaponsDesignerName.Contains("weapon_bayonet") && !g_Main.RemoveKnife ||
weaponsDesignerName.Contains("weapon_c4"))
continue;
if (!weaponsTSet.Contains(weaponsDesignerName))
{
Helper.RemoveWeaponByName(player, weaponsDesignerName);
}
}
}
if (g_Main.ForceRemoveGroundWeapons == 1 || g_Main.ForceRemoveGroundWeapons == 2)
{
if (Helper.IsWarmup() || g_Main.ForceRemoveGroundWeapons == 2)
{
Helper.ClearGroundWeapons();
}
}
foreach (var weaponCT in weaponsTSet.Where(w => !string.IsNullOrWhiteSpace(w)))
{
Server.NextFrame(() =>
{
AddTimer(g_Main.DelayGiveLoadOut, () =>
{
Helper.GiveWeaponsToPlayer(player, weaponCT);
},TimerFlags.STOP_ON_MAPCHANGE);
});
}
}
}
}
return HookResult.Continue;
}
private HookResult OnEventRoundPrestart(EventRoundPrestart @event, GameEventInfo info)
{
if(@event == null)return HookResult.Continue;
bool GetBoolServerCommands = g_Main.ForceRemoveServerCommands? true : false;
bool GetBoolClientCommands = g_Main.ForceRemoveClientCommands? true : false;
Helper.ClearMapCommands(GetBoolServerCommands,GetBoolClientCommands);
if(g_Main.RemoveBuyMenu)
{
Server.ExecuteCommand("sv_buy_status_override 3");
}
return HookResult.Continue;
}
private HookResult OnEventRoundStart(EventRoundStart @event, GameEventInfo info)
{
if(@event == null)return HookResult.Continue;
g_Main.loadoutsGivenPerPlayer.Clear();
bool GetBoolServerCommands = g_Main.ForceRemoveServerCommands? true : false;
bool GetBoolClientCommands = g_Main.ForceRemoveClientCommands? true : false;
Helper.ClearMapCommands(GetBoolServerCommands,GetBoolClientCommands);
if(g_Main.RemoveBuyMenu)
{
Server.ExecuteCommand("sv_buy_status_override 3");
}
return HookResult.Continue;
}
private HookResult OnEventPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
{
if(@event == null)return HookResult.Continue;
var player = @event.Userid;
if(player == null || !player.IsValid)return HookResult.Continue;
if (g_Main.PlayerCleanUp.ContainsKey(player))
{
g_Main.PlayerCleanUp[player].Timer?.Kill();
g_Main.PlayerCleanUp[player].Timer = null!;
g_Main.PlayerCleanUp[player].KillTheTimer?.Kill();
g_Main.PlayerCleanUp[player].KillTheTimer = null!;
}
return HookResult.Continue;
}
private HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
{
if (@event == null)return HookResult.Continue;
var player = @event.Userid;
if (player == null || !player.IsValid)return HookResult.Continue;
if (g_Main.PlayerCleanUp.ContainsKey(player))
{
g_Main.PlayerCleanUp[player].Timer?.Kill();
g_Main.PlayerCleanUp[player].Timer = null!;
g_Main.PlayerCleanUp[player].KillTheTimer?.Kill();
g_Main.PlayerCleanUp[player].KillTheTimer = null!;
g_Main.PlayerCleanUp.Remove(player);
}
if (g_Main.loadoutsGivenPerPlayer.ContainsKey(player))g_Main.loadoutsGivenPerPlayer.Remove(player);
return HookResult.Continue;
}
public void OnMapEnd()
{
Helper.ClearVariables();
}
public override void Unload(bool hotReload)
{
Helper.ClearVariables();
}
/* [ConsoleCommand("css_test", "test")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
public void GetJsonCorrectissoaaan(CCSPlayerController? player, CommandInfo commandInfo)
{
if (player == null || !player.IsValid) return;
Server.PrintToConsole($"Remove_BuyMenu: {g_Main.RemoveBuyMenu}");
Server.PrintToConsole($"Remove_Custom_Point_Server_Command: {g_Main.ForceRemoveServerCommands}");
Server.PrintToConsole($"Remove_Custom_Point_Client_Command: {g_Main.ForceRemoveClientCommands}");
Server.PrintToConsole($"Remove_Ground_Weapons: {g_Main.ForceRemoveGroundWeapons}");
Server.PrintToConsole($"Delay_InXSecs_Give_LoadOuts: {g_Main.DelayGiveLoadOut}");
Server.PrintToConsole($"Force_Strip_Players: {g_Main.ForceStripPlayers}");
} */
}