-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGiveWeps.as
92 lines (81 loc) · 2.38 KB
/
GiveWeps.as
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
void PluginInit()
{
g_Module.ScriptInfo.SetAuthor("Karma Kitten");
g_Module.ScriptInfo.SetContactInfo("@karmakittenx - Twitter");
g_Hooks.RegisterHook( Hooks::Player::ClientSay, @ClientSay );
}
// Define console commands
CConCommand give("givewep", "Grants the player a weapon of their choice", @CnsCmd);
array<string> weapons = { // * - Special weapon, not included in 'all' command
"weapon_crowbar",
"weapon_9mmhandgun",
"weapon_357",
"weapon_9mmAR",
"weapon_mp5",
"weapon_handgrenade",
"weapon_crossbow",
"weapon_shotgun",
"weapon_rpg",
"weapon_gauss",
"weapon_egon",
"weapon_hornetgun",
"weapon_satchel",
"weapon_uzi",
"weapon_uziakimbo",
"weapon_medkit",
"weapon_pipewrench",
"weapon_grapple",
"weapon_sniperrifle",
"weapon_m249",
"weapon_tripmine",
"weapon_snark",
"weapon_m16",
"weapon_sporelauncher",
"weapon_eagle",
"weapon_displacer",
"weapon_minigun", // * Does not grant however
"weapon_shockrifle" // *
};
bool GiveWeapon(CBasePlayer@ player, string weapon)
{
if (weapon == "all")
{
for(uint i = 0; i < weapons.length() - 2; i++)
{
player.GiveNamedItem(weapons[i], 0, 200);
}
return true; // All weapons successfully given
}
if(IsValidWeapon(weapon))
{
player.GiveNamedItem(weapon, 0, 200);
return true; // Weapon was successfully given
}
return false; // Weapon was not successfully given
}
bool IsValidWeapon(string weapon)
{
if (weapons.find(weapon) > 0)
{
return true; // If the weapon is found (>0, valid in the game)
}
return false; // If the weapon is not found (-1, not in the game or typo)
}
void CnsCmd(const CCommand@ args)
{
CBasePlayer@ player = g_ConCommandSystem.GetCurrentPlayer();
if (args.ArgC() > 0) // Has at least 1 argument (the weapon identifier)
{
GiveWeapon(player, args[1]);
}
}
HookReturnCode ClientSay(SayParameters@ sp)
{
const CCommand@ args = sp.GetArguments(); // Get arguments from the user message
CBasePlayer@ player = sp.GetPlayer();
if (args.ArgC() > 0 && GiveWeapon(player, args[1])) // Same logic as CnsCmd(), true if args are valid and the weapon was successfully given to the player
{
return HOOK_HANDLED;
}
return HOOK_CONTINUE;
}