All pastes #910915 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-02-20 09:35 UTC
rendered paste body
#ifdef CLIENT_DLL
	ConVar cl_attachedmodels( "cl_attachedmodels", "1", FCVAR_ARCHIVE );


	C_ClientAttachedModel* C_ClientAttachedModel::Create( const char *pszModelName, const char *attachmentName, CBaseEntity* pOwner )
	{
		C_ClientAttachedModel *pAttach = new C_ClientAttachedModel;

		if ( pAttach == NULL )
			return NULL;

		if ( pAttach->Initialize( pszModelName, attachmentName, pOwner ) == false )
			return NULL;

		return pAttach;
	}

	bool C_ClientAttachedModel::Initialize( const char *pszModelName, const char *attachmentName, CBaseEntity* pOwner )
	{
		if ( !pOwner )
			return false;

		if ( InitializeAsClientEntity( pszModelName, RENDER_GROUP_OPAQUE_ENTITY ) == false )
		{
			Release();
			return false;
		}

		int attachment = pOwner->LookupAttachment( attachmentName );

		SetParent( pOwner, attachment );

		SetOwnerEntity(pOwner);

		SetSolid( SOLID_NONE );
		SetMoveType( MOVETYPE_NONE );

		SetLocalOrigin( vec3_origin );
		SetLocalAngles( vec3_angle );

		AddEffects( EF_PARENT_ANIMATES );

		RemoveEFlags( EFL_USE_PARTITION_WHEN_NOT_SOLID );

		SetBodygroup( 1, 1 );

		m_bVisible = true;

		SetNextClientThink( gpGlobals->curtime );

		//m_fadeMinDist = 700.0;
		//m_fadeMaxDist = 768.0;

		return true;
	}

	void C_ClientAttachedModel::ClientThink()
	{
		if ( (GetOwnerEntity() == NULL) ||
			((GetMoveParent() != GetOwnerEntity()) || (GetOwnerEntity()->IsAlive() == false)) )
		{
			m_bVisible = false;
			return;
		}

		SetNextClientThink( gpGlobals->curtime );
	}

	int C_ClientAttachedModel::DrawModel( int flags )
	{
		C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

		if ( !m_bVisible )
		{
			return 0;
		}
		else if ( GetOwnerEntity() == pPlayer )
		{
			if ( !input->CAM_IsThirdPerson() )
				return 0;
		}
		else if ( (pPlayer->GetObserverMode() == OBS_MODE_IN_EYE) && (pPlayer->GetObserverTarget() == GetOwnerEntity()) )
		{
			return 0;
		}

		return BaseClass::DrawModel(flags);
	}

#endif