Skip to content

Commit

Permalink
add getElementBaseModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Aug 1, 2024
1 parent 6a82134 commit 6fe0f45
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions newmodels_reborn/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<export function="setPickupType" type="shared"/>
<export function="setElementModel" type="shared"/>
<export function="getElementModel" type="shared"/>
<export function="getElementBaseModel" type="shared"/>
<export function="getBaseModelIdFromCustomModelId" type="shared"/>
<export function="import" type="shared"/>

Expand Down
14 changes: 13 additions & 1 deletion newmodels_reborn/scripts/core/shared_exported.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,19 @@ end
function getElementModel(element)
assert(isElement(element), "Invalid element passed: " .. tostring(element))
assert(isValidElement(element), "Invalid element type passed: " .. getElementType(element))
return getElementData(element, getCustomModelDataKey(element)) or _getElementModel(element)
return tonumber(getElementData(element, getCustomModelDataKey(element))) or _getElementModel(element)
end

function getElementBaseModel(element)
if not isClientsideScript then
return getElementModel(element)
end
local customModel = tonumber(getElementData(element, getCustomModelDataKey(element)))
if not customModel then
return getElementModel(element)
end
local customModelInfo = getSharedCustomModelsTable()[customModel]
return customModelInfo and customModelInfo.baseModel or nil
end

-- PS. You can't set element model on a pickup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,7 @@ function getModList()
end

function getBaseModel(element)
if not isClientsideScript then
return getElementModel(element)
else
local customModel = tonumber(getElementData(element, getCustomModelDataKey(element)))
if customModel then
local customModelInfo = getSharedCustomModelsTable()[customModel]
return customModelInfo and customModelInfo.baseModel or nil
else
return getElementModel(element)
end
end
return getElementBaseModel(element)
end

function isCustomModID(id)
Expand Down

0 comments on commit 6fe0f45

Please sign in to comment.