本文整理汇总了C++中CNetworkVehicle::GetVehicle方法的典型用法代码示例。如果您正苦于以下问题:C++ CNetworkVehicle::GetVehicle方法的具体用法?C++ CNetworkVehicle::GetVehicle怎么用?C++ CNetworkVehicle::GetVehicle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNetworkVehicle
的用法示例。
在下文中一共展示了CNetworkVehicle::GetVehicle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnEnterVehicle
void CLocalPlayer::OnEnterVehicle( void )
{
// Get the vehicle instance from the vehicle guid
CNetworkVehicle * pNetworkVehicle = pCore->GetVehicleManager()->GetFromGameGUID( GetPlayerPed()->GetCurrentVehicle()->m_dwGUID );
// Is the vehicle instance valid?
if( pNetworkVehicle )
{
#ifdef _DEBUG
M2Vehicle * pVehicle = pNetworkVehicle->GetVehicle()->GetVehicle();
DWORD dwVehicleData = (DWORD)(pVehicle) + 0xA8;
pCore->GetChat()->AddDebugMessage ( "Vehicle: 0x%p, VehicleData: 0x%p", pVehicle, dwVehicleData );
#endif
// Set the initial seat as the driver
EntityId seat = 0;
// Is the player in the passenger seat?
//if( GetState() == PLAYERSTATE_PASSENGER )
// seat = pNetworkVehicle->GetVehicle()->GetPedOccupiedSeat( GetPlayerPed()->GetPed() );
// Does the vehicle already have a driver?
if ( pNetworkVehicle->GetDriver () )
seat = pNetworkVehicle->GetVehicle()->GetPedOccupiedSeat( GetPlayerPed()->GetPed() );
// Are we getting in as the driver?
if( seat == 0 )
SetState( PLAYERSTATE_DRIVER );
else
SetState( PLAYERSTATE_PASSENGER );
#ifdef _DEBUG
pCore->GetChat()->AddDebugMessage( "Seat: %d, Driver: 0x%p, State: %d", seat, pNetworkVehicle->GetDriver (), GetState () );
#endif
// Construct a new bitstream
RakNet::BitStream pBitStream;
// Write the vehicle id
pBitStream.WriteCompressed( pNetworkVehicle->GetId() );
// Write the seat
pBitStream.WriteCompressed( seat );
// Send to the server
pCore->GetNetworkModule()->Call( RPC_ENTER_VEHICLE, &pBitStream, HIGH_PRIORITY, RELIABLE_ORDERED, true );
#ifdef _DEBUG
pCore->GetChat()->AddDebugMessage( "CLocalPlayer::OnEnterVehicle( %d, %d )", pNetworkVehicle->GetId(), seat );
#endif
// Handle this enter with the network vehicle
pNetworkVehicle->HandlePlayerEnter( this, seat );
// Set the vehicle
SetVehicle( pNetworkVehicle );
// Set the seat
SetSeat( seat );
// Set the target data
SetEnteringVehicle( pNetworkVehicle, seat );
}
}
示例2: GetClosestVehicle
void CLocalPlayer::GetClosestVehicle( CNetworkVehicle ** pNetworkVehicle, EntityId * seatId )
{
// Are we spawned and not dead and not already in a vehicle?
if( IsSpawned() && !IsDead() && !m_pPlayerPed->GetCurrentVehicle() )
{
//
float fCurrentDistance = 2.68f;
CVector3 vecVehiclePos;
CNetworkVehicle * pClosestVehicle = NULL;
// Get our position
CVector3 vecCurrentPosition;
GetPosition( &vecCurrentPosition );
// Loop through all network vehicles
for( int i = 0; i < MAX_VEHICLES; i++ )
{
// Is the current vehicle active?
if( pCore->GetVehicleManager()->IsActive( i ) )
{
// Get a pointer to the current vehicle
CNetworkVehicle * pCurrentVehicle = pCore->GetVehicleManager()->Get( i );
// Get the vehicle position
pCurrentVehicle->GetPosition( &vecVehiclePos );
// Get the distance between the current vehicle and us
float fDistance = Math::GetDistanceBetweenPoints( vecCurrentPosition, vecVehiclePos );
// Is this distance less than the current distance?
if( fDistance < fCurrentDistance )
{
// Set the current distance
fCurrentDistance = fDistance;
// Set the closest vehicle
pClosestVehicle = pCurrentVehicle;
}
}
}
// Isn't there a vehicle in range?
if( !pClosestVehicle )
return;
// Loop through all the passenger seats
BYTE byteCurrentSeat = 0;
for( BYTE i = 2; i < 5; i++ )
{
// Is there no one in this seat?
if( !pClosestVehicle->GetVehicle()->GetSeatOccupant( i ) )
{
byteCurrentSeat = i;
break;
}
}
// Didn't we find a seat?
if( !byteCurrentSeat )
return;
// Set the seat
*seatId = byteCurrentSeat;
// Set the vehicle
*pNetworkVehicle = pClosestVehicle;
}
}
示例3: SendInVehicleSync
void CLocalPlayer::SendInVehicleSync( void )
{
// Are we not connected to the network?
if( !pCore->GetNetworkModule()->IsConnected() )
return;
// Are we dead?
if( IsDead() )
return;
// Get the vehicle instance
CNetworkVehicle * pVehicle = pCore->GetVehicleManager()->GetFromGameGUID( GetPlayerPed()->GetCurrentVehicle()->m_dwGUID );
// Did we fail to find the vehicle?
if( !pVehicle )
return;
// Construct a new bitstream
RakNet::BitStream pBitStream;
// Write the vehicle id
pBitStream.WriteCompressed( pVehicle->GetId() );
// Construct a new in vehicle sync data structure
InVehicleSync inVehicleSync;
// Get the vehicle position
pVehicle->GetPosition( &inVehicleSync.m_vecPosition );
// Get the vehicle rotation
pVehicle->GetRotation( &inVehicleSync.m_vecRotation );
// Get the vehicle dirt level
inVehicleSync.m_fDirtLevel = pVehicle->GetVehicle()->GetDirtLevel();
// Get the vehicle tuning table
inVehicleSync.m_iTuningTable = pVehicle->GetVehicle()->GetTuningTable();
// Get the vehicle horn state
inVehicleSync.m_bHornState = pVehicle->GetVehicle()->IsHornOn();
// Get the vehicle siren state
inVehicleSync.m_bSirenState = pVehicle->GetVehicle()->IsSirenOn();
// Get the vehicle fuel
inVehicleSync.m_fFuel = pVehicle->GetVehicle()->GetFuel();
// Get the vehicle speed
pVehicle->GetSpeedVec( &inVehicleSync.m_vecVelocity );
// Get the turn speed
inVehicleSync.m_fTurnSpeed = pVehicle->GetSteer();
// Get the engine damage
inVehicleSync.m_fEngineDamage = pVehicle->GetVehicle()->GetEngineDamage();
// Get the vehicle plate text
strcpy( inVehicleSync.m_szPlateText, pVehicle->GetPlateText() );
inVehicleSync.m_szPlateText[ 6 ] = '\0';
// Get the vehicle colour
pVehicle->GetColour( &inVehicleSync.m_primaryColour, &inVehicleSync.m_secondaryColour );
// Get the power state
inVehicleSync.m_bPower = pVehicle->GetVehicle()->GetPower();
// Get the brake state
inVehicleSync.m_bBrake = pVehicle->GetVehicle()->GetBrake();
// Get the vehicle wheel models (DISABLED FOR TESTING)
for ( int i = 0; i < 3; i++ )
inVehicleSync.m_bWheelModels[ i ] = 0xFF; //Game::GetIdFromVehicleWheelModel ( pVehicle->GetVehicle()->GetWheelTexture ( i ) );
// Get the handbrake state
inVehicleSync.m_bHandbrake = pVehicle->GetVehicle()->IsHandbrakeOn ();
// Get the light state
inVehicleSync.m_bLightState = pVehicle->GetVehicle()->GetLightState ();
// Write the sync structure into the bitstream
pBitStream.Write( (char *)&inVehicleSync, sizeof(InVehicleSync) );
// Send the bitstream to the server
pCore->GetNetworkModule()->Call( RPC_VEHICLE_SYNC, &pBitStream, LOW_PRIORITY, UNRELIABLE_SEQUENCED, true );
}