Skip to content

Commit

Permalink
Add "includeCustom" argument for getValidPedModels clientside (#3796)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha authored Oct 15, 2024
1 parent 7e6b4d0 commit 889567a
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,40 @@

int CLuaFunctionDefs::GetValidPedModels(lua_State* luaVM)
{
int iIndex = 0;
bool includeCustom;
CScriptArgReader argStream(luaVM);
argStream.ReadBool(includeCustom, true);

auto* modelManager = g_pClientGame->GetManager()->GetModelManager();

std::size_t index = 0;
lua_newtable(luaVM);

// Gather GTASA default skins
for (int i = 0; i <= 312; i++)
// Gather default and possibly custom GTASA ped model IDs
for (std::size_t i = 0; i <= 312; i++)
{
if (CClientPlayerManager::IsValidModel(i))
{
lua_pushnumber(luaVM, ++iIndex);
// Skip custom skins if not requested
if (!includeCustom && modelManager->FindModelByID(i))
continue;

lua_pushnumber(luaVM, ++index);
lua_pushnumber(luaVM, i);
lua_settable(luaVM, -3);
}
}

// 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 auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::PED, 313))
if (includeCustom)
{
lua_pushnumber(luaVM, ++iIndex);
lua_pushnumber(luaVM, model->GetModelID());
lua_settable(luaVM, -3);
// Gather the rest of custom skin model IDs allocated with engineRequestModel
// (there are usually 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 auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::PED, 313))
{
lua_pushnumber(luaVM, ++index);
lua_pushnumber(luaVM, model->GetModelID());
lua_settable(luaVM, -3);
}
}

return 1;
Expand Down

0 comments on commit 889567a

Please sign in to comment.