From e8d636a52501e9c16af7a23f230ef1506e6f0ff0 Mon Sep 17 00:00:00 2001 From: iAmir Date: Sat, 7 Oct 2023 17:43:59 +0330 Subject: [PATCH] initialize player object data on player pool entry create --- Server/Components/Objects/objects_impl.hpp | 2 ++ Server/Components/Objects/objects_main.cpp | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Server/Components/Objects/objects_impl.hpp b/Server/Components/Objects/objects_impl.hpp index 7def53c4c..edb38418f 100644 --- a/Server/Components/Objects/objects_impl.hpp +++ b/Server/Components/Objects/objects_impl.hpp @@ -417,6 +417,8 @@ class ObjectComponent final : public IObjectsComponent, public CoreEventHandler, void onPoolEntryDestroyed(IPlayer& player) override; + void onPoolEntryCreated(IPlayer& player) override; + void onPlayerStreamIn(IPlayer& player, IPlayer& forPlayer) override; // Pre-spawn so you can safely attach onPlayerSpawn diff --git a/Server/Components/Objects/objects_main.cpp b/Server/Components/Objects/objects_main.cpp index 92e0ffa8b..ce2a21ce7 100644 --- a/Server/Components/Objects/objects_main.cpp +++ b/Server/Components/Objects/objects_main.cpp @@ -33,20 +33,21 @@ void ObjectComponent::onTick(Microseconds elapsed, TimePoint now) void ObjectComponent::onPlayerConnect(IPlayer& player) { - auto player_data = new PlayerObjectData(*this, player); - player.addExtension(player_data, true); - // If client is using 0.3.7 or artwork isn't enabled we can create objects right on connect. // If not we need to wait for client to download custom models before creating objects. static bool artwork = (core->getConfig().getBool("artwork.enable")) ? (*core->getConfig().getBool("artwork.enable")) : false; if (artwork && player.getClientVersion() == ClientVersion::ClientVersion_SAMP_03DL) return; - player_data->setStreamedGlobalObjects(true); - for (IObject* o : storage) + auto playerData = reinterpret_cast(queryExtension(player)); + if (playerData) { - Object* obj = static_cast(o); - obj->createForPlayer(player); + playerData->setStreamedGlobalObjects(true); + for (IObject* o : storage) + { + Object* obj = static_cast(o); + obj->createForPlayer(player); + } } } @@ -168,6 +169,12 @@ void ObjectComponent::onPoolEntryDestroyed(IPlayer& player) } } +void ObjectComponent::onPoolEntryCreated(IPlayer& player) +{ + auto playerData = new PlayerObjectData(*this, player); + player.addExtension(playerData, true); +} + COMPONENT_ENTRY_POINT() { return new ObjectComponent();