-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathl4d2_smg_reload_tweak.sp
More file actions
111 lines (97 loc) · 3.45 KB
/
l4d2_smg_reload_tweak.sp
File metadata and controls
111 lines (97 loc) · 3.45 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
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
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <l4d2_weapon_stocks>
new Handle:hCvarReloadSpeedUzi;
new Handle:hCvarReloadSpeedSilencedSmg;
new Handle:hCvarReloadSpeedMP5;
public Plugin:myinfo =
{
name = "L4D2 SMG Reload Speed Tweaker",
description = "Allows cvar'd control over the reload durations for all SMGs",
author = "Visor, Wicket",
version = "1.2",
url = "https://github.com/Attano/L4D2-Competitive-Framework"
};
public OnPluginStart()
{
hCvarReloadSpeedUzi = CreateConVar("l4d2_reload_speed_uzi", "0", "Reload duration of Uzi(normal SMG)", FCVAR_CHEAT|FCVAR_NOTIFY, true, 0.0, true, 10.0);
hCvarReloadSpeedSilencedSmg = CreateConVar("l4d2_reload_speed_silenced_smg", "0", "Reload duration of Silenced SMG", FCVAR_CHEAT|FCVAR_NOTIFY, true, 0.0, true, 10.0);
hCvarReloadSpeedMP5 = CreateConVar("l4d2_reload_speed_mp5", "0", "Reload duration of MP5", FCVAR_CHEAT|FCVAR_NOTIFY, true, 0.0, true, 10.0);
HookEvent("weapon_reload", OnWeaponReload, EventHookMode_Post);
}
public OnWeaponReload(Handle:event, String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (!IsSurvivor(client) || !IsPlayerAlive(client) || IsFakeClient(client))
return;
new Float:originalReloadDuration = 0.0;
new Float:alteredReloadDuration = 0.0;
new weapon = GetPlayerWeaponSlot(client, 0);
new WeaponId:weaponId = IdentifyWeapon(weapon);
if (weaponId == WEPID_SMG)
{
originalReloadDuration = 2.235352;
alteredReloadDuration = GetConVarFloat(hCvarReloadSpeedUzi);
}
else if (weaponId == WEPID_SMG_SILENCED)
{
originalReloadDuration = 2.235291;
alteredReloadDuration = GetConVarFloat(hCvarReloadSpeedSilencedSmg);
}
else if (weaponId == WEPID_SMG_MP5)
{
originalReloadDuration = 3.066201;
alteredReloadDuration = GetConVarFloat(hCvarReloadSpeedMP5);
}
else
{
return;
}
if (alteredReloadDuration <= 0.0)
{
return;
}
new Float:oldNextAttack = GetEntPropFloat(weapon, Prop_Send, "m_flNextPrimaryAttack", 0);
new Float:newNextAttack = oldNextAttack - originalReloadDuration + alteredReloadDuration;
new Float:playbackRate = originalReloadDuration / alteredReloadDuration;
SetEntPropFloat(weapon, Prop_Send, "m_flNextPrimaryAttack", newNextAttack);
SetEntPropFloat(client, Prop_Send, "m_flNextAttack", newNextAttack);
SetEntPropFloat(weapon, Prop_Send, "m_flPlaybackRate", playbackRate);
}
public Action:OnPlayerRunCmd(client, &buttons)
{
if (!(buttons & IN_ATTACK2))
return Plugin_Continue;
if (!IsSurvivor(client) || !IsPlayerAlive(client) || IsFakeClient(client))
return Plugin_Continue;
new Float:originalReloadDuration = 0.0;
new Float:alteredReloadDuration = 0.0;
new weapon = GetPlayerWeaponSlot(client, 0);
new WeaponId:weaponId = IdentifyWeapon(weapon);
if (weaponId == WEPID_SMG)
{
originalReloadDuration = 2.235352;
alteredReloadDuration = GetConVarFloat(hCvarReloadSpeedUzi);
}
else if (weaponId == WEPID_SMG_SILENCED)
{
originalReloadDuration = 2.235291;
alteredReloadDuration = GetConVarFloat(hCvarReloadSpeedSilencedSmg);
}
else if (weaponId == WEPID_SMG_MP5)
{
originalReloadDuration = 2.235291;
alteredReloadDuration = GetConVarFloat(hCvarReloadSpeedMP5);
}
else
{
return Plugin_Continue;
}
new Float:playbackRate = originalReloadDuration / alteredReloadDuration;
SetEntPropFloat(weapon, Prop_Send, "m_flPlaybackRate", playbackRate);
}
bool:IsSurvivor(client)
{
return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2;
}