-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.cs
More file actions
48 lines (41 loc) · 1.57 KB
/
Functions.cs
File metadata and controls
48 lines (41 loc) · 1.57 KB
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
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using static WeaponRestricter.Types;
namespace WeaponRestricter
{
internal class Functions
{
// Get weapon by designer_name or name
internal static Weapon? FindWeaponByName(string name, List<Weapon> list)
{
return list.FirstOrDefault(w => w.designer_name == name) ?? list.FirstOrDefault(w => w.name == name);
}
// Get weapon by index
internal static Weapon? FindWeaponByIndex(long index, List<Weapon> list)
{
return list.FirstOrDefault(w => w.def == index);
}
// Check if a restricted weapon is pickable
internal static PickableResult IsPickable(Weapon wep, CsTeam team)
{
// Get all the players
List<CCSPlayerController> _players = Utilities.GetPlayers();
int count = 0;
int limit = wep.limit > 0 ? (_players.Count / wep.limit) : 0;
foreach (CCSPlayerController player in _players)
{
// Is not on the team we're checking for
if (player.Team != team) continue;
// Get all weapons
foreach (var weapon in player.PlayerPawn.Value!.WeaponServices!.MyWeapons)
{
if (weapon.Value!.DesignerName != wep.designer_name) continue;
// Increment count if weapon is found
count++;
}
}
return new(limit, count);
}
}
}