From 1b2d2e48ff415df283f1f492930ab5b106efae4b Mon Sep 17 00:00:00 2001 From: xen Date: Tue, 7 Mar 2023 19:09:31 +0200 Subject: [PATCH] FixPlayerGravity: Rework ladder checking logic to be more robust --- .../scripting/fixplayergravity.sp | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/FixPlayerGravity/scripting/fixplayergravity.sp b/FixPlayerGravity/scripting/fixplayergravity.sp index 48a535f0..465c1e19 100644 --- a/FixPlayerGravity/scripting/fixplayergravity.sp +++ b/FixPlayerGravity/scripting/fixplayergravity.sp @@ -56,23 +56,29 @@ public void OnGameFrame() // They're on a ladder, ignore current gravity modifier if (!g_bLadder[client]) g_bLadder[client] = true; + + continue; } - else + + // Now that they're off, restore it + if (g_bLadder[client]) { - if (g_bLadder[client]) - { - // Now that they're off, restore it - g_bLadder[client] = false; - SetEntityGravity(client, g_flClientGravity[client]); - } - - g_flClientGravity[client] = GetEntityGravity(client); + RequestFrame(RestoreGravity, client); + continue; } - float flClientActualGravity = g_flClientGravity[client] * flSVGravity; + float flClientGravity = GetEntityGravity(client); + + // Gamemovement treats 0.0 gravity as 1.0 + if (flClientGravity != 0.0) + g_flClientGravity[client] = flClientGravity; + else + flClientGravity = 1.0; // Some maps change sv_gravity while clients already have modified gravity // So we store the actual calculated gravity to catch such cases + float flClientActualGravity = flClientGravity * flSVGravity; + if (flClientActualGravity != g_flClientActualGravity[client]) { char szGravity[8]; @@ -84,6 +90,12 @@ public void OnGameFrame() } } +public void RestoreGravity(int client) +{ + g_bLadder[client] = false; + SetEntityGravity(client, g_flClientGravity[client]); +} + public void ResetGravityAll() { char szGravity[8];