/
TickrateFixes.sp
163 lines (141 loc) · 6.14 KB
/
TickrateFixes.sp
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
/*
SourcePawn is Copyright (C) 2006-2008 AlliedModders LLC. All rights reserved.
SourceMod is Copyright (C) 2006-2008 AlliedModders LLC. All rights reserved.
Pawn and SMALL are Copyright (C) 1997-2008 ITB CompuPhase.
Source is Copyright (C) Valve Corporation.
All trademarks are property of their respective owners.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//<<<<<<<<<<<<<<<<<<<<< TICKRATE FIXES >>>>>>>>>>>>>>>>>>
//// ------- Fast Pistols ---------
// *****************************
//Cvars
new Handle:g_hPistolDelayDualies = INVALID_HANDLE;
new Handle:g_hPistolDelaySingle = INVALID_HANDLE;
new Handle:g_hPistolDelayIncapped = INVALID_HANDLE;
//Floats
new Float:g_fNextAttack[MAXPLAYERS + 1];
new Float:g_fPistolDelayDualies = 0.1;
new Float:g_fPistolDelaySingle = 0.2;
new Float:g_fPistolDelayIncapped = 0.3;
new Float:tickInterval;
new Float:tickRRate;
//Cvar Check & Adjust
new Handle: g_hCvarGravity = INVALID_HANDLE;
#include <sourcemod>
#include <sdkhooks>
public Plugin:myinfo =
{
name = "Tickrate Fixes",
author = "Sir, Griffin",
description = "Fixes a handful of silly Tickrate bugs",
version = "1.0",
url = "Nawl."
}
public OnPluginStart()
{
//Is Server 40+ Tick?
tickInterval = GetTickInterval();
if(0.0 < tickInterval) tickRRate = 1.0/tickInterval;
if(tickRRate >= 40)
{
//Hook Pistols
for (new client = 1; client <= MaxClients; client++)
{
if (!IsClientInGame(client)) continue;
SDKHook(client, SDKHook_PostThinkPost, Hook_OnPostThinkPost);
}
g_hPistolDelayDualies = CreateConVar("l4d_pistol_delay_dualies", "0.1", "Minimum time (in seconds) between dual pistol shots",
FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_NOTIFY, true, 0.0, true, 5.0);
g_hPistolDelaySingle = CreateConVar("l4d_pistol_delay_single", "0.2", "Minimum time (in seconds) between single pistol shots",
FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_NOTIFY, true, 0.0, true, 5.0);
g_hPistolDelayIncapped = CreateConVar("l4d_pistol_delay_incapped", "0.3", "Minimum time (in seconds) between pistol shots while incapped",
FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_NOTIFY, true, 0.0, true, 5.0);
UpdatePistolDelays();
HookConVarChange(g_hPistolDelayDualies, Cvar_PistolDelay);
HookConVarChange(g_hPistolDelaySingle, Cvar_PistolDelay);
HookConVarChange(g_hPistolDelayIncapped, Cvar_PistolDelay);
HookEvent("weapon_fire", Event_WeaponFire);
//Gravity
g_hCvarGravity = FindConVar("sv_gravity");
if (GetConVarInt(g_hCvarGravity) != 750) SetConVarInt(g_hCvarGravity, 750);
}
//We don't need you on this 30T Server
else ServerCommand("sm plugins unload TickrateFixes.smx");
}
public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_PreThink, Hook_OnPostThinkPost);
g_fNextAttack[client] = 0.0;
}
public OnClientDisconnect(client)
{
SDKUnhook(client, SDKHook_PreThink, Hook_OnPostThinkPost);
}
public Cvar_PistolDelay(Handle:convar, const String:oldValue[], const String:newValue[])
{
UpdatePistolDelays();
}
UpdatePistolDelays()
{
g_fPistolDelayDualies = GetConVarFloat(g_hPistolDelayDualies);
if (g_fPistolDelayDualies < 0.0) g_fPistolDelayDualies = 0.0;
else if (g_fPistolDelayDualies > 5.0) g_fPistolDelayDualies = 5.0;
g_fPistolDelaySingle = GetConVarFloat(g_hPistolDelaySingle);
if (g_fPistolDelaySingle < 0.0) g_fPistolDelaySingle = 0.0;
else if (g_fPistolDelaySingle > 5.0) g_fPistolDelaySingle = 5.0;
g_fPistolDelayIncapped = GetConVarFloat(g_hPistolDelayIncapped);
if (g_fPistolDelayIncapped < 0.0) g_fPistolDelayIncapped = 0.0;
else if (g_fPistolDelayIncapped > 5.0) g_fPistolDelayIncapped = 5.0;
}
public Hook_OnPostThinkPost(client)
{
// Human survivors only
if (!IsClientInGame(client) || IsFakeClient(client) || GetClientTeam(client) != 2) return;
new activeweapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if (!IsValidEdict(activeweapon)) return;
decl String:weaponname[64];
GetEdictClassname(activeweapon, weaponname, sizeof(weaponname));
if (strcmp(weaponname, "weapon_pistol") != 0) return;
new Float:old_value = GetEntPropFloat(activeweapon, Prop_Send, "m_flNextPrimaryAttack");
new Float:new_value = g_fNextAttack[client];
// Never accidentally speed up fire rate
if (new_value > old_value)
{
// PrintToChatAll("Readjusting delay: Old=%f, New=%f", old_value, new_value);
SetEntPropFloat(activeweapon, Prop_Send, "m_flNextPrimaryAttack", new_value);
}
}
public Action:Event_WeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (!IsClientInGame(client) || IsFakeClient(client) || GetClientTeam(client) != 2) return;
new activeweapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if (!IsValidEdict(activeweapon)) return;
decl String:weaponname[64];
GetEdictClassname(activeweapon, weaponname, sizeof(weaponname));
if (strcmp(weaponname, "weapon_pistol") != 0) return;
// new dualies = GetEntProp(activeweapon, Prop_Send, "m_hasDualWeapons");
if (GetEntProp(client, Prop_Send, "m_isIncapacitated"))
{
g_fNextAttack[client] = GetGameTime() + g_fPistolDelayIncapped;
}
// What is the difference between m_isDualWielding and m_hasDualWeapons ?
else if (GetEntProp(activeweapon, Prop_Send, "m_isDualWielding"))
{
g_fNextAttack[client] = GetGameTime() + g_fPistolDelayDualies;
}
else
{
g_fNextAttack[client] = GetGameTime() + g_fPistolDelaySingle;
}
}