bool CVehicleEntity::Destroy()
{
	// Is the vehicle not spawned?
	if(!IsSpawned())
		return false;

	// Remove the vehicle from the world
	m_pVehicle->RemoveFromWorld();

	// Remove the vehicle reference
	m_pModelInfo->RemoveReference();

	// Release the entity
	m_pVehicle->GetEntity()->Remove();

	// Mark vehicle as no longer needed
	IVVehicle * pVehicle = m_pVehicle->GetVehicle();
	*(BYTE *)(pVehicle + 3949) |= 8u;
	*(BYTE *)(pVehicle + 4360) = 1; // Disable function call(some loops through arrays..)

	// Destroy the vehicle
	CIVScript::DeleteCar(&m_uiVehicleHandle);

	// Delete the vehicle instance
	SAFE_DELETE(m_pVehicle);

	// Mark as not spawned
	m_bSpawned = false;

	return true;
}
bool CVehicleEntity::Create()
{
	if (m_pModelInfo == NULL)
		return false;

	// Is the vehicle already spawned?
	if (IsSpawned())
		return false;

	// Load the model
	m_pModelInfo->AddReference(true);

	DWORD dwModelHash = m_pModelInfo->GetHash();

	CIVScript::CreateCar(dwModelHash, 0.0f, 0.0f, 0.0f, &m_uiVehicleHandle, true);

    // Create the vehicle instance
	m_pVehicle = new CIVVehicle(g_pCore->GetGame()->GetPools()->GetVehiclePool()->AtHandle(m_uiVehicleHandle));

	// Mark as spawned
	m_bSpawned = true;

	// Reset the vehicle
	Reset();

	CLogFile::Printf("Created vehicle! (Id: %d, Handle: %d)", m_vehicleId, m_uiVehicleHandle);
	return true;
}
Example #3
0
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;
}
Example #4
0
void CNetworkPlayer::RemoveFromVehicle( CNetworkVehicle * pVehicle )
{
	DEBUG_TRACE("CNetworkPlayer::RemoveFromVehicle");

	// Is the player and vehicle valid?
	if( m_pPlayerPed && pVehicle && IsSpawned() )
	{
		// Remove the player from the vehicle
		m_pPlayerPed->GetInOutVehicle( pVehicle->GetVehicle()->GetVehicle(), m_seat, false, true );

		// Handle with the vehicle
		pVehicle->HandlePlayerExit ( this, m_seat );

		// Reset
		SetVehicle ( NULL );
		SetSeat ( INVALID_ENTITY_ID );
		m_playerState = ePlayerState::PLAYERSTATE_ONFOOT;
	}

	// Is the player exiting a vehicle?
	if( m_VehicleExit.m_bIsExiting )
	{
		// Reset
		m_VehicleExit.m_bIsExiting = false;
		m_VehicleExit.m_ulExitStartTime = 0;
		m_VehicleExit.m_pExitAICommand = NULL;
	}
}
Example #5
0
	// get mob info if you fish one up
	void GetMobInfo(CCharEntity* PChar)
	{
		const int8* Query = "SELECT mobid, type,zone \
							FROM fishing_mobs \
							WHERE zone = %u \
							ORDER BY zone ASC";

		int32 ret = Sql_Query(SqlHandle, Query, PChar->getZone());
		int RC = 0;
		// this will pick a random  number from range 1 to max record count
		int RID = rand() % Sql_NumRows(SqlHandle) + 1;

		if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0)
		{
			while (Sql_NextRow(SqlHandle) == SQL_SUCCESS)
			{
				RC = RC + 1;
				if (RC == RID && Sql_GetIntData(SqlHandle, 0) != 0)
				{
					if (IsSpawned(Sql_GetIntData(SqlHandle, 0)) == false)
					{
						mobid[0] = Sql_GetIntData(SqlHandle, 0);
						catchtype[0] = Sql_GetIntData(SqlHandle, 1); // Type
						break;
					}
				}
			}
		}
	}
Example #6
0
void CNetworkPlayer::SetEnteringVehicle( CNetworkVehicle * pNetworkVehicle, EntityId seat )
{
	DEBUG_TRACE("CNetworkPlayer::SetEnteringVehicle");

	// Are we spawned?
	if( IsSpawned() )
	{
		// Is the target vehicle valid?
		if( pNetworkVehicle )
		{
			// Set the target vehicle
			m_VehicleEnter.m_pTargetVehicle = pNetworkVehicle;

			// Set the target seat
			m_VehicleEnter.m_targetSeat = seat;

			// Mark as entering
			m_VehicleEnter.m_bIsEntering = true;

			// Set the enter start time
			m_VehicleEnter.m_ulEnterStartTime = SharedUtility::GetTime();
		}
		else
		{
			// Reset
			m_VehicleEnter.m_pTargetVehicle = NULL;
			m_VehicleEnter.m_targetSeat = INVALID_ENTITY_ID;
			m_VehicleEnter.m_ulEnterStartTime = 0;
			m_VehicleEnter.m_bIsEntering = false;
			SAFE_DELETE( m_VehicleEnter.m_pEnterAICommand );
		}
	}
}
Example #7
0
void CClientVehicle::GetTurnSpeed(CVector3& vecTurnSpeed)
{
	if(IsSpawned())
		m_pVehicle->GetTurnSpeed(&vecTurnSpeed);
	else
		vecTurnSpeed = m_vecTurnSpeed;
}
Example #8
0
void CVehicleEntity::GetPosition(CVector3& vecPosition)
{
	if(IsSpawned())
		m_pVehicle->GetPosition(&vecPosition);
	else
		vecPosition = m_vecPosition;
}
Example #9
0
void CClientVehicle::SetRotation(const CVector3& vecRotation)
{
	if(IsSpawned())
	{
		// Remove the vehicle from the world
		m_pVehicle->RemoveFromWorld();

		// Get the vehicle matrix
		Matrix matMatrix;
		m_pVehicle->GetMatrix(&matMatrix);

		// Convert the rotation to radians and apply it to the vehicle matrix
		CVector3 vecNewRotation = vecRotation;
		ConvertDegreesToRadians(vecNewRotation);
		g_pClient->GetGame()->ConvertEulerAnglesToRotationMatrix(vecNewRotation, matMatrix);

		// Set the new vehicle matrix
		m_pVehicle->SetMatrix(&matMatrix);

		// Re-add the vehicle to the world
		m_pVehicle->AddToWorld();
	}

	m_vecRotation = vecRotation;
}
Example #10
0
void CClientVehicle::SetTurnSpeed(const CVector3& vecTurnSpeed)
{
	if(IsSpawned())
		m_pVehicle->SetTurnSpeed((CVector3 *)&vecTurnSpeed);

	m_vecTurnSpeed = vecTurnSpeed;
}
Example #11
0
unsigned int CClientVehicle::GetScriptingHandle()
{
	if(IsSpawned())
		return CPools::GetVehiclePool()->HandleOf(m_pVehicle->GetVehicle());

	return 0;
}
Example #12
0
PSpawnedVehicle* PVehicles::SpawnVehicle( u32 nVehicleId, u32 nLocation, PVhcCoordinates const* nVhcPos )
{
  PSpawnedVehicle* newVhc = NULL;
  PWorld* cWorld;
  PVehicleInformation nVhcInfo;

  if (( nLocation != PWorlds::mNcSubwayWorldId ) && IsValidVehicle( nVehicleId ) && !IsSpawned( nVehicleId ) )
  {
    cWorld = Worlds->LeaseWorld( nLocation );

    if ( cWorld && GetVehicleInfo( nVehicleId, &nVhcInfo ) )
    {
      newVhc = cWorld->GetSpawnedVehicules()->SpawnVehicle( &nVhcInfo, nVhcPos );
      if ( newVhc )
      {
        if ( !RegisterSpawnedVehicle( newVhc ) )
        {
          Console->Print( RED, BLACK, "[Error] PVehicles::SpawnVehicle : Could not register spawned vhc" );
        }
        if( gDevDebug )
          Console->Print( "%d Spawned vhc %d (local 0x%04x) type %d (requested: %d)", Console->ColorText( CYAN, BLACK, "[DEBUG]" ), newVhc->GetVehicleId(), newVhc->GetLocalId(), newVhc->GetInformation().GetVehicleType(), nVhcInfo.GetVehicleType() );
      }
      else
        Console->Print( RED, BLACK, "[Error] PVehicles::SpawnVehicle : Could not create vhc" );
    }

    Worlds->ReleaseWorld( nLocation );
  }

  return newVhc;
}
Example #13
0
void CLocalPlayer::Pulse()
{
	CPlayerEntity::Pulse();

	if(IsSpawned()) {
		DoDeathCheck();
		
		if(!m_bParachuteCheck) {

			// Create "simulated" parachute
			CIVScript::GiveWeaponToChar(GetScriptingHandle(), 41, 1, false);
			DWORD dwParachute = 0x4C19FE43; //0x402B7648;
			CVector3 vecCurrPos;
			GetPosition(vecCurrPos);

			CIVScript::CreateObject(dwParachute, vecCurrPos.fX, vecCurrPos.fY, -25.0 , &m_pObj, 1);
			CIVScript::SetObjectDynamic(m_pObj, 1);
			CIVScript::SetObjectCollision(m_pObj, 1);
			CIVScript::SetObjectVisible(m_pObj, 0);
			CIVScript::SetActivateObjectPhysicsAsSoonAsItIsUnfrozen(m_pObj, 1);
			CIVScript::AttachObjectToPed(m_pObj, GetScriptingHandle(), 1202, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 1);

			m_bParachuteCheck = true;
		}

		if(!m_bParachuteIntitialised)
		{
			//g_pCore->GetGame()->OnClientPastGameJoin();
			m_bParachuteIntitialised = true;
		}
	}
	m_bSpawnMarked = true;
}
bool CVehicleEntity::GetVehicleGPSState()
{
	if (IsSpawned())
		return m_pVehicle->GetGPSState();

	return false;
}
Example #15
0
BYTE CClientVehicle::GetMaxPassengers()
{
	if(IsSpawned())
		return m_pVehicle->GetMaxPasssengers();

	return 0;
}
Example #16
0
unsigned int CVehicleEntity::GetScriptingHandle()
{
	if(IsSpawned())
		return g_pCore->GetGame()->GetPools()->GetVehiclePool()->HandleOf(m_pVehicle->GetVehicle());

	return 0;
}
Example #17
0
void CVehicleEntity::SoundHorn(int iDuration)
{
    if(IsSpawned())
		m_pVehicle->SoundHorn(iDuration);

    m_ulHornDurationEnd = (SharedUtility::GetTime() + iDuration);
}
bool CVehicleEntity::GetLightsState()
{
	if (IsSpawned())
		return (m_pVehicle->GetLightsState() == 2);

	return m_bLights;
}
Example #19
0
bool CVehicleEntity::Create()
{
	// Is the vehicle already spawned?
	if(IsSpawned())
		return false;

	// Load the model
	m_pModelInfo->AddReference(true);

	DWORD dwModelHash = m_pModelInfo->GetHash();

	unsigned uiVehicleHandle;
	CIVScript::CreateCar(dwModelHash, 0.0f, 0.0f, 0.0f, &uiVehicleHandle, true);

    // Create the vehicle instance
	m_pVehicle = new CIVVehicle(g_pCore->GetGame()->GetPools()->GetVehiclePool()->AtHandle(uiVehicleHandle));

	// Disable damage
	m_pVehicle->SetCarCanBeDamaged(false);
	m_pVehicle->SetCanBeVisiblyDamaged(false);

	// Reset Indicators
	SetIndicatorState(false,false,true,true);

	// Mark as spawned
	m_bSpawned = true;

	CLogFile::Printf("Created vehicle! (Id: %d, Handle: %d)", m_vehicleId, m_uiVehicleHandle);
	return true;
}
Example #20
0
void CVehicleEntity::SetTargetRotation(const CVector3& vecRotation, unsigned long ulDelay)
{
    // Are we spawned?
    if(IsSpawned())
	{
        // Update our target rotation
        UpdateTargetRotation();

        // Get the current time
        unsigned long ulTime = SharedUtility::GetTime();

        // Get our local rotation
        CVector3 vecLocalRotation;
        GetRotation(vecLocalRotation);

        // Set the target rotation
        m_interp.rot.vecTarget = vecRotation;

        // Get the error
        m_interp.rot.vecError = Math::GetOffsetDegrees(vecLocalRotation, vecRotation);

        // Get the interpolation interval
        m_interp.rot.ulStartTime = ulTime;
        m_interp.rot.ulFinishTime = (ulTime + ulDelay);

        // Initialize the interpolation
        m_interp.rot.fLastAlpha = 0.0f;
    }

    // Set our rotation straight
    m_vecRotation = vecRotation;
}
Example #21
0
void CVehicleEntity::SetTargetPosition(const CVector3& vecPosition, unsigned long ulDelay)
{
    // Are we spawned?
    if(IsSpawned())
    {
        // Update our target position
        UpdateTargetPosition();

        // Get the current time
        unsigned long ulTime = SharedUtility::GetTime();

        // Get our local position
        CVector3 vecLocalPosition;
        GetPosition(vecLocalPosition);

        // Set the target position
        m_interp.pos.vecTarget = vecPosition;

        // Calculate the relative error
        m_interp.pos.vecError = (vecPosition - vecLocalPosition);

        // Apply the error over 400ms (i.e. 1/4 per 100ms)
        m_interp.pos.vecError *= Math::Lerp<const float>(0.25f, Math::UnlerpClamped(100, ulDelay, 400), 1.0f);

        // Get the interpolation interval
        m_interp.pos.ulStartTime = ulTime;
        m_interp.pos.ulFinishTime = (ulTime + ulDelay);

        // Initialize the interpolation
        m_interp.pos.fLastAlpha = 0.0f;
    }

    // Set our position straight
    m_vecPosition = vecPosition;
}
Example #22
0
void CVehicleEntity::SetDoorLockState(DWORD dwDoorLockState)
{
	// Get the actual lock state
	DWORD dwState = 0;

	switch(dwDoorLockState)
	{
		case 0:
			dwState = 0;
			break;
		case 1:
			dwState = 3;
			break;
		case 2:
			dwState = 7;
			break;
		default:
		return;
	}

	m_dwDoorLockState = dwState;

	// Are we spawned?
	if(IsSpawned())
		CIVScript::LockCarDoor(GetScriptingHandle(), m_dwDoorLockState);
}
Example #23
0
void CObject::SetRotation(const CVector3& vecRotation)
{
	// Are we spawned?
	if(IsSpawned())
		Scripting::SetObjectRotation(m_uiObjectHandle, vecRotation.fX, vecRotation.fY, vecRotation.fZ);

	m_vecRotation = vecRotation;
}
Example #24
0
bool CVehicleEntity::GetEngineState()
{
    // Are we spawned?
    if(IsSpawned())
        return m_bEngineStatus;

    return false;
}
Example #25
0
float CVehicleEntity::GetSteeringAngle()
{
    // Are we spawned?
    if(IsSpawned())
        m_pVehicle->GetSteeringAngle();

    return 0.0f;
}
Example #26
0
float CVehicleEntity::GetCarDoorAngle(int iDoor)
{
    // Are we spawned?
    if(IsSpawned())
        return m_fDoor[iDoor];

    return 0.0f;
}
Example #27
0
bool CVehicleEntity::GetTaxiLightsState()
{
    // Are we spawned?
    if(IsSpawned())
        return m_bTaxiLights;

    return false;
}
Example #28
0
void CVehicleEntity::SetTaxiLightsState(bool bState)
{
    // Are we spawned?
    if(IsSpawned())
        CIVScript::SetTaxiLights(GetScriptingHandle(),bState);

    m_bTaxiLights = bState;
}
Example #29
0
BYTE CVehicleEntity::GetMaxPassengers()
{
	// Are we spawned?
	if(IsSpawned())
		return m_pVehicle->GetMaxPasssengers();

	return 0;
}
Example #30
0
float CVehicleEntity::GetDirtLevel()
{
	// Are we spawned?
	if(IsSpawned())
		return m_pVehicle->GetDirtLevel();

	return m_fDirtLevel;
}