本文整理汇总了C++中CNetworkVehicle::GetId方法的典型用法代码示例。如果您正苦于以下问题:C++ CNetworkVehicle::GetId方法的具体用法?C++ CNetworkVehicle::GetId怎么用?C++ CNetworkVehicle::GetId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNetworkVehicle
的用法示例。
在下文中一共展示了CNetworkVehicle::GetId方法的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: SpawnVehicle
void SpawnVehicle( RakNet::BitStream * pBitStream, RakNet::Packet * pPacket )
{
// Read the vehicle id
EntityId vehicleId;
pBitStream->ReadCompressed( vehicleId );
// Read the spawn position
CVector3 vecPosition;
pBitStream->Read( vecPosition );
// Read teh spawn rotation
CVector3 vecRotation;
pBitStream->Read( vecRotation );
// Get a pointer to the network vehicle
CNetworkVehicle * pNetworkVehicle = pCore->GetVehicleManager()->Get( vehicleId );
// Is the vehicle pointer valid?
if( pNetworkVehicle )
{
// Is the vehicle not already spawned?
if( !pNetworkVehicle->IsSpawned() )
{
// Set the spawn position
pNetworkVehicle->SetSpawnPosition( vecPosition );
// Set the spawn rotation
pNetworkVehicle->SetSpawnRotation( vecRotation );
// Create the vehicle
pNetworkVehicle->Create();
// Read the occupant count
int iTotalOccupants;
pBitStream->Read( iTotalOccupants );
#ifdef DEBUG
CLogFile::Printf( "(SpawnVehicle) Total occupants: %d", iTotalOccupants );
#endif
// Loop over the total occupants
EntityId occupantId = INVALID_ENTITY_ID;
int iSeat = 0;
CRemotePlayer * pOccupant = NULL;
for( int i = 0; i < iTotalOccupants; i++ )
{
// Read the current occupant id
pBitStream->ReadCompressed( occupantId );
// Read the current occupant seat
pBitStream->Read( iSeat );
#ifdef DEBUG
CLogFile::Printf( "SpawnVehicle - Read occupant %d in seat %d.", occupantId, iSeat );
#endif
// Is the read data valid?
if( occupantId != INVALID_ENTITY_ID )
{
// Get a pointer to the current occupant
pOccupant = pCore->GetPlayerManager()->Get( occupantId );
// Is the pointer valid?
if( pOccupant )
{
// Set the occupant vehicle
pOccupant->SetVehicle( pNetworkVehicle );
// Set the occupant seat
pOccupant->SetSeat( (iSeat + 1) );
// Set the vehicle passenger
pNetworkVehicle->SetOccupant( iSeat, pOccupant );
#ifdef DEBUG
CLogFile::Printf( "Put occupant %d into vehicle %d (%d)", occupantId, pNetworkVehicle->GetId(), (iSeat + 1) );
#endif
}
}
}
#ifdef DEBUG
CLogFile::Print ( "SpawnVehicle RPC done!" );
#endif
}
}
}
示例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 );
}