View Single Post
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-22-2011 , 04:59   Re: fm_is_ent_visible (Replace with FUN/Engine/FM)
Reply With Quote #10

ExecuteHam(Ham_FVisible, id, idOther)

This will call :
Code:
//=========================================================
// FVisible - returns true if a line can be traced from
// the caller's eyes to the target
//=========================================================
BOOL CBaseEntity :: FVisible ( CBaseEntity *pEntity )
{
	TraceResult tr;
	Vector		vecLookerOrigin;
	Vector		vecTargetOrigin;
	
	if (FBitSet( pEntity->pev->flags, FL_NOTARGET ))
		return FALSE;

	// don't look through water
	if ((pev->waterlevel != 3 && pEntity->pev->waterlevel == 3) 
		|| (pev->waterlevel == 3 && pEntity->pev->waterlevel == 0))
		return FALSE;

	vecLookerOrigin = pev->origin + pev->view_ofs;//look through the caller's 'eyes'
	vecTargetOrigin = pEntity->EyePosition();

	UTIL_TraceLine(vecLookerOrigin, vecTargetOrigin, ignore_monsters, ignore_glass, ENT(pev)/*pentIgnore*/, &tr);
	
	if (tr.flFraction != 1.0)
	{
		return FALSE;// Line of sight is not established
	}
	else
	{
		return TRUE;// line of sight is valid.
	}
}
It's similar to fm_ stock :
Code:
stock bool:fm_is_ent_visible(index, entity, ignoremonsters = 0) {     new Float:start[3], Float:dest[3];     pev(index, pev_origin, start);     pev(index, pev_view_ofs, dest);     xs_vec_add(start, dest, start);     pev(entity, pev_origin, dest);     engfunc(EngFunc_TraceLine, start, dest, ignoremonsters, index, 0);     new Float:fraction;     get_tr2(0, TR_flFraction, fraction);     if (fraction == 1.0 || get_tr2(0, TR_pHit) == entity)         return true;     return false; }
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline