Skip to content

Commit

Permalink
Merge pull request #19 from danzayau/2.1.0
Browse files Browse the repository at this point in the history
2.1.0
  • Loading branch information
danzayau authored Dec 7, 2019
2 parents 98e59c6 + 98f0fa6 commit 451b045
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ A SourceMod API focused on player movement in the form of a [function stock liba
* **Landing** - Leaving the air, including landing on the ground, grabbing a ladder and entering noclip.
* **Perfect Bunnyhop (Perf)** - When the player has jumped in the tick after landing and keeps their speed.
* **Jumpbug** - When the player is never seen as 'on ground' when bunnyhopping. This is achievable by uncrouching and jumping at the same time. A jumpbug results in unusual behaviour such as maintaining horizontal speed and not receiving fall damage.
* **Distbug** - A distbug can occur when a player lands close to the edge of a block. When calculating the landing position, the source engine will only consider either the horizontal or vertical speed on the very last tick, but not both. The GetNobugLandingOrigin calculates the correct landing position of the player based on his actual trajectory using all components of the velocity instead.
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/include/movement.inc
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,4 @@ methodmap MovementPlayer {
return Movement_GetNoclipping(this.ID);
}
}
}
}
17 changes: 16 additions & 1 deletion addons/sourcemod/scripting/include/movementapi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
When the player is never seen as 'on ground' when bunnyhopping. This is achievable by
uncrouching and jumping at the same time. A jumpbug results in unusual behaviour such
as maintaining horizontal speed and not receiving fall damage.
Distbug
A distbug can occur when a player lands close to the edge of a block. When calculating
the landing position, the source engine will only consider either the horizontal or
vertical speed on the very last tick, but not both. The GetNobugLandingOrigin native
calculates the correct landing position of the player based on his actual trajectory
using all components of the velocity instead.
*/


Expand Down Expand Up @@ -151,6 +158,14 @@ native int Movement_GetTakeoffTick(int client);
*/
native int Movement_GetTakeoffCmdNum(int client);

/**
* Gets a player's origin at the time of their last landing with the distbug fixed.
*
* @param client Client index.
* @param result Resultant vector.
*/
native void Movement_GetNobugLandingOrigin(int client, float result[3]);

/**
* Gets a player's origin at the time of their last landing.
*
Expand Down Expand Up @@ -358,4 +373,4 @@ public void __pl_movementapi_SetNTVOptional()
MarkNativeAsOptional("Movement_GetTurningRight");
MarkNativeAsOptional("Movement_GetMaxSpeed");
}
#endif
#endif
46 changes: 44 additions & 2 deletions addons/sourcemod/scripting/movementapi.sp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Plugin myinfo =
name = "MovementAPI",
author = "DanZay",
description = "Provides API focused on player movement",
version = "2.0.2",
version = "2.1.0",
url = "https://github.com/danzayau/MovementAPI"
};

Expand All @@ -27,6 +27,7 @@ bool gB_JustJumped[MAXPLAYERS + 1];

bool gB_Jumped[MAXPLAYERS + 1];
bool gB_HitPerf[MAXPLAYERS + 1];
float gF_NobugLandingOrigin[MAXPLAYERS + 1][3];
float gF_LandingOrigin[MAXPLAYERS + 1][3];
float gF_LandingVelocity[MAXPLAYERS + 1][3];
int gI_LandingTick[MAXPLAYERS + 1];
Expand Down Expand Up @@ -193,6 +194,7 @@ static void UpdateOnGround(
{
if (onGround && !oldOnGround)
{
NobugLandingOrigin(client, oldOrigin, oldVelocity, gF_NobugLandingOrigin[client]);
gF_LandingOrigin[client] = origin;
gF_LandingVelocity[client] = velocity;
gI_LandingTick[client] = tickcount;
Expand Down Expand Up @@ -263,4 +265,44 @@ static void UpdateTurning(int client, const float oldEyeAngles[3], const float e
gB_Turning[client] = eyeAngles[1] != oldEyeAngles[1];
gB_TurningLeft[client] = eyeAngles[1] < oldEyeAngles[1] - 180
|| eyeAngles[1] > oldEyeAngles[1] && eyeAngles[1] < oldEyeAngles[1] + 180;
}
}

static void NobugLandingOrigin(int client, const float oldOrigin[3], const float oldVelocity[3], float landingOrigin[3])
{
float firstTraceEndpoint[3], velocity[3];
float hullMin[3] = { -16.0, -16.0, 0.0 };
float hullMax[3] = { 16.0, 16.0, 0.0 };

velocity[0] = oldVelocity[0] * GetTickInterval();
velocity[1] = oldVelocity[1] * GetTickInterval();
velocity[2] = oldVelocity[2] * GetTickInterval();
AddVectors(oldOrigin, velocity, firstTraceEndpoint);

Handle trace = TR_TraceHullFilterEx(oldOrigin, firstTraceEndpoint, hullMin, hullMax, MASK_PLAYERSOLID, TraceEntityFilterPlayers, client);
if (!TR_DidHit(trace))
{
delete trace;

float secondTraceEndpoint[3];
velocity[2] -= Movement_GetGravity(client) * GetTickInterval();
AddVectors(firstTraceEndpoint, velocity, secondTraceEndpoint);

trace = TR_TraceHullFilterEx(firstTraceEndpoint, secondTraceEndpoint, hullMin, hullMax, MASK_PLAYERSOLID, TraceEntityFilterPlayers, client);
if (!TR_DidHit(trace))
{
// Invalidate the landing origin
landingOrigin[0] = 0.0 / 0.0;
landingOrigin[1] = 0.0 / 0.0;
landingOrigin[2] = 0.0 / 0.0;
delete trace;
return;
}
}

TR_GetEndPosition(landingOrigin, trace);

// Fix the offset.
landingOrigin[2] -= 0.03125;

delete trace;
}
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/movementapi/forwards.sp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ void Call_OnPlayerJump(int client, bool jumpbug)
Call_PushCell(client);
Call_PushCell(jumpbug);
Call_Finish();
}
}
8 changes: 7 additions & 1 deletion addons/sourcemod/scripting/movementapi/natives.sp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ void CreateNatives()
CreateNative("Movement_GetTakeoffSpeed", Native_GetTakeoffSpeed);
CreateNative("Movement_GetTakeoffTick", Native_GetTakeoffTick);
CreateNative("Movement_GetTakeoffCmdNum", Native_GetTakeoffCmdNum);
CreateNative("Movement_GetNobugLandingOrigin", Native_GetNobugLandingOrigin);
CreateNative("Movement_GetLandingOrigin", Native_GetLandingOrigin);
CreateNative("Movement_GetLandingVelocity", Native_GetLandingVelocity);
CreateNative("Movement_GetLandingSpeed", Native_GetLandingSpeed);
Expand Down Expand Up @@ -53,6 +54,11 @@ public int Native_GetTakeoffCmdNum(Handle plugin, int numParams)
return gI_TakeoffCmdNum[GetNativeCell(1)];
}

public int Native_GetNobugLandingOrigin(Handle plugin, int numParams)
{
SetNativeArray(2, gF_NobugLandingOrigin[GetNativeCell(1)], 3);
}

public int Native_GetLandingOrigin(Handle plugin, int numParams)
{
SetNativeArray(2, gF_LandingOrigin[GetNativeCell(1)], 3);
Expand Down Expand Up @@ -98,4 +104,4 @@ public int Native_GetMaxSpeed(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
return view_as<int>(GetMaxSpeed(client));
}
}

0 comments on commit 451b045

Please sign in to comment.