diff --git a/Client/mods/deathmatch/logic/CClientModel.h b/Client/mods/deathmatch/logic/CClientModel.h index a39d36f954c..98f6b2932ca 100644 --- a/Client/mods/deathmatch/logic/CClientModel.h +++ b/Client/mods/deathmatch/logic/CClientModel.h @@ -28,12 +28,12 @@ class CClientModel CClientModel(CClientManager* pManager, int iModelID, eClientModelType eModelType); ~CClientModel(void); - int GetModelID(void) { return m_iModelID; }; - eClientModelType GetModelType(void) { return m_eModelType; }; + int GetModelID(void) const { return m_iModelID; }; + eClientModelType GetModelType(void) const { return m_eModelType; }; bool Allocate(void); bool Deallocate(void); void SetParentResource(CResource* pResource) { m_pParentResource = pResource; } - CResource* GetParentResource(void) { return m_pParentResource; } + CResource* GetParentResource(void) const { return m_pParentResource; } protected: CClientManager* m_pManager; diff --git a/Client/mods/deathmatch/logic/CClientModelManager.cpp b/Client/mods/deathmatch/logic/CClientModelManager.cpp index d91d28b154f..ba405722aa9 100644 --- a/Client/mods/deathmatch/logic/CClientModelManager.cpp +++ b/Client/mods/deathmatch/logic/CClientModelManager.cpp @@ -30,6 +30,7 @@ void CClientModelManager::RemoveAll(void) { Remove(m_Models[i]); } + m_modelCount = 0; } void CClientModelManager::Add(CClientModel* pModel) @@ -40,6 +41,7 @@ void CClientModelManager::Add(CClientModel* pModel) return; } m_Models[pModel->GetModelID()] = pModel; + m_modelCount++; } bool CClientModelManager::Remove(CClientModel* pModel) @@ -47,6 +49,7 @@ bool CClientModelManager::Remove(CClientModel* pModel) if (pModel && m_Models[pModel->GetModelID()] != nullptr) { m_Models[pModel->GetModelID()] = nullptr; + m_modelCount--; return true; } return false; @@ -74,6 +77,22 @@ CClientModel* CClientModelManager::FindModelByID(int iModelID) return nullptr; } +std::vector CClientModelManager::GetModelsByType(const eClientModelType type, const unsigned int minModelID) +{ + std::vector found; + found.reserve(m_modelCount); + + for (int i = minModelID; i < MAX_MODEL_ID; i++) + { + CClientModel* model = m_Models[i]; + if (model && model->GetModelType() == type) + { + found.push_back(model); + } + } + return found; +} + void CClientModelManager::DeallocateModelsAllocatedByResource(CResource* pResource) { for (ushort i = 0; i < MAX_MODEL_ID; i++) diff --git a/Client/mods/deathmatch/logic/CClientModelManager.h b/Client/mods/deathmatch/logic/CClientModelManager.h index 664caf875eb..4b8a958cd42 100644 --- a/Client/mods/deathmatch/logic/CClientModelManager.h +++ b/Client/mods/deathmatch/logic/CClientModelManager.h @@ -13,6 +13,7 @@ class CClientModelManager; #pragma once #include +#include #include "CClientModel.h" #define MAX_MODEL_ID 20000 @@ -34,8 +35,12 @@ class CClientModelManager CClientModel* FindModelByID(int iModelID); + std::vector CClientModelManager::GetModelsByType(const eClientModelType type, const unsigned int minModelID = 0); + + void DeallocateModelsAllocatedByResource(CResource* pResource); private: CClientModel* m_Models[MAX_MODEL_ID]; + unsigned int m_modelCount = 0; }; diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp b/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp index 1cef317c3d0..873836847e4 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp @@ -14,6 +14,8 @@ int CLuaFunctionDefs::GetValidPedModels(lua_State* luaVM) { int iIndex = 0; lua_newtable(luaVM); + + // Gather GTASA default skins for (int i = 0; i <= 312; i++) { if (CClientPlayerManager::IsValidModel(i)) @@ -24,6 +26,15 @@ int CLuaFunctionDefs::GetValidPedModels(lua_State* luaVM) } } + // Gather our custom skin model IDs allocated with engineRequestModel + // (there might be some < 313 as well, and since we don't want duplicates, we start at 313, others are already included by the loop above) + for (const CClientModel* model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::CCLIENTMODELPED, 313)) + { + lua_pushnumber(luaVM, ++iIndex); + lua_pushnumber(luaVM, model->GetModelID()); + lua_settable(luaVM, -3); + } + return 1; }