2009-05-06 02:28:09 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-04-05 23:20:35 +02:00
|
|
|
* Zombie:Reloaded
|
2009-05-06 02:28:09 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: antistick.inc
|
|
|
|
* Type: Module
|
|
|
|
* Description: Antistick system.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Greyscale, Richard Helgeby
|
|
|
|
*
|
|
|
|
* 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/>.
|
2009-05-06 02:28:09 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
2009-04-05 23:20:35 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
/**
|
|
|
|
* @section Collision values.
|
|
|
|
*/
|
|
|
|
#define ANTISTICK_COLLISIONS_OFF 2
|
|
|
|
#define ANTISTICK_COLLISIONS_ON 5
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
2009-04-05 23:20:35 +02:00
|
|
|
/**
|
|
|
|
* @section Offsets relating to player hull dimensions.
|
|
|
|
*/
|
2009-04-29 01:58:41 +02:00
|
|
|
#define ANTISTICK_PLAYER_HULL_XY_OFFSET 32
|
|
|
|
#define ANTISTICK_PLAYER_HULL_Z_OFFSET 12
|
|
|
|
#define ANTISTICK_PLAYER_HULL_STACK_OFFSET 14
|
2009-04-05 23:20:35 +02:00
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
/**
|
|
|
|
* Variable to store antistick offset value.
|
|
|
|
*/
|
|
|
|
new g_iToolsCollisionGroup;
|
|
|
|
|
2009-04-05 23:20:35 +02:00
|
|
|
/**
|
2009-04-15 09:42:12 +02:00
|
|
|
* Handle to keep track of AntiStickTimer.
|
2009-05-14 02:28:26 +02:00
|
|
|
*/
|
2009-04-05 23:20:35 +02:00
|
|
|
new Handle:tAntiStick = INVALID_HANDLE;
|
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
/**
|
|
|
|
* Find antistick-specific offsets here.
|
|
|
|
*/
|
|
|
|
AntiStickOnOffsetsFound()
|
|
|
|
{
|
|
|
|
// If offset "m_CollisionGroup" can't be found, then stop the plugin.
|
|
|
|
g_iToolsCollisionGroup = FindSendPropInfo("CBaseEntity", "m_CollisionGroup");
|
|
|
|
if (g_iToolsCollisionGroup == -1)
|
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
LogEvent(false, LogType_Fatal, LOG_CORE_EVENTS, LogModule_Antistick, "Offsets", "Offset \"CBaseEntity::m_CollisionGroup\" was not found.");
|
2009-05-29 08:43:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 01:09:52 +02:00
|
|
|
/**
|
2009-04-21 02:03:35 +02:00
|
|
|
* Map is starting.
|
2009-05-14 02:28:26 +02:00
|
|
|
*/
|
2009-04-21 02:03:35 +02:00
|
|
|
AntiStickOnMapStart()
|
2009-04-17 01:09:52 +02:00
|
|
|
{
|
2009-04-21 02:03:35 +02:00
|
|
|
// Reset timer handle.
|
|
|
|
tAntiStick = INVALID_HANDLE;
|
2009-04-17 01:09:52 +02:00
|
|
|
}
|
|
|
|
|
2009-04-05 23:20:35 +02:00
|
|
|
/**
|
2009-04-21 02:03:35 +02:00
|
|
|
* The round is starting.
|
|
|
|
*/
|
|
|
|
AntiStickOnRoundStart()
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
2009-04-21 02:03:35 +02:00
|
|
|
// If timer is running, kill it.
|
2009-04-05 23:20:35 +02:00
|
|
|
if (tAntiStick != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tAntiStick);
|
|
|
|
}
|
|
|
|
|
2009-04-21 02:03:35 +02:00
|
|
|
// If antistick is disabled, then stop.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:antistick = GetConVarBool(g_hCvarsList[CVAR_ANTISTICK]);
|
2009-04-21 02:03:35 +02:00
|
|
|
if (!antistick)
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
2009-04-21 02:03:35 +02:00
|
|
|
return;
|
2009-04-05 23:20:35 +02:00
|
|
|
}
|
2009-04-21 02:03:35 +02:00
|
|
|
|
|
|
|
new Float:interval = GetConVarFloat(g_hCvarsList[CVAR_ANTISTICK_INTERVAL]);
|
|
|
|
tAntiStick = CreateTimer(interval, AntiStickTimer, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
2009-04-05 23:20:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-04-15 09:42:12 +02:00
|
|
|
* Checks if a player is currently stuck within another player.
|
2009-04-05 23:20:35 +02:00
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @return The client index of the other stuck player, -1 when
|
|
|
|
* player is not stuck.
|
2009-05-14 02:28:26 +02:00
|
|
|
*/
|
2009-04-05 23:20:35 +02:00
|
|
|
AntiStickIsStuck(client)
|
|
|
|
{
|
|
|
|
new Float:clientloc[3];
|
|
|
|
new Float:stuckloc[3];
|
|
|
|
|
|
|
|
GetClientAbsOrigin(client, clientloc);
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
// x = client index.
|
2009-04-16 05:30:26 +02:00
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
2009-04-15 09:42:12 +02:00
|
|
|
// Validate player is in-game, alive, and isn't the player being checked. ('client')
|
2009-04-05 23:20:35 +02:00
|
|
|
if (!IsClientInGame(x) || !IsPlayerAlive(x) || x == client)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetClientAbsOrigin(x, stuckloc);
|
|
|
|
|
|
|
|
// x-y plane distance formula: sqrt((x2-x1)^2 + (y2-y1)^2)
|
|
|
|
new Float:xydistance = SquareRoot(Pow(stuckloc[0] - clientloc[0], 2.0) + Pow(stuckloc[1] - clientloc[1], 2.0));
|
2009-04-29 01:58:41 +02:00
|
|
|
if (xydistance < ANTISTICK_PLAYER_HULL_XY_OFFSET)
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
|
|
|
if (clientloc[2] <= stuckloc[2])
|
|
|
|
{
|
|
|
|
new Float:eyeloc[3];
|
2009-04-24 05:02:19 +02:00
|
|
|
GetClientEyePosition(client, eyeloc);
|
2009-04-05 23:20:35 +02:00
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
// Get the distance between the eyes and feet and subtract the stack "view crush."
|
2009-04-29 01:58:41 +02:00
|
|
|
new Float:eyedistance = FloatAbs(eyeloc[2] - clientloc[2]) - ANTISTICK_PLAYER_HULL_STACK_OFFSET;
|
2009-04-05 23:20:35 +02:00
|
|
|
new Float:zdistance = FloatAbs(stuckloc[2] - clientloc[2]);
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
if (zdistance <= eyedistance + ANTISTICK_PLAYER_HULL_Z_OFFSET)
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-04-17 01:09:52 +02:00
|
|
|
* Timer callback, automatically unsticks players that are stuck together.
|
2009-05-14 02:28:26 +02:00
|
|
|
*/
|
2009-04-05 23:20:35 +02:00
|
|
|
public Action:AntiStickTimer(Handle:timer)
|
|
|
|
{
|
|
|
|
// x = client index
|
2009-04-16 05:30:26 +02:00
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
2009-04-15 09:42:12 +02:00
|
|
|
// Validate player is in-game and alive.
|
2009-04-05 23:20:35 +02:00
|
|
|
if (!IsClientInGame(x) || !IsPlayerAlive(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
// Stop if the player isn't stuck.
|
2009-04-05 23:20:35 +02:00
|
|
|
new stuckindex = AntiStickIsStuck(x);
|
|
|
|
if (stuckindex == -1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
if (AntiStickClientCollisionGroup(x, false))
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
AntiStickClientCollisionGroup(x, true, ANTISTICK_COLLISIONS_OFF);
|
2009-04-05 23:20:35 +02:00
|
|
|
CreateTimer(0.5, AntiStickSolidify, x, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
if (AntiStickClientCollisionGroup(stuckindex, false))
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
AntiStickClientCollisionGroup(stuckindex, true, ANTISTICK_COLLISIONS_OFF);
|
2009-04-05 23:20:35 +02:00
|
|
|
CreateTimer(0.5, AntiStickSolidify, stuckindex, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Repeated timer function.
|
|
|
|
* Re-solidifies a player being unstuck.
|
|
|
|
*
|
2009-04-15 09:42:12 +02:00
|
|
|
* @param timer The timer handle.
|
2009-04-15 11:27:03 +02:00
|
|
|
* @param client The client index.
|
2009-05-14 02:28:26 +02:00
|
|
|
*/
|
2009-04-15 11:27:03 +02:00
|
|
|
public Action:AntiStickSolidify(Handle:timer, any:client)
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
2009-04-15 09:42:12 +02:00
|
|
|
// Validate player is in-game, alive, and is being unstuck.
|
2009-04-29 01:58:41 +02:00
|
|
|
if (!IsClientInGame(client) || !IsPlayerAlive(client) || AntiStickClientCollisionGroup(client, false))
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
|
|
|
return Plugin_Stop;
|
|
|
|
}
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
// Stop if the player is still stuck.
|
2009-04-15 11:27:03 +02:00
|
|
|
if (AntiStickIsStuck(client) > -1)
|
2009-04-05 23:20:35 +02:00
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
AntiStickClientCollisionGroup(client, true, ANTISTICK_COLLISIONS_ON);
|
2009-04-05 23:20:35 +02:00
|
|
|
|
|
|
|
return Plugin_Stop;
|
|
|
|
}
|
2009-04-29 01:58:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set collision group flags on a client.
|
|
|
|
* @param client The client index.
|
|
|
|
* @param collisiongroup Collision group flag.
|
|
|
|
* @return The collision group on the client, -1 if applying collision group.
|
|
|
|
*/
|
|
|
|
AntiStickClientCollisionGroup(client, bool:apply = true, collisiongroup = 0)
|
|
|
|
{
|
|
|
|
if (apply)
|
|
|
|
{
|
|
|
|
SetEntData(client, g_iToolsCollisionGroup, collisiongroup, 1, true);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetEntData(client, g_iToolsCollisionGroup, 1);
|
2009-05-29 08:43:15 +02:00
|
|
|
}
|