Skip to content

Commit c127ac0

Browse files
committed
Added CS:GO support.
1 parent 49ef2d0 commit c127ac0

File tree

2 files changed

+71
-8
lines changed

2 files changed

+71
-8
lines changed

noslide.zip

-18.2 KB
Binary file not shown.

scripting/noslide.sp

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#include <sourcemod>
2222
#include <clientprefs>
2323
#include <sdktools>
24+
#include <sdkhooks>
2425

2526
#undef REQUIRE_PLUGIN
2627
#include <shavit>
2728

28-
#define NOSLIDE_VERSION "1.0"
29+
#define NOSLIDE_VERSION "1.1"
2930

3031
// Uncommenting will result in an unnecessary message per land.
3132
// #define DEBUG
@@ -55,13 +56,19 @@ bool gB_Enabled = false;
5556
#endif
5657

5758
// cache
59+
ConVar sv_friction = null;
60+
float gF_DefaultFriction = 4.0;
61+
char gS_DefaultFriction[16];
62+
63+
EngineVersion gEV_Type;
5864
bool gB_Shavit = false;
5965
bool gB_Late = false;
6066
float gF_Tickrate = 0.01; // 100 tickrate.
6167
any gA_StyleSettings[STYLE_LIMIT][STYLESETTINGS_SIZE];
6268
int gBS_Style[MAXPLAYERS+1];
6369
bool gB_EnabledPlayers[MAXPLAYERS+1];
6470
int gI_GroundTicks[MAXPLAYERS+1];
71+
bool gB_StuckFriction[MAXPLAYERS+1];
6572

6673
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
6774
{
@@ -77,6 +84,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
7784

7885
public void OnPluginStart()
7986
{
87+
gEV_Type = GetEngineVersion();
88+
8089
gH_NoslideCookie = RegClientCookie("noslide_enabled", "Noslide settings", CookieAccess_Protected);
8190

8291
gCV_Enabled = CreateConVar("noslide_enabled", "0", "Is noslide enabled?\nIt's recommended to set to 0 as default,\nbut use map-configs to enable it for specific maps.\n\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 2.0);
@@ -88,7 +97,6 @@ public void OnPluginStart()
8897
RegConsoleCmd("sm_kz", Command_Noslide, "Toggles noslide. Alias for sm_noslide.");
8998
RegConsoleCmd("sm_kzmode", Command_Noslide, "Toggles noslide. Alias for sm_noslide.");
9099

91-
gF_Tickrate = GetTickInterval();
92100
gB_Shavit = LibraryExists("shavit");
93101

94102
if(gB_Late)
@@ -107,6 +115,25 @@ public void OnPluginStart()
107115
Shavit_OnStyleConfigLoaded(-1);
108116
}
109117
}
118+
119+
sv_friction = FindConVar("sv_friction");
120+
sv_friction.Flags &= ~(FCVAR_NOTIFY | FCVAR_REPLICATED);
121+
sv_friction.GetString(gS_DefaultFriction, 16);
122+
gF_DefaultFriction = sv_friction.FloatValue;
123+
}
124+
125+
public void OnMapStart()
126+
{
127+
gF_Tickrate = GetTickInterval();
128+
}
129+
130+
public void OnConfigsExecuted()
131+
{
132+
if(sv_friction != null)
133+
{
134+
sv_friction.GetString(gS_DefaultFriction, 16);
135+
gF_DefaultFriction = sv_friction.FloatValue;
136+
}
110137
}
111138

112139
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
@@ -133,11 +160,25 @@ public void OnLibraryRemoved(const char[] name)
133160
public void OnClientPutInServer(int client)
134161
{
135162
gI_GroundTicks[client] = 3;
163+
gB_StuckFriction[client] = false;
136164

137165
if(!AreClientCookiesCached(client))
138166
{
139167
gB_EnabledPlayers[client] = false;
140168
}
169+
170+
if(gEV_Type == Engine_CSGO)
171+
{
172+
SDKHook(client, SDKHook_PreThinkPost, PreThinkPost);
173+
}
174+
}
175+
176+
public void PreThinkPost(int client)
177+
{
178+
if(IsPlayerAlive(client))
179+
{
180+
sv_friction.FloatValue = (gB_StuckFriction[client])? 50.0:gF_DefaultFriction;
181+
}
141182
}
142183

143184
public void OnClientCookiesCached(int client)
@@ -214,28 +255,41 @@ public Action OnPlayerRunCmd(int client, int &buttons)
214255
return Plugin_Continue;
215256
}
216257

217-
if(!gB_EnabledPlayers[client] || (gB_Shavit && !gA_StyleSettings[gBS_Style[client]][bEasybhop]))
258+
if(!gB_EnabledPlayers[client] || (gB_Shavit && !gA_StyleSettings[gBS_Style[client]][bEasybhop]) || (buttons & IN_JUMP) > 0)
218259
{
219260
return Plugin_Continue;
220261
}
221262

222263
float fStamina = GetEntPropFloat(client, Prop_Send, "m_flStamina");
223264

265+
#if defined DEBUG
266+
// PrintToChat(client, "m_flFriction: %f", GetEntPropFloat(client, Prop_Send, "m_flFriction"));
267+
#endif
268+
224269
// Noslide when a jump is imperfect. Your jump is only perfect when you jump at the same tick you land!
225-
if(++gI_GroundTicks[client] == 2 && fStamina <= 350.0) // 350.0 is a sweetspoot for me.
270+
if(++gI_GroundTicks[client] == ((gEV_Type == Engine_CSS)? 3:5) && (gEV_Type != Engine_CSS || fStamina <= 350.0)) // 350.0 is a sweetspoot for me.
226271
{
227-
SetEntPropFloat(client, Prop_Send, "m_flStamina", 1320.0); // 1320.0 is highest stamina in CS:S.
272+
if(gEV_Type == Engine_CSS)
273+
{
274+
SetEntPropFloat(client, Prop_Send, "m_flStamina", 1320.0); // 1320.0 is highest stamina in CS:S.
275+
}
276+
277+
else
278+
{
279+
gB_StuckFriction[client] = true;
280+
sv_friction.ReplicateToClient(client, "50");
281+
}
228282

229283
DataPack pack = new DataPack();
230284
pack.WriteCell(GetClientSerial(client));
231285
pack.WriteFloat(fStamina);
232286

233-
CreateTimer((gF_Tickrate * 5), Timer_ApplyNewStamina, pack, TIMER_FLAG_NO_MAPCHANGE);
287+
CreateTimer((gEV_Type == Engine_CSS)? (gF_Tickrate * 5):gF_Tickrate, Timer_ApplyNewStamina, pack, TIMER_FLAG_NO_MAPCHANGE);
234288

235289
#if defined DEBUG
236290
if(gB_Shavit)
237291
{
238-
Shavit_PrintToChat(client, "Applied new stamina.");
292+
Shavit_PrintToChat(client, "Applied new %s.", (gEV_Type == Engine_CSS)? "stamina":"friction");
239293
}
240294
#endif
241295
}
@@ -254,7 +308,16 @@ public Action Timer_ApplyNewStamina(Handle timer, DataPack data)
254308

255309
if(client != 0)
256310
{
257-
SetEntPropFloat(client, Prop_Send, "m_flStamina", fStamina);
311+
if(gEV_Type == Engine_CSS)
312+
{
313+
SetEntPropFloat(client, Prop_Send, "m_flStamina", fStamina);
314+
}
315+
316+
else
317+
{
318+
sv_friction.ReplicateToClient(client, gS_DefaultFriction);
319+
gB_StuckFriction[client] = false;
320+
}
258321
}
259322

260323
return Plugin_Stop;

0 commit comments

Comments
 (0)