Files
Elite-Gaming-FiveM/resources/ox_lib/imports/requestModel/client.lua
T
2023-11-16 20:26:05 -08:00

24 lines
796 B
Lua

---Load a model. When called from a thread, it will yield until it has loaded.
---@param model number | string
---@param timeout number? Number of ticks to wait for the model to load. Default is 500.
---@return number? model
function lib.requestModel(model, timeout)
if not tonumber(model) then model = joaat(model) end
---@cast model -string
if HasModelLoaded(model) then return model end
if not IsModelValid(model) then
return error(("attempted to load invalid model '%s'"):format(model))
end
RequestModel(model)
if not coroutine.isyieldable() then return model end
return lib.waitFor(function()
if HasModelLoaded(model) then return model end
end, ("failed to load model '%s'"):format(model), timeout or 500)
end
return lib.requestModel