From 0f19ab08cf8a7966196fe7d2b45b0e89e72e64ef Mon Sep 17 00:00:00 2001 From: jenz Date: Mon, 9 Jan 2023 22:33:51 +0100 Subject: [PATCH] added check to prevent from teleporting player if they would get stuck --- zombie_hunting_respawn/zh_respawn_stop.sp | 35 +++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/zombie_hunting_respawn/zh_respawn_stop.sp b/zombie_hunting_respawn/zh_respawn_stop.sp index 3b537a39..53f73f48 100644 --- a/zombie_hunting_respawn/zh_respawn_stop.sp +++ b/zombie_hunting_respawn/zh_respawn_stop.sp @@ -88,10 +88,19 @@ public Action ZR_OnClientRespawn(&client, &ZR_RespawnCondition:condition) int total_nearest = -1; for (int i = 1; i <= MaxClients; i++) { + //if player would get stuck being teleported dont teleport them to this player + if (!IsValidClient(i) || !IsPlayerAlive(i)) + { + continue; + } + if (IsPlayerStuck(i) != -1) + { + continue; + } float nearestdistance = -1.0; int nearest = -1; for (int j = 1; j <= MaxClients; j++) - if (IsValidClient(i) && IsPlayerAlive(i) && IsValidClient(j) && IsPlayerAlive(j) && GetClientTeam(i) != GetClientTeam(j) && GetClientTeam(i) == 3) + if (IsValidClient(j) && IsPlayerAlive(j) && GetClientTeam(i) != GetClientTeam(j) && GetClientTeam(i) == 3) { float pos[3]; GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); @@ -102,7 +111,7 @@ public Action ZR_OnClientRespawn(&client, &ZR_RespawnCondition:condition) nearestdistance = dist_target; } } - //the closest enemy to this player is further away than previous player + //the closest enemy to this player is further away than previous players closest enemy if (nearestdistance > total_furthest_distance) { total_furthest_distance = nearestdistance; @@ -117,6 +126,28 @@ public Action ZR_OnClientRespawn(&client, &ZR_RespawnCondition:condition) return Plugin_Continue; } +stock int IsPlayerStuck(int client) { + float vecMin[3]; + float vecMax[3]; + float vecOrigin[3]; + + GetClientMins(client, vecMin); + GetClientMaxs(client, vecMax); + vecMax[2] = 63.0; + vecMin[2] += 1.0; + GetClientAbsOrigin(client, vecOrigin); + + TR_TraceHullFilter(vecOrigin, vecOrigin, vecMin, vecMax, MASK_PLAYERSOLID, TraceRayDontHitPlayerAndWorld); + return TR_GetEntityIndex(); +} + +public bool TraceRayDontHitPlayerAndWorld(int entityhit, int mask) { + return entityhit>MaxClients +} +public bool TraceRayHitOnlyEnt(int entityhit, int mask, any data) { + return entityhit==data; +} + public void OnClientPostAdminCheck(int client) { client_target[client] = 0;