// getVehicleCoordinates(vehicleid)
SQInteger CVehicleNatives::GetCoordinates(SQVM * pVM)
{
    EntityId vehicleId;
    sq_getentity(pVM, -1, &vehicleId);

    CNetworkVehicle * pVehicle = g_pClient->GetVehicleManager()->Get(vehicleId);

    if(pVehicle)
    {
        CVector3 vecPosition;
        pVehicle->GetPosition(vecPosition);
        CSquirrelArguments args;
        args.push(vecPosition.fX);
        args.push(vecPosition.fY);
        args.push(vecPosition.fZ);
        sq_pusharg(pVM, CSquirrelArgument(args, true));
        return 1;
    }

    sq_pushbool(pVM, false);
    return 1;
}
示例#2
0
void SavePosCommand(char * szParams)
{
	FILE * file = fopen(SharedUtility::GetAbsolutePath("SavedData.txt"), "a");
	if(!file)
	{
		g_pClient->GetChatWindow()->AddInfoMessage("Failed to open 'SavedData.txt'");
		return;
	}

	CVector3 vecPosition;

	// Get our local player
	CLocalPlayer * pLocalPlayer = g_pClient->GetLocalPlayer();

	if(pLocalPlayer->IsInVehicle())
	{
		CNetworkVehicle * pVehicle = pLocalPlayer->GetVehicle();

		if(pVehicle)
		{
			pVehicle->GetPosition(vecPosition);
			CVector3 vecRotation;
			pVehicle->GetRotation(vecRotation);
			BYTE byteColors[4];
			pVehicle->GetColors(byteColors[0], byteColors[1], byteColors[2], byteColors[3]);
			fprintf(file, "createVehicle(%d, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d);%s%s\n", g_pClient->GetModelManager()->ModelHashToVehicleId(pVehicle->GetModelInfo()->GetHash()), vecPosition.fX, vecPosition.fY, vecPosition.fZ, vecRotation.fX, vecRotation.fY, vecRotation.fZ, byteColors[0], byteColors[1], byteColors[2], byteColors[3], szParams ? " // " : "", szParams ? szParams : "");
		}
	}
	else
	{
		pLocalPlayer->GetPosition(vecPosition);
		int iModelId = ModelHashToSkinId(pLocalPlayer->GetModelInfo()->GetHash());
		fprintf(file, "PlayerData(%d, %f, %f, %f, %f(%f));%s%s\n", iModelId, vecPosition.fX, vecPosition.fY, vecPosition.fZ, pLocalPlayer->GetCurrentHeading(), pLocalPlayer->GetDesiredHeading(),szParams ? " // " : "", szParams ? szParams : "");
	}

	fclose(file);
	g_pClient->GetChatWindow()->AddInfoMessage("Position data saved to 'SavedData.txt'");
}
示例#3
0
// Direct3DDevice9::EndScene
void Direct3DRender()
{
	// Check for pause menu
	if(g_pNetworkManager)
	{
		if(CGame::IsMenuActive() && CGame::GetState() == GAME_STATE_INGAME && g_pNetworkManager->IsConnected())
			CGame::SetState(GAME_STATE_PAUSE_MENU);
		else if(!CGame::IsMenuActive() && CGame::GetState() == GAME_STATE_PAUSE_MENU && g_pNetworkManager->IsConnected())
			CGame::SetState(GAME_STATE_INGAME);
	}
	// Are we in the main menu?
	if(CGame::GetState() == GAME_STATE_MAIN_MENU || CGame::GetState() == GAME_STATE_LOADING)
	{
		// Is the main menu shown?
		if(CGame::IsMenuActive())
		{
			// Clear the screen
			g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0, 0);
		}
	}
	if(g_pMainMenu && CGame::GetState() == GAME_STATE_MAIN_MENU || CGame::GetState() == GAME_STATE_IVMP_PAUSE_MENU)
	{
		if(!g_pMainMenu->IsVisible())
		{
			if(g_pNetworkManager && g_pNetworkManager->IsConnected())
			{
				g_pMainMenu->SetDisconnectButtonVisible(true);
				g_pMainMenu->SetVisible(true);
			}
			else
			{
				g_pMainMenu->SetDisconnectButtonVisible(false);
				g_pMainMenu->SetVisible(true);
			}
		}
	}
	else
	{
		if(g_pMainMenu->IsVisible())
			g_pMainMenu->SetVisible(false);
	}

	if(g_pClientScriptManager && g_pClientScriptManager->GetGUIManager())
	{
		if(CGame::GetState() != GAME_STATE_INGAME)
		{
			if(!g_pClientScriptManager->GetGUIManager()->IsHidden())
				g_pClientScriptManager->GetGUIManager()->Hide();
		}
		else
		{
			if(g_pClientScriptManager->GetGUIManager()->IsHidden())
				g_pClientScriptManager->GetGUIManager()->Show();
		}
	}

	// If our GUI class exists render it
	if(g_pGUI)
		g_pGUI->Render();

	// If our WebKit class exists render it
	/*	
	#ifdef IVMP_WEBKIT
		if(g_pWebkit)
		{
			g_pWebkit->RenderAll();
		}
	#endif
	*/
	// If our main menu exists process it
	if(g_pMainMenu)
		g_pMainMenu->Process();

	// if our chat exist draw it
	if(g_pChatWindow && !CGame::IsMenuActive())
		g_pChatWindow->Draw();

	// If our fps class exists update it
	if(g_pFPSCounter)
		g_pFPSCounter->Pulse();

	// If our credits class exists process it
	if(g_pCredits)
		g_pCredits->Process();

	// If our scripting manager exists, call the frame event
	if(g_pEvents && !g_pMainMenu->IsVisible())
		g_pEvents->Call("frameRender");

	// Check if our screen shot write failed
	if(CScreenShot::IsDone())
	{
		if(CScreenShot::HasSucceeded())
			g_pChatWindow->AddInfoMessage("Screen shot written (%s).", CScreenShot::GetWriteName().Get());
		else
			g_pChatWindow->AddInfoMessage("Screen shot write failed (%s).", CScreenShot::GetError().Get());

		CScreenShot::Reset();
	}
	
	// Moving Camera for main menu, problem: g_pCamera->SetLookAt() cause an crash at change
	/*if(g_pNetworkManager && g_pCamera)
	{
		if(!g_pNetworkManager->IsConnected() && CGame::IsGameLoaded())
		{
			if(g_iCameraTime > 500)
			{
				if(g_iCameraState == 1)
					g_iCameraState = 2;
				else if(g_iCameraState == 2)
					g_iCameraState = 3;
				else if(g_iCameraState == 3)
					g_iCameraState = 1;

				g_iCameraTime = 0;

				if(g_iCameraState == 1)
				{
					g_pCamera->SetPosition(CVector3(HAPPINESS_CAMERA_POS));
					//g_pCamera->SetLookAt(CVector3(HAPPINESS_CAMERA_LOOK_AT));
				}
				if(g_iCameraState == 2)
				{
					g_pCamera->SetPosition(CVector3(TRIANGLE_CAMERA_POS));
					//g_pCamera->SetLookAt(CVector3(TRIANGLE_CAMERA_LOOK_AT));
				}
				if(g_iCameraState == 3)
				{
					g_pCamera->SetPosition(CVector3(TRIANGLE_CAMERA_POS_OLD));
					//g_pCamera->SetLookAt(CVector3(TRIANGLE_CAMERA_LOOK_AT_OLD));
				}
			}
			else
			{
				g_iCameraTime++;

				CVector3 vecPosition;
				g_pCamera->GetPosition(vecPosition);

				vecPosition.fX += 0.1f;
				vecPosition.fY += 0.1f;

				g_pCamera->SetPosition(vecPosition);
			}
		}
	}
	if(g_pNetworkManager)
	{
		if(!g_pNetworkManager->IsConnected() && CGame::IsGameLoaded())
		{
			if(CGame::GetState() == (eState)3)
				CGame::SetState(GAME_STATE_IVMP_PAUSE_MENU);

			if(!g_pMainMenu->IsVisible() && !CGame::IsMenuActive())
				CGame::SetState(GAME_STATE_IVMP_PAUSE_MENU);
		}
	}*/

	// Are we in game?
	if(CGame::GetState() == GAME_STATE_INGAME)
	{
		// Is F4 held down and do we have a network manager?
		if(GetAsyncKeyState(VK_F4) && g_pNetworkManager)
		{
			// Get the network statistics
			CNetStats * pNetStats = g_pNetworkManager->GetNetClient()->GetNetStats();

			// Convert the network statistics to a string
			char szNetworkStats[10000];
			pNetStats->ToString(szNetworkStats, 2);

			// Create the statistics string
			String strStats(szNetworkStats);

			// Append loaded and unloaded model counts to the stats
			// jenksta: too performance heavy to be done every frame
			//strStats.AppendF("Models (Loaded/Unload): %d/%d\n", CGame::GetLoadedModelCount(), CGame::GetUnloadedModelCount());

			// Append streamed in/out entity counts and streamed in limits to the stats
			strStats.AppendF("Vehicles (StreamedIn/StreamedInLimit): %d/%d\n", g_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_VEHICLE), g_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_VEHICLE));
			strStats.AppendF("Pickups (StreamedIn/StreamedInLimit): %d/%d\n", g_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_PICKUP), g_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_PICKUP));
			strStats.AppendF("Objects (StreamedIn/StreamedInLimit): %d/%d\n", g_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_OBJECT), g_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_OBJECT));
			strStats.AppendF("Checkpoints (StreamedIn/StreamedInLimit): %d/%d\n", g_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_CHECKPOINT), g_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_CHECKPOINT));

			// Draw the string
			g_pGUI->DrawText(strStats, CEGUI::Vector2(26, 30), (CEGUI::colour)D3DCOLOR_RGBA(255, 255, 255, 255), g_pGUI->GetFont("tahoma-bold", 10));
			g_pChatWindow->SetEnabled(false);
			g_bNetworkStatsDisplayed = true;
		}
		else
		{
			// If our network stats were displayed
			if(g_bNetworkStatsDisplayed) {
				if(g_pChatWindow && !g_pChatWindow->IsEnabled())
					g_pChatWindow->SetEnabled(true);
				
				g_bNetworkStatsDisplayed = false;
			}

			// If our input window exists draw it
			if(g_pInputWindow)
				g_pInputWindow->Draw();
		}

		// Update the time
		if(g_pTime)
		{
			// jenksta: Setting this every frame causes the weather to change
			// rapidly
			unsigned char ucHour = 0, ucMinute = 0;
			g_pTime->GetTime(&ucHour, &ucMinute);
			CGame::SetTime(ucHour, ucMinute);
			CGame::SetDayOfWeek(g_pTime->GetDayOfWeek());
		}
		/* Vehicle Headlights testcode
			IVVehicle * pGameVehicle = pVehicle->GetGameVehicle()->GetVehicle();
			//*(BYTE *)(pVehicle->GetGameVehicle()->GetVehicle() + 0xF71) |= 1;
			*((BYTE *)pGameVehicle + 3953) = *((BYTE *)pGameVehicle + 3953) & 0xFE | 2;
				
		}

		 CViewportManager + 0x00 = sysArray (CViewport *)
		 CViewport + 0x53C = Viewport ID
		 GET_VIEWPORT_POS_AND_SIZE(unsigned int uiViewportId, float * fPosX, float * fPosY, float * fSizeX, float * fSizeY)
		 (pViewport + 0x10) is always used
		 ((pViewport + 0x10) + 0x298) = float fPosX;
		 (((pViewport + 0x10) + 0x298) + 0x4) = float fPosY;
		 (((pViewport + 0x10) + 0x298) + 0x8) = float fSizeX;
		 (((pViewport + 0x10) + 0x298) + 0xC) = float fSizeY;
		 GET_VIEWPORT_POSITION_OF_COORD(float fCoordX, float fCoordY, float fCoordZ, unsigned int uiViewportId, float * fPosX, float * fPosY)
		 Viewport 1 = CViewportPrimaryOrtho
		 Viewport 2 = CViewportGame
		 Viewport 3 = CViewportRadar
		*/
		if(g_pLocalPlayer)
		{
			if(g_pLocalPlayer->GetVehicleInfos())
			{
				if(g_pVehicleManager)
				{
					CVector3 vecWorldPosition;
					Vector2 vecScreenPosition;

					for(EntityId i = 0; i < MAX_VEHICLES; i++)
					{
						if(g_pVehicleManager->Exists(i))
						{
							CNetworkVehicle * pVehicle = g_pVehicleManager->Get(i);

							if(!pVehicle->IsStreamedIn())
								continue;

							if(!pVehicle->IsOnScreen())
								continue;
					
							pVehicle->GetPosition(vecWorldPosition); 
							CGame::GetScreenPositionFromWorldPosition(vecWorldPosition, vecScreenPosition);

							//if(g_pGraphics)
							//{
							//	CVector3 vecScreen;
							//	g_pGraphics->GetScreenPositionFromWorldPosition(vecWorldPosition, &vecScreen);
						
							//	if( vecScreen.fZ < 0 )
							//		return;
							//}
							//else
							//	return;
							
							int health = pVehicle->GetHealth();
							int model = pVehicle->GetEngineState();
							float petrol = pVehicle->GetPetrolTankHealth();
							CVector3 vecPos; pVehicle->GetPosition(vecPos);
							CVector3 vecRot; pVehicle->GetRotation(vecRot);
							g_pGUI->DrawText(String("VehicleId %d, Enginestate: %d, Health: %d, PetrolTankHealth: %f\nPosition(%.3f,%.3f,%.3f), Rot(%.3f,%.3f,%.3f)", i, model, health, petrol, vecPos.fX,vecPos.fY,vecPos.fZ,vecRot.fX,vecRot.fY,vecRot.fZ), CEGUI::Vector2(vecScreenPosition.X, vecScreenPosition.Y));
						}
					}
				}
			}
		}
		if(g_pNameTags)
			g_pNameTags->Draw();
	}
}
示例#4
0
void CClient::OnD3DEndScene()
{
	// Check for pause menu
	if(m_pNetworkManager)
	{
		if(CGame::IsMenuActive() && CGame::GetState() == GAME_STATE_INGAME && m_pNetworkManager->IsConnected())
			CGame::SetState(GAME_STATE_PAUSE_MENU);
		else if(!CGame::IsMenuActive() && CGame::GetState() == GAME_STATE_PAUSE_MENU && m_pNetworkManager->IsConnected())
			CGame::SetState(GAME_STATE_INGAME);
	}
	// Are we in the main menu?
	if(CGame::GetState() == GAME_STATE_MAIN_MENU || CGame::GetState() == GAME_STATE_LOADING)
	{
		// Is the main menu shown?
		if(CGame::IsMenuActive())
		{
			// Clear the screen
			m_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0, 0);
		}
	}
	if(m_pMainMenu && CGame::GetState() == GAME_STATE_MAIN_MENU || CGame::GetState() == GAME_STATE_IVMP_PAUSE_MENU)
	{
		if(!m_pMainMenu->IsVisible())
		{
			if(m_pNetworkManager && m_pNetworkManager->IsConnected())
			{
				m_pMainMenu->SetDisconnectButtonVisible(true);
				m_pMainMenu->SetVisible(true);
			}
			else
			{
				m_pMainMenu->SetDisconnectButtonVisible(false);
				m_pMainMenu->SetVisible(true);
			}

			if(CGame::GetState() == GAME_STATE_MAIN_MENU)
			{
				String strPostPath("/getlatestversion.php");
				m_pHttpClient->Get(strPostPath);

				if(strcmp(m_strConnectHost,"0.0.0.0"))
				{
					// Send connect event
					m_pMainMenu->OnDirectConnect(m_strConnectHost,m_usConnectPort);

					// Remove current connect entries from xml file
					CVAR_SET_STRING("currentconnect_server","0.0.0.0");
					CVAR_SET_INTEGER("currentconnect_port",9999);
				}
			}
		}
	}
	else
	{
		if(m_pMainMenu->IsVisible())
		{
			m_pMainMenu->SetVisible(false);
			m_pChatWindow->SetEnabled(true);
		}
	}

	if(m_pClientScriptManager && m_pClientScriptManager->GetGUIManager())
	{
		if(CGame::GetState() != GAME_STATE_INGAME)
		{
			if(!m_pClientScriptManager->GetGUIManager()->IsHidden())
				m_pClientScriptManager->GetGUIManager()->Hide();
		}
		else
		{
			if(m_pClientScriptManager->GetGUIManager()->IsHidden())
				m_pClientScriptManager->GetGUIManager()->Show();
		}
	}

	// If our GUI class exists render it
	if(m_pGUI)
		m_pGUI->Render();

	// If our main menu exists process it
	if(m_pMainMenu)
		m_pMainMenu->Process();

	// If our chat window exist draw it
	if(m_pChatWindow && !CGame::IsMenuActive())
		m_pChatWindow->Draw();

	// If our fps class exists update it
	if(m_pFPSCounter)
		m_pFPSCounter->Pulse();

	// If our credits class exists process it
	if(m_pCredits)
		m_pCredits->Process();

	if(m_p3DLabelManager)
		m_p3DLabelManager->Render();

	// If our scripting manager exists, call the frame event
	if(m_pEvents && !m_pMainMenu->IsVisible())
		m_pEvents->Call("frameRender");

#ifdef IVMP_DEBUG
	if(m_pDebugView && m_pGUI && m_pLocalPlayer)
		m_pDebugView->Draw();
#endif

	// Check if our screen shot write failed
	if(CScreenShot::IsDone())
	{
		if(CScreenShot::HasSucceeded())
			m_pChatWindow->AddInfoMessage("Screen shot written (%s).", CScreenShot::GetWriteName().Get());
		else
			m_pChatWindow->AddInfoMessage("Screen shot write failed (%s).", CScreenShot::GetError().Get());

		CScreenShot::Reset();
	}
	
	if(CGame::GetState() == GAME_STATE_MAIN_MENU)
	{
		if(m_pHttpClient->IsBusy())
			m_pHttpClient->Process();
		if(m_pHttpClient->GotData())
		{
			// Get the data
			String * strData = m_pHttpClient->GetData();

			// Did we get any data?
			if(!strData->IsEmpty())
			{
#ifndef IVMP_DEBUG
				if(strcmp(strData->Get(), MOD_VERSION_STRING))
				{
					if(m_pGUI)
						m_pGUI->ShowMessageBox(String("A new version of IV:MP is available (Version %s)", strData->Get()).Get(), "New Version available");
				}
#endif
			}
		}
	}

	// Are we in game?
	if(CGame::GetState() == GAME_STATE_INGAME)
	{
		// Is F4 held down and do we have a network manager?
		if(GetAsyncKeyState(VK_F4) && m_pNetworkManager && m_pActorManager)
		{
			// Get the network statistics
			CNetStats * pNetStats = m_pNetworkManager->GetNetClient()->GetNetStats();

			// Convert the network statistics to a string
			char szNetworkStats[10000];
			pNetStats->ToString(szNetworkStats, 2);

			// Create the statistics string
			String strStats(szNetworkStats);

			// Append loaded and unloaded model counts to the stats
			// jenksta: too performance heavy to be done every frame
			//strStats.AppendF("Models (Loaded/Unload): %d/%d\n", CGame::GetLoadedModelCount(), CGame::GetUnloadedModelCount());

			// Append streamed in/out entity counts and streamed in limits to the stats
			strStats.AppendF("Players (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_PLAYER)+1, m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_PLAYER));
			strStats.AppendF("Vehicles (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_VEHICLE), m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_VEHICLE));
			strStats.AppendF("Actors (Actor-Count/Max-Actors): %d/%d\n", m_pActorManager->GetActorCount(), MAX_ACTORS);
			strStats.AppendF("Pickups (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_PICKUP), m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_PICKUP));
			strStats.AppendF("Objects (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_OBJECT), m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_OBJECT));
			strStats.AppendF("Checkpoints (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_CHECKPOINT), m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_CHECKPOINT));

			// Draw the string
			m_pGUI->DrawText(strStats, CEGUI::Vector2(26, 30), (CEGUI::colour)D3DCOLOR_RGBA(255, 255, 255, 255), m_pGUI->GetFont("tahoma-bold", 10));
			m_pChatWindow->SetEnabled(false);
			m_bNetworkStatsDisplayed = true;
		}
		else
		{
			// If our network stats were displayed
			if(m_bNetworkStatsDisplayed)
			{
				if(m_pChatWindow && !m_pChatWindow->IsEnabled())
					m_pChatWindow->SetEnabled(true);
				
				m_bNetworkStatsDisplayed = false;
			}

			// If our input window exists draw it
			if(m_pInputWindow)
				m_pInputWindow->Draw();
		}

		// Update the time
		if(m_pTime)
		{
			// jenksta: Setting this every frame causes the weather to change
			// rapidly
			unsigned char ucHour = 0, ucMinute = 0;
			m_pTime->GetTime(&ucHour, &ucMinute);
			CGame::SetTime(ucHour, ucMinute);
			CGame::SetDayOfWeek(m_pTime->GetDayOfWeek());
		}

#ifdef IVMP_DEBUG
		if(m_pVehicleManager)
		{
			CVector3 vecWorldPosition;
			Vector2 vecScreenPosition;

			for(EntityId i = 0; i < MAX_VEHICLES; i++)
			{
				CNetworkVehicle * pVehicle = m_pVehicleManager->Get(i);
				if(pVehicle)
				{
					if(!pVehicle->IsStreamedIn())
						continue;

					if(!pVehicle->IsOnScreen())
						continue;
					
					pVehicle->GetPosition(vecWorldPosition); 
					if(!CGame::GetScreenPositionFromWorldPosition(vecWorldPosition, vecScreenPosition))
						continue;

							
					int iHealth = pVehicle->GetHealth();
					int iModel = pVehicle->GetEngineState();
					float fPetrol = pVehicle->GetPetrolTankHealth();
					CVector3 vecPos; pVehicle->GetPosition(vecPos);
					CVector3 vecRot; pVehicle->GetRotation(vecRot);
					m_pGUI->DrawText(String("VehicleId %d, Enginestate: %d, Health: %d, PetrolTankHealth: %f\nPosition(%.3f,%.3f,%.3f), Rot(%.3f,%.3f,%.3f)", i, iModel, iHealth, fPetrol, vecPos.fX,vecPos.fY,vecPos.fZ,vecRot.fX,vecRot.fY,vecRot.fZ), CEGUI::Vector2(vecScreenPosition.fX, vecScreenPosition.fY));
				}
			}
		}
#endif

		if(m_pNameTags)
			m_pNameTags->Draw();
	}
}
示例#5
0
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;
	}
}
示例#6
0
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 );
}