void CNetworkPlayer::HandlePlayerDeath( void ) { DEBUG_TRACE("CNetworkPlayer::HandlePlayerDeath"); // Is the localplayer not spawned? if( !pCore->GetPlayerManager()->GetLocalPlayer()->IsSpawned() ) return; // Is the player invalid? if( !IsSpawned() || !m_pPlayerPed ) return; // Reset invulnerability m_pPlayerPed->SetInvulnerable( false ); // Set the player health m_pPlayerPed->SetHealth( 0.0f ); // Mark as dead SetDead( true ); // Mark as not spawned SetSpawned( false ); // Are we in a vehicle as driver? if( IsInVehicle() ) { // Reset the vehicle interpolation m_pVehicle->ResetInterpolation(); } // Set the playerstate m_playerState = ePlayerState::PLAYERSTATE_DEAD; }
Vehicle ^Ped::CurrentVehicle::get() { if (!IsInVehicle()) { return nullptr; } return gcnew Vehicle(Native::Function::Call<int>(Native::Hash::GET_VEHICLE_PED_IS_IN, this->Handle, false)); }
void CLocalPlayer::HandleSpawn( bool bRespawn ) { // Are we respawning and not dead? if( bRespawn && !IsDead() ) return; // Have we already just spawned? if( (SharedUtility::GetTime() - m_ulSpawnTime) < 500 ) return; // Set the spawn time m_ulSpawnTime = SharedUtility::GetTime(); // Reset the death time m_ulDeathTime = 0; // Set the state SetState( ePlayerState::PLAYERSTATE_ONFOOT ); // Mark as not dead SetDead( false ); // Mark as spawned SetSpawned( true ); // Are we in a vehicle? if( IsInVehicle() ) { // Handle this enter with the network vehicle m_pVehicle->HandlePlayerExit( this, m_seat, false ); // Reset the vehicle SetVehicle( NULL ); // Reset the seat SetSeat( INVALID_ENTITY_ID ); } // Reset the player position and rotation Teleport ( CVector3() ); SetRotation ( CVector3() ); // Send RPC to server pCore->GetNetworkModule()->Call( RPC_PLAYER_SPAWN, NULL, HIGH_PRIORITY, RELIABLE, true ); // Restore the camera (TODO: Use real game function to reset camera behind player!) pCore->GetCamera()->LockControl ( false ); LockControls ( false ); // Restore the camera control pCore->GetCamera()->LockControl ( bOldCameraState ); // Restore the control state LockControls ( bOldCTRLState ); }
bool Ped::IsIdle::get() { return !IsInjured && !IsRagdoll && !IsInAir && !IsOnFire && !IsDucking && !IsGettingIntoAVehicle && !IsInCombat && !IsInMeleeCombat && !(IsInVehicle() && !IsSittingInVehicle()); }
void CLocalPlayer::Pulse( void ) { // Are we experiencing connection trouble? if ( IsSpawned() && (SharedUtility::GetTime() - m_ulLastPingTime) > 6000 ) pCore->SetConnectionProblem ( true ); // Get our current position and rotation CVector3 vecCurrentPosition, vecCurrentRotation; GetPosition( &vecCurrentPosition ); GetRotation( &vecCurrentRotation ); // Is our position or rotation invalid? if ( !Math::IsValidVector ( vecCurrentPosition ) || !Math::IsValidVector ( vecCurrentRotation ) ) { CLogFile::Printf ( "ERROR - Player position or rotation was invalid. Warped back to the last good saved state." ); // Warp the player back to their last good saved position and rotation Teleport ( m_vecLastGoodPosition ); SetRotation ( m_vecLastGoodRotation ); // Is the last good state invalid? if ( !Math::IsValidVector ( m_vecLastGoodPosition ) || !Math::IsValidVector ( m_vecLastGoodRotation ) ) { // Fade hud and sound quickly pCore->GetHud()->FadeOut ( 0 ); pCore->GetGame()->FadeSound ( true, 0 ); // Reset position Teleport ( CVector3() ); SetRotation ( CVector3() ); // Kill the player SetHealth ( 0.0f ); } // Return so we don't overwrite the last good position with invalid positions return; } // Save this current position and rotation memcpy ( &m_vecLastGoodPosition, &vecCurrentPosition, sizeof ( CVector3 ) ); memcpy ( &m_vecLastGoodRotation, &vecCurrentRotation, sizeof ( CVector3 ) ); // Do we need a full sync? if( IsFullSyncNeeded () ) { // Are we not in a vehicle? if( !InternalIsInVehicle() ) { // Send onfoot sync data SendOnFootSync(); } else { // Are we the vehicle driver? if( GetState() == PLAYERSTATE_DRIVER ) { // Send invehicle sync data SendInVehicleSync(); } // Send passenger sync data SendPassengerSync(); } } // Are we spawned and not dead? if( IsSpawned() && ((SharedUtility::GetTime() - m_ulSpawnTime) > 5000) && !IsDead() ) { // Are we falling below the map? if( vecCurrentPosition.fZ <= -150.0f ) { // Kill ourself SetHealth( 0.0f ); } } // Have we been dead for 3 seconds? if ( (SharedUtility::GetTime() - m_ulDeathTime) > 4000 && IsDead() ) { // Deactivate the player ped m_pPlayerPed->Deactivate (); // Respawn HandleSpawn ( true ); // Fade the hud back in pCore->GetHud()->FadeIn ( 1000 ); // Fade the sound back in pCore->GetGame()->FadeSound ( false, 1 ); // Activate the player ped m_pPlayerPed->Activate (); } // Are we spawned, in a vehicle and typing? if( IsSpawned() && IsInVehicle() && pCore->GetChat()->IsInputVisible() ) { // Reset the vehicle steering (prevent car turning to sides) if( m_pVehicle->GetVehicle() ) m_pVehicle->GetVehicle()->AddSteer( 0.0f ); } // Loop over all vehicles we're syncing //for( std::list< CNetworkVehicle* >::iterator iter = m_syncingVehicles.begin(); iter != m_syncingVehicles.end(); iter++ ) //{ // Send the vehicle sync for this vehicle // SendUnoccupiedVehicleSync( *iter ); //} }