engineSetModelLODDistance
Pair: engineGetModelLODDistance
Updated in 1.6.0 r22676
This function sets a custom LOD distance for any object / model ID. This is the distance at which objects of that model ID are switched to their LOD model, or (if there is no LOD model) become invisible.
- This function only works with script-created objects, just like objects created with createObject or buildings created with createBuilding. It DOES NOT work with default map objects/buildings.
- If the LOD distance for a high LOD model is set to more than 325, the fade out effect of the model will not trigger and the model will just pop in/pop out of existence.
- The actual draw distance used is modified by the draw distance slider in the settings Video tab of the MTA client.
- When the 'Video' tab draw distance slider is 0%, the engineSetModelLODDistance setting approximately matches the draw distance used. e.g
engineSetModelLODDistance(1337,100)will mean model 1337 will be visible up to a distance of 100 units. - When the Video tab draw distance slider is 100%, the engineSetModelLODDistance setting is approximately doubled before use. e.g.
engineSetModelLODDistance(1337,100)will mean model 1337 will be visible up to a distance of 200 units. - There is a general draw distance limit of 325 units. So
engineSetModelLODDistance(1337,400)will mean model 1337 will be visible up to a distance of 325 units no matter what the Video tab says. - The limit for objects is 325 units, but the actual draw distance used is 5 times the setting value. Also, they ignore the Video tab draw distance slider. So a setting of 200 will mean a low LOD element will always have a draw distance of 1000 units.
- For buildings the distance must be set greater than 300 for a low LOD building in order to work correctly. Otherwise, the low LOD will always be visible. The actual draw distance is NOT 5 times the setting value.
- You can use setVehiclesLODDistance for vehicles and setPedsLODDistance for peds.
Therefore, unless it's really important, engineSetModelLODDistance should not be set to anything greater than 170. 170 will still give the maximum draw distance (of 325 units) on clients that have a Video tab draw distance setting of 100%, and it will help reduce lag for players who chose a lower draw distance in their settings.
OOP Syntax Help! I don't understand this!
- Method:Engine.setModelLODDistance(...)
Syntax
bool engineSetModelLODDistance ( string/int modelNameOrID, float distance, [ bool extendedLod = false ] )Required Arguments
- modelNameOrID: The model ID or name of the model you want to change the LOD distance of.
- distance: New LOD distance value in San Andreas units.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- extendedLod (default: false): Allows to set a greater distance than the current 325 units.
Returns
- bool: result
Returns true if the function executed succesfully, false otherwise.
Code Examples
This example will set the LOD distance of all script-created objects.
-- Client-side-- WARNING: Can cause significant lag.
-- Adjusts LOD for all objects.function setAllObjectsLOD()
-- Get all current objects. local objects = getElementsByType("object", root, false)
for _, theObject in ipairs(objects) do
local modelID = getElementModel(theObject) local lodLevel = 325 -- Distance value
-- Set LOD for this model ID. -- The 'true' enables extended range. engineSetModelLODDistance(modelID, lodLevel, true) endend
-- Command to run the function.addCommandHandler("setAllObjectsLOD", setAllObjectsLOD)Changelog
Added extendedLod argument.
See Also
Engine Functions
- engineAddClothingModelNew
- engineAddClothingTXDNew
- engineAddImageNew
- engineApplyShaderToWorldTexture
- engineFreeModel
- engineFreeTXDNew
- engineGetModelFlagsNew
- engineGetModelIDFromName
- engineGetModelLODDistance
- engineGetModelNameFromID
- engineGetModelPhysicalPropertiesGroup
- engineGetModelTextureNames
- engineGetModelTextures
- engineGetModelTXDIDNew
- engineGetModelVisibleTime
- engineGetObjectGroupPhysicalProperty
- engineGetPoolCapacityNew
- engineGetPoolDefaultCapacityNew
- engineGetPoolUsedCapacityNew
- engineGetSurfaceProperties
- engineGetVisibleTextureNames
- engineImageGetFileNew
- engineImageGetFilesNew
- engineImageGetFilesCountNew
- engineImageLinkDFFNew
- engineImageLinkTXDNew
- engineImportTXD
- engineLoadCOL
- engineLoadDFF
- engineLoadIFP
- engineLoadIMGNew
- engineLoadTXD
- enginePreloadWorldAreaNew
- engineRemoveImageNew
- engineRemoveShaderFromWorldTexture
- engineReplaceAnimation
- engineReplaceCOL
- engineReplaceModel
- engineRequestModel
- engineRequestTXDNew
- engineResetModelFlagsNew
- engineResetModelLODDistance
- engineResetModelTXDIDNew
- engineResetSurfaceProperties
- engineRestoreAnimation
- engineRestoreCOL
- engineRestoreDFFImageNew
- engineRestoreModel
- engineRestoreModelPhysicalPropertiesGroup
- engineRestoreObjectGroupPhysicalProperties
- engineRestoreTXDImageNew
- engineRestreamNew
- engineRestreamModelNew
- engineRestreamWorldUpdated
- engineSetAsynchronousLoading
- engineSetModelFlagNew
- engineSetModelFlagsNew
- engineSetModelLODDistanceUpdated
- engineSetModelPhysicalPropertiesGroupUpdated
- engineSetModelTXDIDNew
- engineSetModelVisibleTime
- engineSetObjectGroupPhysicalProperty
- engineSetPoolCapacityNew
- engineSetSurfaceProperties
- engineStreamingFreeUpMemory
- engineStreamingGetBufferSizeNew
- engineStreamingGetMemorySizeNew
- engineStreamingGetModelLoadStateNew
- engineStreamingGetUsedMemory
- engineStreamingReleaseModelNew
- engineStreamingRequestModelNew
- engineStreamingRestoreBufferSizeNew
- engineStreamingRestoreMemorySizeNew
- engineStreamingSetBufferSizeNew
- engineStreamingSetMemorySizeNew
- engineStreamingSetModelCacheLimitsNew