void CVehicleEntity::SetModel(DWORD dwModelHash) { // Get the model index from the model hash int iModelIndex = g_pCore->GetGame()->GetCharacterManager()->ModelHashToVehicleId(dwModelHash); // Do we have an invalid model index? if(iModelIndex == -1) { CLogFile::Printf("CClientVehicle::SetModel Failed (Invalid model hash)!"); return; } // Has the model not changed? if(m_pModelInfo->GetIndex() == iModelIndex) { CLogFile::Printf("CClientVehicle::SetModel Failed (Model change not needed)!"); return; } // Get the new model info CIVModelInfo * pNewModelInfo = g_pCore->GetGame()->GetModelInfo(iModelIndex); // Is the new model info valid? if(!pNewModelInfo || !pNewModelInfo->IsValid() || !pNewModelInfo->IsVehicle()) { CLogFile::Printf("CClientVehicle::SetModel Failed (Invalid model)!"); return; } if(IsSpawned()) { // Stream ourselves out CLogFile::Printf("CClientVehicle::SetModel Stream Out Begin"); Destroy(); CLogFile::Printf("CClientVehicle::SetModel Stream Out Complete"); } // Set the new model info m_pModelInfo = pNewModelInfo; // Stream ourselves back in CLogFile::Printf("CClientVehicle::SetModel Stream In Begin"); Create(); CLogFile::Printf("CClientVehicle::SetModel Stream In Complete"); }
bool CClientVehicle::SetModel(int iModelIndex) { // Is the model index different from our current model index? if(iModelIndex != m_pModelInfo->GetIndex()) { // Get the new model info CIVModelInfo * pNewModelInfo = g_pClient->GetGame()->GetModelInfo(iModelIndex); // Is the new model info valid? if(!pNewModelInfo || !pNewModelInfo->IsValid() || !pNewModelInfo->IsVehicle()) { CLogFile::Printf("CClientVehicle::SetModel Failed (Invalid model)!"); return false; } bool bSpawned = IsSpawned(); // Are we spawned? if(bSpawned) { // Destroy the old vehicle StreamOut(); } // Set the new model info m_pModelInfo = pNewModelInfo; // Are we spawned? if(bSpawned) { // Ensure the new model is loaded m_pModelInfo->Load(); // Create the new vehicle StreamIn(); } return true; } return false; }