forked from UNLOZE/sm-plugins
SourceMod 1.10 and new OnEntitySpawned forward
This commit is contained in:
@@ -33,8 +33,6 @@ float g_flDuckDelta;
|
||||
int g_iTick[MAXPLAYERS+1];
|
||||
float g_flFrameTime[MAXPLAYERS+1];
|
||||
|
||||
bool g_bTouchingTrigger[MAXPLAYERS+1][2048];
|
||||
|
||||
int g_iButtons[MAXPLAYERS+1];
|
||||
float g_vVel[MAXPLAYERS+1][3];
|
||||
float g_vAngles[MAXPLAYERS+1][3];
|
||||
@@ -86,8 +84,6 @@ Handle g_hProcessMovementHookPre;
|
||||
Address g_IServerGameEnts;
|
||||
Handle g_hMarkEntitiesAsTouching;
|
||||
|
||||
bool g_bIsSurfMap;
|
||||
|
||||
bool g_bLateLoad;
|
||||
|
||||
int g_iLaserIndex;
|
||||
@@ -254,40 +250,16 @@ public void OnPluginStart()
|
||||
{
|
||||
if (IsClientInGame(client)) OnClientPutInServer(client);
|
||||
}
|
||||
|
||||
char classname[64];
|
||||
for (int entity = MaxClients+1; entity < sizeof(g_bTouchingTrigger[]); entity++)
|
||||
{
|
||||
if (!IsValidEntity(entity)) continue;
|
||||
GetEntPropString(entity, Prop_Data, "m_iClassname", classname, sizeof(classname));
|
||||
HookTrigger(entity, classname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
g_iLaserIndex = PrecacheModel("materials/sprites/laserbeam.vmt", true);
|
||||
|
||||
char map[PLATFORM_MAX_PATH];
|
||||
GetCurrentMap(map, sizeof(map));
|
||||
g_bIsSurfMap = StrContains(map, "surf_", false) == 0;
|
||||
}
|
||||
|
||||
public void OnEntityCreated(int entity, const char[] classname)
|
||||
{
|
||||
if (entity >= sizeof(g_bTouchingTrigger[])) return;
|
||||
HookTrigger(entity, classname);
|
||||
}
|
||||
|
||||
void HookTrigger(int entity, const char[] classname)
|
||||
{
|
||||
if (StrContains(classname, "trigger_") != -1)
|
||||
{
|
||||
SDKHook(entity, SDKHook_StartTouchPost, Hook_TriggerStartTouch);
|
||||
SDKHook(entity, SDKHook_EndTouchPost, Hook_TriggerEndTouch);
|
||||
}
|
||||
|
||||
if (StrContains(classname, "trigger_teleport") != -1)
|
||||
{
|
||||
SDKHook(entity, SDKHook_TouchPost, Hook_TriggerTeleportTouchPost);
|
||||
@@ -297,7 +269,6 @@ void HookTrigger(int entity, const char[] classname)
|
||||
public void OnClientConnected(int client)
|
||||
{
|
||||
g_iTick[client] = 0;
|
||||
for (int i = 0; i < sizeof(g_bTouchingTrigger[]); i++) g_bTouchingTrigger[client][i] = false;
|
||||
}
|
||||
|
||||
public void OnClientPutInServer(int client)
|
||||
@@ -306,17 +277,6 @@ public void OnClientPutInServer(int client)
|
||||
SDKHook(client, SDKHook_PostThink, Hook_PlayerPostThink);
|
||||
}
|
||||
|
||||
public Action Hook_TriggerStartTouch(int entity, int other)
|
||||
{
|
||||
if (1 <= other <= MaxClients)
|
||||
{
|
||||
g_bTouchingTrigger[other][entity] = true;
|
||||
DebugMsg(other, "StartTouch %i", entity);
|
||||
}
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
// TODO Would be nice to have IServerTools::FindEntityByName / CGlobalEntityList::FindEntityByName
|
||||
bool NameExists(const char[] targetname)
|
||||
{
|
||||
@@ -358,16 +318,6 @@ public void Hook_TriggerTeleportTouchPost(int entity, int other)
|
||||
DebugMsg(other, "Triggered teleport %i", entity);
|
||||
}
|
||||
|
||||
public Action Hook_TriggerEndTouch(int entity, int other)
|
||||
{
|
||||
if (1 <= other <= MaxClients)
|
||||
{
|
||||
g_bTouchingTrigger[other][entity] = false;
|
||||
DebugMsg(other, "EndTouch %i", entity);
|
||||
}
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public bool PlayerFilter(int entity, int mask)
|
||||
{
|
||||
return !(1 <= entity <= MaxClients);
|
||||
@@ -829,174 +779,6 @@ public void Hook_PlayerGroundEntChanged(int client)
|
||||
}
|
||||
}
|
||||
|
||||
bool DoTriggerjumpFix(int client, const float landingPoint[3], const float landingMins[3], const float landingMaxs[3])
|
||||
{
|
||||
/* if (!g_cvTriggerjump.BoolValue) return false;
|
||||
|
||||
// It's possible to land above a trigger but also in another trigger_teleport, have the teleport move you to
|
||||
// another location, and then the trigger jumping fix wouldn't fire the other trigger you technically landed above,
|
||||
// but I can't imagine a mapper would ever actually stack triggers like that.
|
||||
|
||||
float origin[3];
|
||||
GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", origin);
|
||||
|
||||
float landingMaxsBelow[3];
|
||||
landingMaxsBelow[0] = landingMaxs[0];
|
||||
landingMaxsBelow[1] = landingMaxs[1];
|
||||
landingMaxsBelow[2] = origin[2] - landingPoint[2];
|
||||
|
||||
ArrayList triggers = new ArrayList();
|
||||
|
||||
// Find triggers that are between us and the ground (using the bounding box quadrant we landed with if applicable).
|
||||
TR_EnumerateEntitiesHull(landingPoint, landingPoint, landingMins, landingMaxsBelow, true, AddTrigger, triggers);
|
||||
|
||||
bool didSomething = false;
|
||||
|
||||
for (int i = 0; i < triggers.Length; i++)
|
||||
{
|
||||
int trigger = triggers.Get(i);
|
||||
|
||||
// MarkEntitiesAsTouching always fires the Touch function even if it was already fired this tick.
|
||||
// In case that could cause side-effects, manually keep track of triggers we are actually touching
|
||||
// and don't re-touch them.
|
||||
if (g_bTouchingTrigger[client][trigger]) continue;
|
||||
|
||||
DebugMsg(client, "DO FIX: Trigger Jumping (entity %i)", trigger);
|
||||
|
||||
SDKCall(g_hMarkEntitiesAsTouching, g_IServerGameEnts, client, trigger);
|
||||
didSomething = true;
|
||||
}
|
||||
|
||||
delete triggers;
|
||||
|
||||
return didSomething;*/
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DoStairsFix(int client)
|
||||
{
|
||||
/* if (!g_cvStairs.BoolValue) return false;
|
||||
if (g_iLastTickPredicted[client] != g_iTick[client]) return false;
|
||||
|
||||
// This fix has undesirable side-effects on bhop. It is also very unlikely to help on bhop.
|
||||
if (!g_bIsSurfMap) return false;
|
||||
|
||||
// Let teleports take precedence (including teleports activated by the trigger jumping fix).
|
||||
if (g_iLastMapTeleportTick[client] == g_iTick[client]) return false;
|
||||
|
||||
// If moving upward, the player would never be able to slide up with any current position.
|
||||
if (g_vPreCollisionVelocity[client][2] > 0.0) return false;
|
||||
|
||||
// Stair step faces don't necessarily have to be completely vertical, but, if they are not,
|
||||
// sliding up them at high speed -- or even just walking up -- usually doesn't work.
|
||||
// Plus, it's really unlikely that there are actual stairs shaped like that.
|
||||
if (g_iLastCollisionTick[client] == g_iTick[client] && g_vCollisionNormal[client][2] == 0.0)
|
||||
{
|
||||
// Do this first and stop if we are moving slowly (less than 1 unit per tick).
|
||||
float velocity_dir[3];
|
||||
velocity_dir = g_vPreCollisionVelocity[client];
|
||||
velocity_dir[2] = 0.0;
|
||||
if (NormalizeVector(velocity_dir, velocity_dir) * g_flFrameTime[client] < 1.0) return false;
|
||||
|
||||
float mins[3], maxs[3];
|
||||
GetEntPropVector(client, Prop_Data, "m_vecMins", mins);
|
||||
GetEntPropVector(client, Prop_Data, "m_vecMaxs", maxs);
|
||||
|
||||
// We seem to have collided with a "wall", now figure out if it's a stair step.
|
||||
|
||||
// Look for ground below us
|
||||
float stepsize = GetEntPropFloat(client, Prop_Data, "m_flStepSize");
|
||||
|
||||
float end[3];
|
||||
end = g_vCollisionPoint[client];
|
||||
end[2] -= stepsize;
|
||||
|
||||
TR_TraceHullFilter(g_vCollisionPoint[client], end, mins, maxs, MASK_PLAYERSOLID, PlayerFilter);
|
||||
|
||||
if (TR_DidHit())
|
||||
{
|
||||
float nrm[3];
|
||||
TR_GetPlaneNormal(null, nrm);
|
||||
|
||||
// Ground below is not walkable, not stairs
|
||||
if (nrm[2] < MIN_STANDABLE_ZNRM) return false;
|
||||
|
||||
float start[3];
|
||||
TR_GetEndPosition(start);
|
||||
|
||||
// Find triggers that we would trigger if we did touch the ground here.
|
||||
ArrayList triggers = new ArrayList();
|
||||
|
||||
TR_EnumerateEntitiesHull(start, start, mins, maxs, true, AddTrigger, triggers);
|
||||
|
||||
for (int i = 0; i < triggers.Length; i++)
|
||||
{
|
||||
int trigger = triggers.Get(i);
|
||||
|
||||
if (SDKCall(g_hPassesTriggerFilters, trigger, client))
|
||||
{
|
||||
// We would have triggered something on the ground here, so we cant be sure the stairs fix is safe to do.
|
||||
// The most likely scenario here is this isn't stairs, but just a short ledge with a fail teleport in front.
|
||||
delete triggers;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
delete triggers;
|
||||
|
||||
// Now follow CGameMovement::StepMove behavior.
|
||||
|
||||
// Trace up
|
||||
end = start;
|
||||
end[2] += stepsize;
|
||||
TR_TraceHullFilter(start, end, mins, maxs, MASK_PLAYERSOLID, PlayerFilter);
|
||||
|
||||
if (TR_DidHit()) TR_GetEndPosition(end);
|
||||
|
||||
// Trace over (only 1 unit, just to find a stair step)
|
||||
start = end;
|
||||
AddVectors(start, velocity_dir, end);
|
||||
|
||||
TR_TraceHullFilter(start, end, mins, maxs, MASK_PLAYERSOLID, PlayerFilter);
|
||||
|
||||
if (TR_DidHit())
|
||||
{
|
||||
// The plane we collided with is too tall to be a stair step (i.e. it's a wall, not stairs).
|
||||
// Or possibly: the ceiling is too low to get on top of it.
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Trace downward
|
||||
start = end;
|
||||
end[2] -= stepsize;
|
||||
|
||||
TR_TraceHullFilter(start, end, mins, maxs, MASK_PLAYERSOLID, PlayerFilter);
|
||||
|
||||
if (!TR_DidHit()) return false; // Shouldn't happen
|
||||
|
||||
TR_GetPlaneNormal(null, nrm);
|
||||
|
||||
// Ground atop "stair" is not walkable, not stairs
|
||||
if (nrm[2] < MIN_STANDABLE_ZNRM) return false;
|
||||
|
||||
// It looks like we actually collided with a stair step.
|
||||
// Put the player just barely on top of the stair step we found and restore their speed
|
||||
TR_GetEndPosition(end);
|
||||
|
||||
DebugMsg(client, "DO FIX: Stair Sliding");
|
||||
|
||||
TeleportEntity(client, end, NULL_VECTOR, NULL_VECTOR);
|
||||
SetVelocity(client, g_vPreCollisionVelocity[client]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DoInclineCollisionFixes(int client, const float nrm[3])
|
||||
{
|
||||
if (!g_cvDownhill.BoolValue && g_cvUphill.IntValue != UPHILL_LOSS) return false;
|
||||
@@ -1186,17 +968,6 @@ public void Hook_PlayerPostThink(int client)
|
||||
}
|
||||
}
|
||||
|
||||
if (landed && TR_GetFraction() > 0.0)
|
||||
{
|
||||
DoTriggerjumpFix(client, landingPoint, landingMins, landingMaxs);
|
||||
|
||||
// Check if a trigger we just touched put us in the air (probably due to a teleport).
|
||||
if (GetEntityFlags(client) & FL_ONGROUND == 0) landed = false;
|
||||
}
|
||||
|
||||
// The stair sliding fix changes the outcome of this tick more significantly, so it doesn't really make sense to do incline fixes too.
|
||||
if (DoStairsFix(client)) return;
|
||||
|
||||
if (landed)
|
||||
{
|
||||
DoInclineCollisionFixes(client, nrm);
|
||||
@@ -1204,15 +975,7 @@ public void Hook_PlayerPostThink(int client)
|
||||
|
||||
DoTelehopFix(client);
|
||||
}
|
||||
/*
|
||||
public bool AddTrigger(int entity, ArrayList triggers)
|
||||
{
|
||||
TR_ClipCurrentRayToEntity(MASK_ALL, entity);
|
||||
if (TR_DidHit()) triggers.Push(entity);
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
bool TracePlayerBBoxForGround(const float origin[3], const float originBelow[3], float mins[3], float maxs[3])
|
||||
{
|
||||
// See CGameMovement::TracePlayerBBoxForGround()
|
||||
|
||||
Reference in New Issue
Block a user