コード例 #1
0
C_BaseEntity *CHUDBlockHealth::ProcessTarget( void )
{
	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();

	if ( !pPlayer )
		return NULL;

	// Get our target's ent index
	int iEntIndex = pPlayer->GetIDTarget();

	// Didn't find one?
	if ( !iEntIndex )
	{
		// Check to see if we should clear our ID
		if ( m_flLastChangeTime && (gpGlobals->curtime > (m_flLastChangeTime + 0.5)) )
		{
			m_flLastChangeTime = 0;
			m_iLastEntIndex = 0;
			m_bBlockInTarget = false;
		}
		else
		{
			// Keep re-using the old one
			iEntIndex = m_iLastEntIndex;
		}
	}
	else
	{
		m_flLastChangeTime = gpGlobals->curtime;
	}

	if ( iEntIndex )
	{
		// set up the vectors and traceline
		trace_t tr;
		Vector	vecStart, vecStop, vecDir;

		// get the angles
		AngleVectors( pPlayer->EyeAngles(), &vecDir );

		// get the vectors
		vecStart = pPlayer->EyePosition();
		vecStop = vecStart + vecDir * BLOCK_HINT_DISTANCE;

		// do the traceline
		UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NPC, &tr );

		C_BaseEntity *pEntity = tr.m_pEnt;

		// check to see if we found a block
		if ( !pEntity )
			return NULL;

		return pEntity;
	}

	return NULL;
}
コード例 #2
0
// CODE DUPLICATION BELOW. FIXME!
C_BaseEntity *ProcessTarget()
{
	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();

	if ( !pPlayer )
		return NULL;

	// Get our target's ent index
	int iEntIndex = pPlayer->GetIDTarget();

	// Didn't find one?
	if ( !iEntIndex )
	{
		return NULL;
	}

	if ( iEntIndex )
	{
		// set up the vectors and traceline
		trace_t tr;
		Vector	vecStart, vecStop, vecDir;

		// get the angles
		AngleVectors( pPlayer->EyeAngles( ), &vecDir );

		// get the vectors
		vecStart = pPlayer->EyePosition();
		vecStop = vecStart + vecDir * 1024;

		// do the traceline
		UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NPC, &tr );

		C_BaseEntity *pEntity = tr.m_pEnt;

		// check to see if we found a block
		if ( !pEntity )
			return NULL;

		return pEntity;
	}

	return NULL;
}