Extract function ZTelePlayerWalkedTooFar.
This commit is contained in:
parent
c149549540
commit
f4a2f151af
|
@ -377,38 +377,23 @@ public Action ZTeleCommand(int client, int argc)
|
||||||
*/
|
*/
|
||||||
public Action ZTeleTimer(Handle timer, int client)
|
public Action ZTeleTimer(Handle timer, int client)
|
||||||
{
|
{
|
||||||
// If client leaves, then stop timer.
|
|
||||||
if (!IsClientInGame(client))
|
if (!IsClientInGame(client))
|
||||||
{
|
{
|
||||||
|
// Client has left the game.
|
||||||
|
tZTele[client] = INVALID_HANDLE;
|
||||||
return Plugin_Stop;
|
return Plugin_Stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zteleautocancel = GetConVarBool(g_hCvarsList[CVAR_ZTELE_AUTOCANCEL]);
|
if (ZTelePlayerWalkedTooFar(client))
|
||||||
if (zteleautocancel)
|
|
||||||
{
|
{
|
||||||
// If client has been running around after using ZTele, then stop timer.
|
// Abort teleport.
|
||||||
float vecClient[3];
|
int maxDistanceInFeet = RoundToNearest(ZTeleGetAutoCancelDistance());
|
||||||
GetClientAbsOrigin(client, vecClient);
|
|
||||||
|
|
||||||
float distance = GetVectorDistance(vecClient, g_vecZTeleOrigin[client]);
|
TranslationPrintCenterText(client, "ZTele autocancel centertext");
|
||||||
float autocanceldistance = GetConVarFloat(g_hCvarsList[CVAR_ZTELE_AUTOCANCEL_DISTANCE]);
|
TranslationPrintToChat(client, "ZTele autocancel text", maxDistanceInFeet);
|
||||||
|
|
||||||
// Convert cvar units
|
tZTele[client] = INVALID_HANDLE;
|
||||||
float unitdistance = ZRConvertUnitsFloat(autocanceldistance, CONVERSION_FEET_TO_UNITS);
|
return Plugin_Stop;
|
||||||
|
|
||||||
// Check if distance has been surpassed.
|
|
||||||
if (distance > unitdistance)
|
|
||||||
{
|
|
||||||
// Reset timer handle.
|
|
||||||
tZTele[client] = INVALID_HANDLE;
|
|
||||||
|
|
||||||
// Tell client teleport has been cancelled.
|
|
||||||
TranslationPrintCenterText(client, "ZTele autocancel centertext");
|
|
||||||
TranslationPrintToChat(client, "ZTele autocancel text", RoundToNearest(autocanceldistance));
|
|
||||||
|
|
||||||
// Stop timer.
|
|
||||||
return Plugin_Stop;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrement time left.
|
// Decrement time left.
|
||||||
|
@ -514,4 +499,31 @@ int ZTeleGetClientDelay(int client)
|
||||||
InfectIsClientInfected(client) ? ZTeleGetZombieDelay() : ZTeleGetHumanDelay();
|
InfectIsClientInfected(client) ? ZTeleGetZombieDelay() : ZTeleGetHumanDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ZTeleIsAutoCancelEnabled()
|
||||||
|
{
|
||||||
|
return GetConVarBool(g_hCvarsList[CVAR_ZTELE_AUTOCANCEL]);
|
||||||
|
}
|
||||||
|
|
||||||
|
float ZTeleGetAutoCancelDistance()
|
||||||
|
{
|
||||||
|
return GetConVarFloat(g_hCvarsList[CVAR_ZTELE_AUTOCANCEL_DISTANCE]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZTelePlayerWalkedTooFar(int client)
|
||||||
|
{
|
||||||
|
if (!ZTeleIsAutoCancelEnabled())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float clientPosition[3];
|
||||||
|
GetClientAbsOrigin(client, clientPosition);
|
||||||
|
|
||||||
|
float clientDistance = GetVectorDistance(clientPosition, g_vecZTeleOrigin[client]);
|
||||||
|
float maxDistanceInFeet = ZTeleGetAutoCancelDistance();
|
||||||
|
float maxDistance = ZRConvertUnitsFloat(maxDistanceInFeet, CONVERSION_FEET_TO_UNITS);
|
||||||
|
|
||||||
|
return clientDistance > maxDistance;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma newdecls optional
|
#pragma newdecls optional
|
||||||
|
|
Loading…
Reference in New Issue
Block a user