If I can make it better let me know
almost totally inspired and based on code from this forum
# requires SMLib
Code:
/**
* Check if there is something visible between the player and the entity.
*
* @param client client entity index
* @param entity entity index
* @param Float:maxdistance max distance to check if specified
* otherwise check in infinited distance
* @param bool:FromEyePosition determine if start position will be from eyes or AbsOrigin
*
* @return true if visible, false if not
*/
stock bool:IsEntVisible(client,entity,const Float:maxdistance=0.0,const bool:FromEyePosition=false)
{
if((Entity_GetDistance(client,entity)>maxdistance)&&(maxdistance>0.0)) return false //if maxdistance used (!0.0) and distance longer return 0
new Float:vClientOrigin[3],Float:vEntOrigin[3]
FromEyePosition ? GetClientEyePosition(client,vClientOrigin) : Entity_GetAbsOrigin(client,vClientOrigin)
Entity_GetAbsOrigin(entity,vEntOrigin)
//Check for colliding entities
new Handle:TrHandle=TR_TraceRayFilterEx(vClientOrigin, vEntOrigin, MASK_VISIBLE_AND_NPCS,RayType_EndPoint, TraceRayDontHitSelf, client)
new TRIndex
if (TR_DidHit(TrHandle))
{
TRIndex = TR_GetEntityIndex(TrHandle)
}
return bool:(TRIndex==entity)
}
public bool:TraceRayDontHitSelf(entity, mask, any:data)
{
if(entity == data) // Check if the TraceRay hit the itself.
{
return false // Don't let the entity be hit
}
return true // It didn't hit itself
}