Sources/CryGame C++/Solution1/CryGame/ScriptObjectVehicle.cpp
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*! Attaches a player to the vehicle, (so he is able to drive it IF bDriving).
		@param nPlayerId id of the player which should be attached (int)
		@param bDriving  if 1-set driver, if 0-passenger  

*/
Attaches a player to the vehicle, (so he is able to drive it IF bDriving).
@param nPlayerId id of the player which should be attached (int)
@param bDriving  if 1-set driver, if 0-passenger
Attaches a player to the vehicle ( so he is able to drive it IF bDriving ) . @param nPlayerId id of the player which should be attached ( int ) @param bDriving if 1 - set driver if 0 - passenger
int CScriptObjectVehicle::SetUser(IFunctionHandler *pH)
{
	CHECK_PARAMETERS(5);
	int parCount = pH->GetParamCount();
	ILog *pLog=m_pVehicle->GetGame()->GetSystem()->GetILog();
	int nPlayerid;
	pH->GetParam(1,nPlayerid);	
	const char *szHelperName;
		if (!pH->GetParam(2,szHelperName))	
		szHelperName=NULL;	
	const char * szAnimName;
	if (!pH->GetParam(3,szAnimName))
		szAnimName=NULL;
	CPlayer::eInVehiclestate vehicleState = CPlayer::PVS_PASSENGER;
	if (parCount>3)
		pH->GetParam(4,(int&)vehicleState);
	int iSlot=0;
	pH->GetParam(5,iSlot);
	if (!szHelperName)
	{
		pLog->Log("/003 CScriptObjectVehicle: Helper not specified");
		return pH->EndFunction();
	}
	IEntity		*pEntity = m_pEntitySystem->GetEntity(nPlayerid);	
	{
		m_pVehicle->GetEntity()->Bind(nPlayerid,iSlot);
		Vec3 hPos = Vec3(0,0,180);
		pEntity->SetAngles(hPos);
		m_pVehicle->GetEntity()->GetHelperPosition(szHelperName, hPos, true);
		pEntity->SetPos( hPos, false );
		pEntity->ResetAnimations(0);
	}
	CPlayer *pPlayer=NULL;
	if (pEntity->GetContainer()) 
		pEntity->GetContainer()->QueryContainerInterface(CIT_IPLAYER,(void**) &pPlayer);
	if (!pPlayer)
	{
		pLog->Log("/004 CScriptObjectVehicle::SetUser trying to set nonplayer as user");
		return pH->EndFunction();
	}
	pPlayer->m_AnimationSystemEnabled = 0;
	pPlayer->EnterVehicle(m_pVehicle, vehicleState, szHelperName);
	pEntity->ActivatePhysics( false );
	pEntity->ResetAnimations(0);
	if (szAnimName)
		pEntity->StartAnimation(0,szAnimName, 0,.15f);
	IAIObject *pObj=pEntity->GetAI();
	return pH->EndFunction(); 
}
int CScriptObjectVehicle :: SetUser ( IFunctionHandler * pH ) { CHECK_PARAMETERS ( 5 ) ; int parCount = pH -> GetParamCount ( ) ; ILog * pLog = m_pVehicle -> GetGame ( ) -> GetSystem ( ) -> GetILog ( ) ; int nPlayerid ; pH -> GetParam ( 1 , nPlayerid ) ; const char * szHelperName ; if ( ! pH -> GetParam ( 2 , szHelperName ) ) szHelperName = NULL ; const char * szAnimName ; if ( ! pH -> GetParam ( 3 , szAnimName ) ) szAnimName = NULL ; CPlayer :: eInVehiclestate vehicleState = CPlayer :: PVS_PASSENGER ; if ( parCount > 3 ) pH -> GetParam ( 4 , ( int & ) vehicleState ) ; int iSlot = 0 ; pH -> GetParam ( 5 , iSlot ) ; if ( ! szHelperName ) { pLog -> Log ( " " ) ; return pH -> EndFunction ( ) ; } IEntity * pEntity = m_pEntitySystem -> GetEntity ( nPlayerid ) ; { m_pVehicle -> GetEntity ( ) -> Bind ( nPlayerid , iSlot ) ; Vec3 hPos = Vec3 ( 0 , 0 , 180 ) ; pEntity -> SetAngles ( hPos ) ; m_pVehicle -> GetEntity ( ) -> GetHelperPosition ( szHelperName , hPos , true ) ; pEntity -> SetPos ( hPos , false ) ; pEntity -> ResetAnimations ( 0 ) ; } CPlayer * pPlayer = NULL ; if ( pEntity -> GetContainer ( ) ) pEntity -> GetContainer ( ) -> QueryContainerInterface ( CIT_IPLAYER , ( void * * ) & pPlayer ) ; if ( ! pPlayer ) { pLog -> Log ( " " ) ; return pH -> EndFunction ( ) ; } pPlayer -> m_AnimationSystemEnabled = 0 ; pPlayer -> EnterVehicle ( m_pVehicle , vehicleState , szHelperName ) ; pEntity -> ActivatePhysics ( false ) ; pEntity -> ResetAnimations ( 0 ) ; if ( szAnimName ) pEntity -> StartAnimation ( 0 , szAnimName , 0 , .15f ) ; IAIObject * pObj = pEntity -> GetAI ( ) ; return pH -> EndFunction ( ) ; }
Attaches a player to the vehicle, (so he is able to drive it IF bDriving).
Attaches a player to the vehicle ( so he is able to drive it IF bDriving ) .
//get the playerID
 //get the helper
 //check if an animation name is specified
 // check if we're setting this player as driver (can be a passenger also)
 // if no helper is specified, nobody knows where to place the player
 //if (pSrv)	//	do server stuff
 //bind the player to this vehicle
 //pSrv->BindEntity(m_pVehicle->GetEntity()->GetId(),nPlayerid,iSlot);	[Anton] - Entity->Bind already called the server
 //make the player facing the correct angles
 // move the player to the correct position
 //stop all animations
 // do not let him use the weapon once he's inside
 // pPlayer->DeselectWeapon();
 // Disable normal animation control so that it doesnt overide us
 // let the player enter the vechicle as passenger or driver
 // if hes the driver, lets switch the control keys to the vehicle keys
 // the key map is changed from script
 //	deactivate the physics for the player
 // CLIENT side code	
 // play enter animation (if any)
