Exemple #1
0
BOOL _stdcall IsFriendlyFire(PED_TYPE *pPlayer,DWORD *pdwEnt, int iWeapon, float fUnk, int PedPiece, BYTE byteUnk)
{
	CPlayerPool *pPlayerPool;
	CRemotePlayer *pRemotePlayer;
	CLocalPlayer *pLocalPlayer;
	BYTE byteRemotePlayerID;
	BYTE byteLocalPlayerTeam;

	if(pPlayer == GamePool_FindPlayerPed()) {
		if(pNetGame && pNetGame->m_byteFriendlyFire) {
			
			pPlayerPool = pNetGame->GetPlayerPool();
			pLocalPlayer = pPlayerPool->GetLocalPlayer();
			byteLocalPlayerTeam = pLocalPlayer->GetTeam();

			if(pLocalPlayer->IsWasted() || (byteLocalPlayerTeam == NO_TEAM)) return FALSE;

			byteRemotePlayerID = pPlayerPool->FindRemotePlayerIDFromGtaPtr((PED_TYPE *)pdwEnt);

			if(byteRemotePlayerID != INVALID_PLAYER_ID) {
				pRemotePlayer = pPlayerPool->GetAt(byteRemotePlayerID);
				if(pRemotePlayer->GetTeam() == byteLocalPlayerTeam) {
					return TRUE;
				} else {
					return FALSE;
				}
			}

			// didn't find pdwEnt in the player pool.
			// this is where we could check for a vehicle.
		}
	}

	return FALSE;	
}
void CDebugView::Draw()
{
	// Get our player manager and local player
	CPlayerManager * pPlayerManager = g_pClient->GetPlayerManager();
	CLocalPlayer * pLocalPlayer = g_pClient->GetLocalPlayer();

	if(g_pClient->GetGUI() && pLocalPlayer && pPlayerManager)
	{
		if(!pLocalPlayer->IsSpawned())
			return;

		if(g_pClient->GetMainMenu()->IsVisible())
			return;

		m_fDebugTextTop = DEBUG_TEXT_TOP;

		DumpPlayer(pLocalPlayer);

		for(EntityId i = 0; i < MAX_PLAYERS; i++)
		{
			CNetworkPlayer * pPlayer = pPlayerManager->GetAt(i);

			if(pPlayer && pPlayer->IsSpawned() && !pPlayer->IsLocalPlayer())
			{
				DumpPlayer(pPlayer);
				break;
			}
		}
	}
}
Exemple #3
0
void cmdDefaultCmdProc(PCHAR szCmd)
{
	if(pNetGame) {
		CLocalPlayer *pLocalPlayer;
		pLocalPlayer = pNetGame->GetPlayerPool()->GetLocalPlayer();
		pLocalPlayer->Say(szCmd);
	}
}
Exemple #4
0
void RequestClass(RakNet::BitStream *bitStream, Packet *packet)
{
	BYTE byteOutcome;
	int iRequestedClass;
	PLAYER_SPAWN_INFO SpawnInfo;
	CLocalPlayer * pPlayer = pNetowkManager->GetPlayerManager()->GetLocalPlayer();
	CSpawnSelection * pGameLogic = pNetowkManager->GetGameLogic();

	bitStream->Read(byteOutcome);
	if(byteOutcome) {
		bitStream->Read(iRequestedClass);
		bitStream->Read((char *)&SpawnInfo, sizeof(PLAYER_SPAWN_INFO));

		pGameLogic->SetSelectedClass(iRequestedClass);
		pPlayer->SetSpawnInfo(&SpawnInfo);
		pGameLogic->HandleClassSelectionOutcome(&SpawnInfo, byteOutcome);
	}
}
Exemple #5
0
void _stdcall DoOnFootWorldBoundsStuff()
{
	if(pNetGame) {
		CLocalPlayer *pLocalPlayer = pNetGame->GetPlayerPool()->GetLocalPlayer();
		CPlayerPed *pPlayerPed = pGame->FindPlayerPed();

		// Make sure they don't leave their worldy confines.
		if(pLocalPlayer->IsActive() && !pPlayerPed->IsInVehicle()) {
			if(pPlayerPed->EnforceWorldBoundries(
				pNetGame->m_WorldBounds[0],pNetGame->m_WorldBounds[1],
				pNetGame->m_WorldBounds[2],pNetGame->m_WorldBounds[3]))
			{
				pGcsInternalKeys->wKeys1[KEY_ONFOOT_JUMP] = 0xFF;
				pGcsInternalKeys->wKeys2[KEY_ONFOOT_JUMP] = 0x00;
				pPlayerPed->SetArmedWeapon(0);
				//pGame->DisplayTextMessage("Stay within the world boundries");
			}
		}
	}
}
Exemple #6
0
void CRemotePlayer::HandleDeath()
{
	CPlayerPool *pPlayerPool = pNetGame->GetPlayerPool();
	CLocalPlayer *pLocalPlayer = NULL;

	if (pPlayerPool) pLocalPlayer = pPlayerPool->GetLocalPlayer();

	if (pLocalPlayer) {
		if (pLocalPlayer->IsSpectating() && pLocalPlayer->m_SpectateID == m_PlayerID) {
				//pLocalPlayer->ToggleSpectating(FALSE);
		}
	}

	if(m_pPlayerPed) {
		m_pPlayerPed->SetKeys(0,0,0);
		m_pPlayerPed->SetDead();
	}

	// Dead weapon pickups
	if (m_pPlayerPed && m_pPlayerPed->GetDistanceFromLocalPlayerPed() <= 100.0f)
	{
		MATRIX4X4 matPlayer;
		m_pPlayerPed->GetMatrix(&matPlayer);

		WEAPON_SLOT_TYPE * WeaponSlot = m_pPlayerPed->GetCurrentWeaponSlot();

		if (WeaponSlot->dwType != 0 &&
			WeaponSlot->dwType != WEAPON_GRENADE &&
			WeaponSlot->dwType != WEAPON_TEARGAS &&
			WeaponSlot->dwType != WEAPON_MOLTOV)
		{
			if(pNetGame->GetPickupPool()) {
				pNetGame->GetPickupPool()->New(pGame->GetWeaponModelIDFromWeapon(WeaponSlot->dwType),
					matPlayer.pos.X, matPlayer.pos.Y, matPlayer.pos.Z, WeaponSlot->dwAmmoInClip, m_PlayerID);
			}
		}
	}

	SetState(PLAYER_STATE_WASTED);
	ResetAllSyncAttributes();
}
Exemple #7
0
// togglePlayerBleeding Native.
void Script_togglePlayerBleeding(RakNet::BitStream *bitStream, Packet *packet)
{
	int player, toggle;

	bitStream->Read(player);
	bitStream->Read(toggle);

	if(player == pNetowkManager->GetPlayerManager()->GetLocalPlayerID())
	{
		CLocalPlayer * pPlayer = pNetowkManager->GetPlayerManager()->GetLocalPlayer();
		pPlayer->GetPlayerPed()->SetActorBleeding(toggle);
	} 
	else if(pNetowkManager->GetPlayerManager()->GetSlotState(player))
	{
		if(player != pNetowkManager->GetPlayerManager()->GetLocalPlayerID())
		{
			CRemotePlayer * pPlayer = pNetowkManager->GetPlayerManager()->GetAt(player);
			pPlayer->GetPlayerPed()->SetActorBleeding(toggle);
		}
	}
}
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'");
}
Exemple #9
0
void EnterVehicle( RakNet::BitStream * pBitStream, RakNet::Packet * pPacket )
{
	// Read if the enter was successful
	bool bSuccess = pBitStream->ReadBit ();

	// Read the player id
	EntityId playerId;
	pBitStream->ReadCompressed( playerId );

	// Read the vehicle id
	EntityId vehicleId;
	pBitStream->ReadCompressed( vehicleId );

	// Read the seat
	EntityId seat;
	pBitStream->ReadCompressed( seat );

	// Get the network vehicle instance
	CNetworkVehicle * pVehicle = pCore->GetVehicleManager()->Get( vehicleId );

	pCore->GetChat()->AddDebugMessage ( "CServerPacket::EnterVehicle ( %s, %d, %d, %d )", (bSuccess ? "true" : "false"), playerId, vehicleId, seat );

	// Is the network vehicle instance valid?
	if( pVehicle )
	{
		// Was the enter a success?
		if ( bSuccess )
		{
			// Get the network player instance
			CNetworkPlayer * pPlayer = pCore->GetPlayerManager()->Get( playerId );

			// Is the network player instance valid?
			if( pPlayer )
			{
				// Is the localplayer spawned?
				if( pCore->GetPlayerManager()->GetLocalPlayer()->IsSpawned() )
				{
					// Handle this with the player
					pPlayer->EnterVehicle( pVehicle, (M2Enums::eVehicleSeat)(seat + 1) );
				}
				else
				{
					// Set the player vehicle
					pPlayer->SetVehicle( pVehicle );

					// Set the seat
					pPlayer->SetSeat( (seat + 1) );
				}
			}
		}
		// If not success this packet will only return to the localplayer!
		else
		{
			// Get the localplayer instance
			CLocalPlayer * pLocalPlayer = pCore->GetPlayerManager()->GetLocalPlayer ();

			// Ensure we're in a vehicle internally
			if ( pLocalPlayer->InternalIsInVehicle () )
			{
				// Get the current vehicle we're in from internal id
				CNetworkVehicle * pCurrentVehicle = pCore->GetVehicleManager()->GetFromGameGUID ( pLocalPlayer->GetPlayerPed()->GetCurrentVehicle()->m_dwGUID );

				// Remove the player from the vehicle
				pLocalPlayer->RemoveFromVehicle ( pCurrentVehicle );

				// Get the network player instance of the real driver (player = driver id)
				CNetworkPlayer * pRealDriver = pCore->GetPlayerManager()->Get( playerId );

				// Is the real driver valid?
				if ( pRealDriver )
				{
					// Is the real driver not in a vehicle?
					//if ( !pRealDriver->InternalIsInVehicle () )
					//{
						// Force the real driver back into the vehicle
					//	pRealDriver->PutInVehicle ( pCurrentVehicle, 0 );
					//}

					pCore->GetChat()->AddDebugMessage ( "Real Driver: %d (0x%p), Vehicle: 0x%p, InternalVehicle: 0x%p", pRealDriver->GetId (), pRealDriver, pRealDriver->GetVehicle(), pRealDriver->GetPlayerPed()->GetCurrentVehicle() );
				}

				pCore->GetChat()->AddDebugMessage ( "HandleVehicleEnter failed. There's already a driver! Restored driver context for player %d", pRealDriver->GetId () );
			}
		}
	}
}
bool CClientCommands::HandleUserInput(std::string strCommand, std::string strParameters)
{
	if(strCommand == "q"  || strCommand == "quit")
	{
		// Are we connected to the network?
		if(g_pCore->GetNetworkManager()->IsConnected())
		{
			// Disconnect and shutdown RakNet
			g_pCore->GetNetworkManager()->Shutdown(500, true);
		}
		
		TerminateProcess(GetCurrentProcess(), 0);
		return true;
	}
	else if(strCommand == "qq" || strCommand == "quickquit")
	{
		TerminateProcess(GetCurrentProcess(), 0);
		return true;
	}

	else if(strCommand == "cv")
	{
		int iVehicleType = atoi(strParameters.c_str());

		CVector3 vecCreatePos; 
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecCreatePos);
		vecCreatePos.fX += 4;
		vecCreatePos.fY += 1;

		CVehicleEntity * pVehicle = new CVehicleEntity(iVehicleType,vecCreatePos,0.0f,0,0,0,0);
		if(pVehicle)
		{
			// Add our vehicle
			g_pCore->GetGame()->GetVehicleManager()->Add(pVehicle);

			pVehicle->SetId(g_pCore->GetGame()->GetVehicleManager()->FindFreeSlot());

			pVehicle->Create();

			pVehicle->SetPosition(vecCreatePos);
		}
		return true;
	}
	else if(strCommand == "respawn")
	{
		g_pCore->GetGame()->GetLocalPlayer()->Respawn();
		return true;
	}
	else if(strCommand == "debug")
	{
		g_pCore->GetDevelopmentInstance()->CreateDebugPlayer();
		return true;
	}
	else if(strCommand == "weapon")
	{
		if(g_pCore->GetDevelopmentInstance()->GetDebugPlayerPed())
			CIVScript::GiveWeaponToChar(g_pCore->GetDevelopmentInstance()->GetDebugPlayerPed()->GetScriptingHandle(),(CIVScript::eWeapon)CIVScript::WEAPON_SHOTGUN,50,true);
		
		CIVScript::GiveWeaponToChar(g_pCore->GetGame()->GetLocalPlayer()->GetScriptingHandle(),(CIVScript::eWeapon)CIVScript::WEAPON_SHOTGUN,50,true);
		return true;
	}
	else if(strCommand == "cp")
	{
		CVector3 vecCreatePos; 
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecCreatePos);

		CPlayerEntity * pPlayer = new CPlayerEntity(false);
		if(pPlayer)
		{
			pPlayer->SetModel(7);
			pPlayer->Create();
			pPlayer->Teleport(vecCreatePos);
		}
		return true;
	}
	else if(strCommand == "spawn")
	{
		g_pCore->GetChat()->Output("Spawning local player ...",false);
		g_pCore->GetGame()->OnClientReadyToGamePlay();
		g_pCore->GetGame()->GetLocalPlayer()->SetModel(7);

		int iVehicleType = g_pCore->GetGame()->IsUsingEFLCContent() ? 128 : 91;

		CVector3 vecCreatePos; 
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecCreatePos);
		vecCreatePos.fX += 4;
		vecCreatePos.fY += 1;

		CVehicleEntity * pVehicle = new CVehicleEntity(iVehicleType,vecCreatePos,0.0f,0,0,0,0);
		if(pVehicle)
		{
			// Add our vehicle
			g_pCore->GetGame()->GetVehicleManager()->Add(pVehicle);

			pVehicle->SetId(g_pCore->GetGame()->GetVehicleManager()->FindFreeSlot());

			pVehicle->Create();

			pVehicle->SetPosition(vecCreatePos);
		}

		PTR_CHAT->Output("Type \"/ready\" and seconds later \"/parachute\" to create a parachute!",false);
		return true;
	}
	else if(strCommand == "engine") 
	{
		if(g_pCore->GetGame()->GetLocalPlayer()->GetVehicleEntity() != NULL)
			g_pCore->GetGame()->GetLocalPlayer()->GetVehicleEntity()->SetEngineState(!g_pCore->GetGame()->GetLocalPlayer()->GetVehicleEntity()->GetEngineState());
		
		return true;
	}
	else if(strCommand == "saveposition" || strCommand == "save")
	{
		FILE * file = fopen(SharedUtility::GetAbsolutePath("multiplayer//SavePositions.log"), "a");
		if(!file)
		{
			g_pCore->GetChat()->Output("Failed to open 'SavedData.log'");
			return true;
		}

		CVector3 vecPosition;

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

		if(pLocalPlayer->IsInVehicle())
		{
			CVehicleEntity * pVehicle = pLocalPlayer->GetVehicleEntity();

			if(pVehicle)
			{
				pVehicle->GetPosition(vecPosition);
				CVector3 vecRotation;
				pVehicle->GetRotation(vecRotation);
				BYTE byteColors[4];
				pVehicle->GetColors(byteColors[0], byteColors[1], byteColors[2], byteColors[3]);
				fprintf_s(file, "createVehicle(%d, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d);%s%s\n", CIVModelManager::ModelHashToVehicleId(pVehicle->GetModelInfo()->GetHash()), vecPosition.fX, vecPosition.fY, vecPosition.fZ, vecRotation.fX, vecRotation.fY, vecRotation.fZ, byteColors[0], byteColors[1], byteColors[2], byteColors[3], strParameters.size() > 0 ? " // " : "", strParameters.size() > 0 ? strParameters.c_str() : "");
			}
		}
		else
		{
			pLocalPlayer->GetPosition(vecPosition);
			int iModelId = pLocalPlayer->GetPlayerPed()->GetModelIndex();
			fprintf_s(file, "PlayerData(%d, %f, %f, %f, %f);%s%s\n", iModelId, vecPosition.fX, vecPosition.fY, vecPosition.fZ, pLocalPlayer->GetRotation() ,strParameters.size() > 0 ? " // " : "", strParameters.size() > 0 ? strParameters.c_str() : "");
		}

		fclose(file);
		g_pCore->GetChat()->Output("Position data saved to 'SavePositions.log'");
		return true;
	}
	else if(strCommand == "giveweapon")
	{
		int iWeapon = atoi(strParameters.c_str());
		CIVScript::GiveWeaponToChar(g_pCore->GetGame()->GetLocalPlayer()->GetScriptingHandle(),(CIVScript::eWeapon)iWeapon, 100, true);
		return true;
	}
	else if(strCommand == "xaxis")
	{
		CVector3 vecPositon;
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecPositon);

		vecPositon.fX += atoi(strParameters.c_str());
		g_pCore->GetGame()->GetLocalPlayer()->SetPosition(vecPositon);
		return true;
	}
	else if(strCommand == "time")
	{
		CIVWeather::SetTime(atoi(strParameters.c_str()),0);
		return true;
	}
	else if(strCommand == "setmodel")
	{
		g_pCore->GetGame()->GetLocalPlayer()->SetModel(atoi(strParameters.c_str()));
		return true;
	}
	else if(strCommand == "testweapon")
	{
		CIVScript::GiveWeaponToChar(g_pCore->GetGame()->GetLocalPlayer()->GetScriptingHandle(),CIVScript::WEAPON_EPISODIC_11,99,false);
		return true;
	}
	else if(strCommand == "ready")
	{
		PTR_CHAT->Output("Installing prachute...");
		CEFLCSupport::InstallPreGameLoad();
		return true;
	}
	else if(strCommand == "parachute")
	{
		PTR_CHAT->Output("Adding prachute...");

		CVector3 vecPosition;
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecPosition);
		unsigned int uiPlayerIndex = g_pCore->GetGame()->GetLocalPlayer()->GetScriptingHandle();

		DWORD dwParachute = 0x58D6A0A0;
		
		//CIVScript::GiveWeaponToChar(uiPlayerIndex, 41, 1, false);
		//CIVScript::CreateObject(dwParachute, vecPosition.fX, vecPosition.fY, vecPosition.fZ + 2, &pObj, 1);
		//CIVScript::AttachObjectToPed(pObj, uiPlayerIndex, 0, 0.02500000, -0.12500000, 5.45000000, 0.00000000, 0.00000000, 0.00000000, 1);

		if(pObj != NULL)
			CIVScript::DeleteObject(&pObj);

		dwParachute = 0x4C19FE43; //0x402B7648;
		CIVScript::CreateObject(dwParachute, vecPosition.fX, vecPosition.fY, -25.0 , &pObj, 1);
		l_U40 = pObj;

		CIVScript::SetObjectDynamic(pObj, 0);
		CIVScript::SetObjectCollision(pObj, 0);
		CIVScript::SetObjectVisible(pObj, 0);
		CIVScript::SetActivateObjectPhysicsAsSoonAsItIsUnfrozen(pObj, 1);

		CIVScript::SetObjectDynamic( pObj, 1 );
        CIVScript::SetObjectCollision( pObj, 1 );
        CIVScript::SetObjectVisible( pObj, 1 );
		CIVScript::AttachObjectToPed( pObj, uiPlayerIndex, 1202, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 1 );
		CIVScript::PlayObjectAnim( pObj, "obj_chute_off", "PARACHUTE", 1000.00000000, 0, 1 );
		CIVScript::TaskPlayAnimWithFlags( uiPlayerIndex, "chute_off", "PARACHUTE", 3.00000000, 0, 1280 );
		return true;
	}
	else if(strCommand == "bahama")
	{
		CVector3 vecPos = CVector3(-15.9453f, -13.5865f, -11.7456f);
		g_pCore->GetGame()->GetLocalPlayer()->CPlayerEntity::Teleport(vecPos);
		return true;
	}
	else if(strCommand == "spawnvehicles")
	{
		CVector3 vecPos;
		PTR_LOCALPLAYER->GetPosition(vecPos);

		for(int i = 0; i < 179; i++) {
			vecPos.fX += 5;
			CVehicleEntity * pVehicle = new CVehicleEntity(i,vecPos,0.0f,0,0,0,0);
			if(pVehicle)
			{
				// Add our vehicle
				g_pCore->GetGame()->GetVehicleManager()->Add(pVehicle);

				pVehicle->SetId(g_pCore->GetGame()->GetVehicleManager()->FindFreeSlot());

				pVehicle->Create();

				pVehicle->SetPosition(vecPos);
			}
		}
		return true;
	}
	else if(strCommand == "getvehpos")
	{
		int iVehicle = atoi(strParameters.c_str());

		if(g_pCore->GetGame()->GetVehicleManager()->DoesExists(iVehicle)) {
			CVector3 vecPosition;
			g_pCore->GetGame()->GetVehicleManager()->GetAt(iVehicle)->GetPosition(vecPosition);
			PTR_CHAT->Outputf(false,"Position of vehicle %d: %f, %f,%f",iVehicle, vecPosition.fX, vecPosition.fY, vecPosition.fZ);
		}
	}
	else if(strCommand == "ivhelp")
	{
		PTR_CHAT->Output(false, "List of Default IV:MP Commands...");
		PTR_CHAT->Output(false, "** /cv /respawn /debug /weapon /cp /spawn /engine /save /giveweapon /xaxis /time");
		PTR_CHAT->Output(false, "** /setmodel /testweapon /ready /parachute /bahama /spawnvehicles /getvehpos");
		return true;
	}	
}
Exemple #11
0
bool CClientCommands::HandleUserInput(CString strCommand, CString strParameters)
{
	if(strCommand == "q"  || strCommand == "quit")
	{
		// Are we connected to the network?
		if(g_pCore->GetNetworkManager()->IsConnected())
		{
			// Disconnect and shutdown RakNet
			g_pCore->GetNetworkManager()->Shutdown(500, true);
		}
		
		TerminateProcess(GetCurrentProcess(), 0);
		return true;
	}
	else if(strCommand == "qq" || strCommand == "quickquit")
	{
		TerminateProcess(GetCurrentProcess(), 0);
		return true;
	}
	else if (strCommand == "saveposition" || strCommand == "save")
	{
		FILE * file = fopen(SharedUtility::GetAbsolutePath("multiplayer//SavePositions.log"), "a");
		if (!file)
		{
			g_pCore->GetChat()->Print("Failed to open 'SavePositions.log'");
			return true;
		}

		CVector3 vecPosition;

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

		if (pLocalPlayer->IsInVehicle())
		{
			CVehicleEntity * pVehicle = pLocalPlayer->GetVehicleEntity();

			if (pVehicle)
			{
				pVehicle->GetPosition(vecPosition);
				CVector3 vecRotation;
				pVehicle->GetRotation(vecRotation);
				DWORD dwColors[5];
				pVehicle->GetColors(dwColors[0], dwColors[1], dwColors[2], dwColors[3], dwColors[4]);
				fprintf_s(file, "createVehicle(%d, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d, %d);%s%s\n", CIVModelManager::ModelHashToVehicleId(pVehicle->GetModelInfo()->GetHash()), vecPosition.fX, vecPosition.fY, vecPosition.fZ, vecRotation.fX, vecRotation.fY, vecRotation.fZ, dwColors[0], dwColors[1], dwColors[2], dwColors[3], dwColors[4], strParameters.GetLength() > 0 ? " // " : "", strParameters.GetLength() > 0 ? strParameters.Get() : "");
			}
		}
		else
		{
			pLocalPlayer->GetPosition(vecPosition);
			int iModelId = pLocalPlayer->GetPlayerPed()->GetModelIndex();
			fprintf_s(file, "PlayerData(%d, %f, %f, %f, %f);%s%s\n", iModelId, vecPosition.fX, vecPosition.fY, vecPosition.fZ, pLocalPlayer->GetHeading(), strParameters.GetLength() > 0 ? " // " : "", strParameters.GetLength() > 0 ? strParameters.Get() : "");
		}

		fclose(file);
		g_pCore->GetChat()->Print("Position data saved to 'SavePositions.log'");
		return true;
	}
#ifdef _DEBUG
	else if(strCommand == "cv")
	{
		CVector3 vecCreatePos; 
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecCreatePos);
		vecCreatePos.fX += 4;

		CVehicleEntity * pVehicle = new CVehicleEntity(atoi(strParameters.Get()), vecCreatePos, 0.0f, 0x000000, 0x000000, 0x000000, 0x000000, 0xFFFFFF);
		if(pVehicle) {
			// Add our vehicle
			pVehicle->SetId(g_pCore->GetGame()->GetVehicleManager()->Add(pVehicle));
			pVehicle->Create();
			g_pCore->GetGame()->GetLocalPlayer()->WarpIntoVehicle(pVehicle);
		}
		return true;
	}
	else if(strCommand == "respawn")
	{
		g_pCore->GetGame()->GetLocalPlayer()->Respawn();
		return true;
	}
	else if(strCommand == "cp")
	{
		CVector3 vecCreatePos; 
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecCreatePos);

		CPlayerEntity * pPlayer = new CPlayerEntity(false);
		if(pPlayer) {
			pPlayer->SetModel(7);
			pPlayer->Create();
			pPlayer->Teleport(vecCreatePos);
		}
		return true;
	}
	else if(strCommand == "engine") 
	{
		if(g_pCore->GetGame()->GetLocalPlayer()->GetVehicleEntity() != NULL)
			g_pCore->GetGame()->GetLocalPlayer()->GetVehicleEntity()->SetEngineState(!g_pCore->GetGame()->GetLocalPlayer()->GetVehicleEntity()->GetEngineState());
		
		return true;
	}
	else if(strCommand == "giveweapon")
	{
		CIVScript::GiveWeaponToChar(g_pCore->GetGame()->GetLocalPlayer()->GetScriptingHandle(), (CIVScript::eWeapon)atoi(strParameters.Get()), 100, true);
		return true;
	}
	else if(strCommand == "xaxis")
	{
		CVector3 vecPositon;
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecPositon);

		vecPositon.fX += atoi(strParameters.Get());
		g_pCore->GetGame()->GetLocalPlayer()->SetPosition(vecPositon);
		return true;
	}
	else if(strCommand == "yaxis")
	{
		CVector3 vecPositon;
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecPositon);

		vecPositon.fY += atoi(strParameters.Get());
		g_pCore->GetGame()->GetLocalPlayer()->SetPosition(vecPositon);
		return true;
	}
	else if(strCommand == "zaxis")
	{
		CVector3 vecPositon;
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecPositon);

		vecPositon.fZ += atoi(strParameters.Get());
		g_pCore->GetGame()->GetLocalPlayer()->SetPosition(vecPositon);
		return true;
	}
	else if(strCommand == "port")
	{
		CVector3 vecPositon;
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecPositon);
		vecPositon.fX = 900;
		vecPositon.fY = -71;
		vecPositon.fZ += 20;
		g_pCore->GetGame()->GetLocalPlayer()->SetPosition(vecPositon);
		return true;
	}
	else if(strCommand == "time")
	{
		g_pCore->GetTimeManagementInstance()->SetTime(atoi(strParameters.Get()), 0);
		CGameFunction::SetTimeOfDay(atoi(strParameters.Get()), 0);
		return true;
	}
	else if(strCommand == "setmodel")
	{
		g_pCore->GetGame()->GetLocalPlayer()->SetModel(atoi(strParameters.Get()));
		return true;
	}
	else if(strCommand == "setclothes")
	{
		CString strParameter = CString("%s", strParameters.Get());
		g_pCore->GetChat()->Print(strParameter.Get());

		// Get the end of the command
		size_t sCommandEnd = strParameter.Find(" "); 

		// If we don't have a valid end use the end of the string
		if (sCommandEnd == std::string::npos)
		{
			sCommandEnd = strParameter.GetLength();
		}

		// Get the command name
		std::string strCommand2 = strParameter.Substring(0, (sCommandEnd));

		// Get the command parameters
		std::string strParams;

		// Do we have any parameters?
		if(sCommandEnd < strParameter.GetLength())
		{
			strParams = strParameter.Substring((sCommandEnd + 1), strParameter.GetLength());
		}

		g_pCore->GetChat()->Print(CString("Setting clothes part %d to %d", atoi(strCommand2.c_str()), atoi(strParams.c_str())));
		g_pCore->GetGame()->GetLocalPlayer()->SetPedClothes(atoi(strCommand2.c_str()), atoi(strParams.c_str()));

		return true;
	}
	else if(strCommand == "bahama")
	{
		g_pCore->GetGame()->GetLocalPlayer()->CPlayerEntity::SetPosition(CVector3(-15.9453f, -13.5865f, -11.7456f));
		return true;
	}
	else if(strCommand == "spawnvehs")
	{
		CVector3 vecPos;
		PTR_LOCALPLAYER->GetPosition(vecPos);

		for (int i = 0; i < 179; i++)
		{
			vecPos.fX += 5;
			CVehicleEntity * pVehicle = new CVehicleEntity(i, vecPos, 0.0f, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF);
			if(pVehicle)
			{
				// Add our vehicle
				g_pCore->GetGame()->GetVehicleManager()->Add(pVehicle);
				pVehicle->SetId(g_pCore->GetGame()->GetVehicleManager()->FindFreeSlot());
				pVehicle->Create();
				pVehicle->SetPosition(vecPos, true);
			}
		}
		return true;
	}
	else if(strCommand == "getvehpos")
	{
		int iVehicle = atoi(strParameters.Get());

		if(g_pCore->GetGame()->GetVehicleManager()->DoesExists(iVehicle)) {
			CVector3 vecPosition;
			g_pCore->GetGame()->GetVehicleManager()->GetAt(iVehicle)->GetPosition(vecPosition);
			PTR_CHAT->Print(CString("Position of vehicle %d: %f, %f,%f", iVehicle, vecPosition.fX, vecPosition.fY, vecPosition.fZ));
		}
		return true;
	}
	else if(strCommand == "ivhelp")
	{
		PTR_CHAT->Print("List of Default IV:N Commands...");
		PTR_CHAT->Print("** /cv /respawn /debug /weapon /cp /spawn /engine /save /giveweapon /xaxis /time");
		PTR_CHAT->Print("** /setmodel /testweapon /ready /parachute /bahama /spawnvehicles /getvehpos");
		return true;
	}
	else if(strCommand == "createtrain")
	{
		g_pCore->GetGame()->GetIVManagement()->CreateTrain(g_pCore->GetGame()->GetLocalPlayer()->GetPosition(), 3, 20.0f, 0);
		return true;
	}
	else if(strCommand == "blip")
	{
		unsigned int uiBlip;
		CIVScript_NativeInvoke::Invoke<unsigned int>(CIVScript::NATIVE_ADD_BLIP_FOR_COORD, 0, 0, 0,&uiBlip); 
		CIVScript_NativeInvoke::Invoke<unsigned int>(CIVScript::NATIVE_CHANGE_BLIP_SPRITE, 10);
		return true;
	}
	else if(strCommand == "sethealth")
	{
		g_pCore->GetGame()->GetLocalPlayer()->SetHealth(atoi(strParameters.Get()));
		return true;
	}
	else if (strCommand == "setarmour")
	{
		g_pCore->GetGame()->GetLocalPlayer()->SetArmour(atoi(strParameters.Get()));
		return true;
	}
#endif
#ifdef SYNC_TEST
	else if (strCommand == "syncTest")
	{
		// Add the player
		CPlayerEntity * pPlayer = new CPlayerEntity;
		pPlayer->SetModel(0); // Set temporary to nico lol
		pPlayer->Create();
		pPlayer->SetNick("Keks");
		pPlayer->SetId(1);
		pPlayer->SetColor(0xFFFFFFFF);
		g_pCore->GetGame()->GetPlayerManager()->Add(1, pPlayer);

		CVector3 vecPosition;
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecPosition);
		vecPosition.fX += 2.0f;
		pPlayer->SetPosition(vecPosition);
	}
	else if (strCommand == "getP")
	{
		CVector3 vecPosition;
		g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecPosition);
		vecPosition.fX += 2.0f;
		g_pCore->GetGame()->GetPlayerManager()->GetAt(1)->SetPosition(vecPosition);
	}
	else if (strCommand = "vehicleSync")
	{
		g_pCore->GetGame()->GetLocalPlayer()->PutInVehicle(g_pCore->GetGame()->GetVehicleManager()->GetAt(0), 0);
		CVector3 vecPosition;
		g_pCore->GetGame()->GetPlayerManager()->GetAt(1)->GetPosition(vecPosition);
		CVehicleEntity * pVehicle = new CVehicleEntity(90, vecPosition, 90, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
		if (pVehicle)
		{
			//	// Add our vehicle
			g_pCore->GetGame()->GetVehicleManager()->Add(1, pVehicle);
			pVehicle->SetId(1);
			pVehicle->Create();
			pVehicle->SetPosition(vecPosition, true);
		}
		//g_pCore->GetGame()->GetPlayerManager()->GetAt(1)->PutInVehicle(g_pCore->GetGame()->GetVehicleManager()->GetAt(0), 0);

		//CVehicleEntity * pVehicle = new CVehicleEntity(90, vecPosition, 90, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
		//if (pVehicle)
		//{
		//	//	// Add our vehicle
		//	g_pCore->GetGame()->GetVehicleManager()->Add(vehicleId, pVehicle);
		//	pVehicle->SetId(vehicleId);
		//	pVehicle->Create();
		//	pVehicle->SetPosition(vecPosition, true);
		//}
	}
#endif
	return false;
}
Exemple #12
0
void CVehiclePool::Process()
{
	// Process all vehicles in the vehicle pool.
	CVehicle *pVehicle;
	DWORD dwThisTime = GetTickCount();
	
	CPlayerPool* pPlayerPool = pNetGame->GetPlayerPool();
	CLocalPlayer* pLocalPlayer = pPlayerPool->GetLocalPlayer();

	int iLocalPlayersInRange = 0;
	if (pLocalPlayer)
		iLocalPlayersInRange = pLocalPlayer->DetermineNumberOfPlayersInLocalRange();

	ProcessWaitingList();

	for(VEHICLEID x = 0; x != MAX_VEHICLES; x++)
	{
		if(GetSlotState(x) == TRUE)
		{
			// It's in use.
			pVehicle = m_pVehicles[x];

			if(m_bIsActive[x])
			{
				if(pVehicle->IsDriverLocalPlayer()) {
					pVehicle->SetInvulnerable(FALSE);
				} else {
					pVehicle->SetInvulnerable(TRUE);
				}

				if (pVehicle->GetHealth() == 0.0f) // || pVehicle->IsWrecked()) // It's dead
				{
					if (pLocalPlayer->m_LastVehicle == x) // Notify server of death
					{
						NotifyVehicleDeath(x);
					}
					continue;
				}
	
				if( pVehicle->GetVehicleSubtype() != VEHICLE_SUBTYPE_BOAT &&
					pVehicle->HasSunk() ) // Not boat and has sunk.
				{
					if (pLocalPlayer->m_LastVehicle == x) {
						NotifyVehicleDeath(x);
					}
					continue;
				}
									
				// Active and in world.
				pLocalPlayer->ProcessUndrivenSync(x, pVehicle, iLocalPlayersInRange); // sync unoccupied vehicle if needed

				/* This has an impact on undriven passenger sync. check for driver instead 
				// Kye: This the source of the audio bug?
				if(!pVehicle->IsOccupied()) {
					pVehicle->SetEngineState(FALSE);
				} else {
					pVehicle->SetEngineState(TRUE);
				}*/

				// Update the actual ingame pointer if it's not the same as the one we have listed.
				if(pVehicle->m_pVehicle != m_pGTAVehicles[x]) {
					m_pGTAVehicles[x] = pVehicle->m_pVehicle;
				}

				pVehicle->ProcessMarkers();
			}
		}
	}
}
Exemple #13
0
void CChat::ProcessInput( void )
{
	// Are we not connected?
	if( !pCore->GetNetworkModule() || !pCore->GetNetworkModule()->IsConnected() )
		return;

	// Was anything entered?
	if( m_strInput.GetLength() > 0 )
	{
		// Is the input a command?
		bool bIsCommand = (m_strInput.GetChar( 0 ) == CHAT_CMD_CHAR);

		// Internal cmds
		bool bHasUsedCmd = false;

		// Process internal commands
		if( bIsCommand )
		{
			//
			std::string sInput = m_strInput.Get();

			// Get the end of the command
			size_t sCommandEnd = sInput.find( " " );

			// If we don't have a valid end use the end of the string
			if ( sCommandEnd == std::string::npos )
				sCommandEnd = sInput.length();

			// Get the command name
			std::string strCommand = sInput.substr( 1, (sCommandEnd - 1) );

			// Get the command parameters
			std::string strParams;

			// Do we have any parameters?
			if( sCommandEnd < sInput.length() )
				strParams = sInput.substr( (sCommandEnd + 1), sInput.length() );

			if( strCommand == "q" || strCommand == "quit" || strCommand == "exit" )
			{
				// Shutdown
				pCore->Shutdown();
				return;
			}
			else if( strCommand == "disconnect" )
			{
				// Are we connected?
				if( pCore->GetNetworkModule() && pCore->GetNetworkModule()->IsConnected() )
				{
					// Disconnect from the network
					pCore->GetNetworkModule()->Disconnect();

					// Stop multiplayer
					pCore->StopMultiplayer();

					// Go back to main menu
					pCore->GetGUI()->GetMainMenu()->SetVisible( true );
				}

				bHasUsedCmd = true;
			}
			else if( strCommand == "savepos" )
			{
				bHasUsedCmd = true;

				// Are we spawned?
				if( pCore->GetPlayerManager()->GetLocalPlayer()->IsSpawned() )
				{
					//
					CVector3 vecPosition;
					CVector3 vecRotation;
					bool bOnFoot = true;

					// Is the player on-foot?
					if( pCore->GetPlayerManager()->GetLocalPlayer()->GetState() == ePlayerState::PLAYERSTATE_ONFOOT )
					{
						// Get the localplayer position
						pCore->GetPlayerManager()->GetLocalPlayer()->GetPosition( &vecPosition );

						// Get the localplayer rotation
						pCore->GetPlayerManager()->GetLocalPlayer()->GetRotation( &vecRotation );
					}
					else if( pCore->GetPlayerManager()->GetLocalPlayer()->GetState() == ePlayerState::PLAYERSTATE_DRIVER || pCore->GetPlayerManager()->GetLocalPlayer()->GetState() == ePlayerState::PLAYERSTATE_PASSENGER )
					{
						// Get the vehicle position
						pCore->GetPlayerManager()->GetLocalPlayer()->GetVehicle()->GetPosition( &vecPosition );

						// Get the vehicle rotation
						pCore->GetPlayerManager()->GetLocalPlayer()->GetVehicle()->GetRotation( &vecRotation );

						//
						bOnFoot = false;
					}

					// Open the saved positions file
					FILE * pFile = fopen( SharedUtility::GetAbsolutePath( "data\\savedpositions.txt" ).Get(), "a" );

					// Did the file open?
					if( pFile )
					{
						// Get the localplayer pointer
						CLocalPlayer * pLocalPlayer = pCore->GetPlayerManager()->GetLocalPlayer();

						// Save the player position
						fprintf( pFile, "%d, %f, %f, %f, %f, %f, %f // %s\n", (bOnFoot ? pLocalPlayer->GetModel () : pLocalPlayer->GetVehicle()->GetModel ()), vecPosition.fX, vecPosition.fY, vecPosition.fZ, vecRotation.fX, vecRotation.fY, vecRotation.fZ, strParams.c_str() );

						// Close the saved positions file
						fclose( pFile );

						//
						AddInfoMessage( (bOnFoot ? " -> Onfoot position saved!" : " -> Invehicle position saved!") );
					}
					else
					{
						//
						AddInfoMessage( CColor( 255, 0, 0, 255 ), "Failed to open savedpositions.txt" );
					}
				}
			}
#ifdef DEBUG
			else if( strCommand == "lua" )
			{
				bHasUsedCmd = true;

				if( CLua::Execute( strParams.c_str() ) )
					AddInfoMessage( CColor( 50, 177, 94, 255 ), strParams.c_str() );
				else
					AddInfoMessage( CColor( 178, 40, 86, 255 ), strParams.c_str() );
			}
#endif
		}

		// Have we used a command?
		if( bHasUsedCmd )
		{
			// Add this command to the history
			AddToHistory();

			// This is an internal command, don't pass it to the server!
			return;
		}

		// Is the network module instance valid?
		if( pCore->GetNetworkModule() )
		{
			// Are we connected?
			if( pCore->GetNetworkModule()->IsConnected() )
			{
				RakNet::BitStream bitStream;
				RakNet::RakString strInput;

				// Is this a command?
				if( bIsCommand )
				{
					// Write 1
					bitStream.Write1();

					// Set the input minus the command character
					strInput = (GetInputText() + 1);
				}
				else
				{
					// Write 0
					bitStream.Write0();

					// Set the input
					strInput = GetInputText();
				}

				// Write the input
				bitStream.Write( strInput );

				// Call the client event
				CSquirrelArguments pArguments;
				pArguments.push( strInput.C_String () );

				// Should we send this message?
				if ( pCore->GetClientScriptingManager()->GetEvents()->Call( "onClientChat", &pArguments ).GetInteger() == 1 )
				{
					// Send it to the server
					pCore->GetNetworkModule()->Call( RPC_PLAYER_CHAT, &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, true );

					// Add this message to the history
					AddToHistory();

					// Add the chat message for the localplayer if it's not a command
					if ( !bIsCommand )
						AddChatMessage( pCore->GetPlayerManager()->GetLocalPlayer(), GetInputText() );
				}
			}
		}
	}
}
void CNetworkManager::Process()
{
	// Get our file transfer manager
	CFileTransferManager * pFileTransferManager = g_pClient->GetFileTransfer();

	// If our file transfer class exists process it
	if(pFileTransferManager)
		pFileTransferManager->Process();

	// Have we joined a server and not joined a game yet?
	if(m_bJoinedServer && !m_bJoinedGame)
	{
		// Get our local player
		CLocalPlayer * pLocalPlayer = g_pClient->GetLocalPlayer();

		// Is the file transfer list empty?
		if(pFileTransferManager->IsComplete() && pLocalPlayer->IsConnectFinished())
		{
			// Flag ourselves as joined a game
			m_bJoinedGame = true;

			// Respawn the local player
			pLocalPlayer->Respawn();
		}
	}

	if(!m_pNetClient)
		return;

	// Process the net client
	m_pNetClient->Process();

	// Are we connected to a server?
	if(m_pNetClient->IsConnected())
	{
		// If our streamer exists, process it
		CStreamer * pStreamer = g_pClient->GetStreamer();

		if(pStreamer)
			pStreamer->Pulse();

		// Is our script timer manager exists, process it
		CScriptTimerManager * pScriptTimerManager = g_pClient->GetClientScriptManager()->GetScriptTimerManager();
		if(pScriptTimerManager)
			pScriptTimerManager->Pulse();

		// If our player manager exists process it
		CPlayerManager * pPlayerManager = g_pClient->GetPlayerManager();

		if(pPlayerManager)
			pPlayerManager->Pulse();

		// If our vehicle manager exists process it
		CVehicleManager * pVehicleManager = g_pClient->GetVehicleManager();

		if(pVehicleManager)
			pVehicleManager->Pulse();

		// If our checkpoint manager exists process it
		CCheckpointManager * pCheckpointManager = g_pClient->GetCheckpointManager();

		if(pCheckpointManager)
			pCheckpointManager->Pulse();

		// If our object manager exists process it
		CObjectManager * pObjectManager = g_pClient->GetObjectManager();

		if(pObjectManager)
			pObjectManager->Process();

		// Process the audio manager
		CAudioManager * pAudioManager = g_pClient->GetAudioManager();

		if(pAudioManager)
			pAudioManager->Process();

		// Process the actor manager
		CActorManager * pActorManager = g_pClient->GetActorManager();

		if(pActorManager)
			pActorManager->Process();
	}
}
void DisableVehicleInfos(char * szParams)
{
	// Get our local player
	CLocalPlayer * pLocalPlayer = g_pClient->GetLocalPlayer();
	pLocalPlayer->SetVehicleInfos(!pLocalPlayer->GetVehicleInfos());
}