Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Client/mods/deathmatch/logic/CClientModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions Client/mods/deathmatch/logic/CClientModelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void CClientModelManager::RemoveAll(void)
{
Remove(m_Models[i]);
}
m_modelCount = 0;
}

void CClientModelManager::Add(CClientModel* pModel)
Expand All @@ -40,13 +41,15 @@ void CClientModelManager::Add(CClientModel* pModel)
return;
}
m_Models[pModel->GetModelID()] = pModel;
m_modelCount++;
}

bool CClientModelManager::Remove(CClientModel* pModel)
{
if (pModel && m_Models[pModel->GetModelID()] != nullptr)
{
m_Models[pModel->GetModelID()] = nullptr;
m_modelCount--;
return true;
}
return false;
Expand Down Expand Up @@ -74,6 +77,22 @@ CClientModel* CClientModelManager::FindModelByID(int iModelID)
return nullptr;
}

std::vector<CClientModel*> CClientModelManager::GetModelsByType(const eClientModelType type, const unsigned int minModelID)
{
std::vector<CClientModel*> 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++)
Expand Down
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CClientModelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CClientModelManager;
#pragma once

#include <list>
#include <vector>
#include "CClientModel.h"

#define MAX_MODEL_ID 20000
Expand All @@ -34,8 +35,12 @@ class CClientModelManager

CClientModel* FindModelByID(int iModelID);

std::vector<CClientModel*> 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;
};
11 changes: 11 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
}

Expand Down