Raised This Month: $ Target: $400
 0% 

bool:IsEntVisible


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
grankee
Member
Join Date: Jun 2008
Old 11-23-2015 , 16:47   bool:IsEntVisible
Reply With Quote #1

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
}

Last edited by grankee; 11-27-2015 at 12:42.
grankee is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode