diff --git a/dGame/dComponents/ActivityComponent.cpp b/dGame/dComponents/ActivityComponent.cpp index 7567e20b..c5436df8 100644 --- a/dGame/dComponents/ActivityComponent.cpp +++ b/dGame/dComponents/ActivityComponent.cpp @@ -325,9 +325,8 @@ bool ActivityComponent::CheckCost(Entity* player) const { } bool ActivityComponent::TakeCost(Entity* player) const { - auto* inventoryComponent = player->GetComponent(); - return CheckCost(player) && inventoryComponent->RemoveItem(m_ActivityInfo.optionalCostLOT, m_ActivityInfo.optionalCostCount, eInventoryType::ALL); + return CheckCost(player) && inventoryComponent && inventoryComponent->RemoveItem(m_ActivityInfo.optionalCostLOT, m_ActivityInfo.optionalCostCount, eInventoryType::ALL); } void ActivityComponent::PlayerReady(Entity* player, bool bReady) { diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 8749d64e..6d0f675b 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -33,7 +33,7 @@ #endif RacingControlComponent::RacingControlComponent(Entity* parent, const int32_t componentID) - : Component(parent, componentID) { + : ActivityComponent(parent, componentID) { m_PathName = u"MainPath"; m_NumberOfLaps = 3; m_RemainingLaps = m_NumberOfLaps; @@ -70,7 +70,7 @@ void RacingControlComponent::OnPlayerLoaded(Entity* player) { auto* vehicle = inventoryComponent->FindItemByLot(8092); // If the race has already started, send the player back to the main world. - if (m_Loaded || !vehicle) { + if (m_Loaded || !vehicle || !TakeCost(player)) { auto* characterComponent = player->GetComponent(); if (characterComponent) characterComponent->SendToZone(m_MainWorld); return; diff --git a/dGame/dComponents/RacingControlComponent.h b/dGame/dComponents/RacingControlComponent.h index a1e99e29..b4300d94 100644 --- a/dGame/dComponents/RacingControlComponent.h +++ b/dGame/dComponents/RacingControlComponent.h @@ -6,7 +6,7 @@ #include "BitStream.h" #include "Entity.h" -#include "Component.h" +#include "ActivityComponent.h" #include "eReplicaComponentType.h" #include @@ -104,7 +104,7 @@ struct RacingPlayerInfo { /** * Component that's attached to a manager entity in each race zone that loads player vehicles, keep scores, etc. */ -class RacingControlComponent final : public Component { +class RacingControlComponent final : public ActivityComponent { public: static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL; diff --git a/dScripts/ActivityManager.cpp b/dScripts/ActivityManager.cpp index 060fda08..047eb76f 100644 --- a/dScripts/ActivityManager.cpp +++ b/dScripts/ActivityManager.cpp @@ -7,6 +7,7 @@ #include "Logger.h" #include "Loot.h" #include "ShootingGalleryComponent.h" +#include "RacingControlComponent.h" bool ActivityManager::IsPlayerInActivity(Entity* self, LWOOBJID playerID) { const auto* sac = self->GetComponent(); @@ -99,6 +100,8 @@ bool ActivityManager::TakeActivityCost(const Entity* self, const LWOOBJID player activityComponent = self->GetComponent(); } + if (!activityComponent) return false; + auto* player = Game::entityManager->GetEntity(playerID); if (player == nullptr) return false;