Hi there. I need a function to find people at a given distance. But this should not find people, ignoring props and walls. So i can’t just use GetVectorDistance. If there is something between the players, then it needs to be eliminated
I used this function from sentry_owner plugin to find first player in range:
Code:
stock FindFirstTargetInRange(client, Float:vAngle[3], Float:vEntPosition[3], Float:entHeight = 60.0)
{
new Float:vClientPosition[3];
GetEntPropVector(client, Prop_Send, "m_vecOrigin", vEntPosition);
vEntPosition[2] += entHeight;
new Float:fDistance[MAXPLAYERS + 1];
new iTager[MAXPLAYERS + 1];
new numb = 0;
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(client) != GetClientTeam(i))
{
GetClientEyePosition(i, vClientPosition);
fDistance[numb] = GetVectorDistance(vClientPosition, vEntPosition, false);
if(fDistance[numb] <= 9000000 && fDistance[numb] > 50)
{
iTager[numb] = i;
numb++;
}
}
}
new zombie = GetZombieMinDistance(iTager, fDistance, numb+1);
if(zombie < 1 || !IsClientInGame(zombie) || !IsPlayerAlive(zombie))
{
return (-1);
}
GetClientEyePosition(zombie, vClientPosition);
vClientPosition[2] -= 10.0;
MakeVectorFromPoints(vEntPosition, vClientPosition, vAngle);
vClientPosition[2] += 10.0;
//NormalizeVector(vAngle, vAngle);
GetVectorAngles(vAngle, vAngle);
new Handle:trace = TR_TraceRayFilterEx(vEntPosition, vClientPosition, MASK_SHOT, RayType_EndPoint, TraceASDF, client);
if(!TR_DidHit(trace))
{
CloseHandle(trace);
return (zombie);
}
CloseHandle(trace);
return (-1);
}
GetZombieMinDistance(clients[], Float:distance[], max_clients)
{
if(max_clients < 1)
{
return -1;
}
new Float:min_distance = 999999999.0;
new zombie = -1;
for(new i = 0; i < max_clients; i++)
{
// 999999999 > 10000000
if(min_distance > distance[i])
{
if(distance[i] <= 9000000009 && distance[i] > 50)
{
min_distance = distance[i];
zombie = clients[i];
}
}
}
return zombie;
}
public bool:TraceASDF(entity, mask, any:data)
{
return (data != entity);
}
But it doesn’t work well, because it is designed for a turret that does such a check in a repeating timer. In most cases, this function does not notice the player, even if he stands at point blank range and there is nothing between the players. Can someone tell me how to make such a function? Thanks in advance