PHP Code:
public int GetNearestEntity(int client, char[] classname)
{
int nearestEntity = -1;
float clientVecOrigin[3], entityVecOrigin[3];
//Get the distance between the first entity and client
float distance, nearestDistance = -1.0;
//Find all the entity and compare the distances
int entity = -1;
while ((entity = FindEntityByClassname(entity, classname)) != -1)
{
GetEntPropVector(entity, Prop_Data, "m_vecOrigin", entityVecOrigin);
distance = GetVectorDistance(clientVecOrigin, entityVecOrigin);
if (distance < nearestDistance || nearestDistance == -1.0)
{
nearestEntity = entity;
nearestDistance = distance;
}
}
return nearestEntity;
}
Simplyfied code and fixed errors ;)
__________________