EngineRequestModel: Difference between revisions
Fernando187 (talk | contribs) m (add info about newmodels resource) |
m (Added changelog) |
||
Line 3: | Line 3: | ||
{{New feature/item|3.0158|1.5.7|20147|This function is used to assign the next available model ID to a certain element type.}} | {{New feature/item|3.0158|1.5.7|20147|This function is used to assign the next available model ID to a certain element type.}} | ||
{{ | {{Tip|For most cases, you will probably want to add models to your server that are synced with all clients automatically. This is possible with this '''resource''': [https://forum.multitheftauto.com/topic/133212-rel-add-new-models-library/ newmodels]}} | ||
{{note|Vehicle unique features may be unsupported, see [https://github.com/multitheftauto/mtasa-blue/issues/1861 issue 1861] for examples and details}} | {{note|Vehicle unique features may be unsupported, see [https://github.com/multitheftauto/mtasa-blue/issues/1861 issue 1861] for examples and details}} | ||
{{Important Note|Unlike some other functions, the side-effects of this function aren't reverted on resource stop, so you must manually call [[engineFreeModel]] in [[onClientResourceStop]] (Just like the example below does)}} | {{Important Note|Unlike some other functions, the side-effects of this function aren't reverted on resource stop, so you must manually call [[engineFreeModel]] in [[onClientResourceStop]] (Just like the example below does)}} | ||
==Syntax== | ==Syntax== | ||
Line 21: | Line 22: | ||
{{New feature/item|3.0158|1.5.7|20147| Returns an ''integer'' of the model ID that was available to be assigned to the element type, ''false'' if no free model ID available or invalid element type.}} | {{New feature/item|3.0158|1.5.7|20147| Returns an ''integer'' of the model ID that was available to be assigned to the element type, ''false'' if no free model ID available or invalid element type.}} | ||
Do not rely on the model numbers returned being consistent across multiple clients or multiple runs of resources. There is no guarantee for the order of the numbers or that the same numbers will always correspond to the same element type. Any patterns are coincidental. | Do not rely on the model numbers returned being consistent across multiple clients or multiple runs of resources. There is no guarantee for the order of the numbers or that the same numbers will always correspond to the same element type. Any patterns are coincidental. | ||
==Example== | ==Example== | ||
Line 61: | Line 58: | ||
addEventHandler("onClientResourceStop", resourceRoot, onStop) | addEventHandler("onClientResourceStop", resourceRoot, onStop) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Changelog== | |||
{{ChangelogHeader}} | |||
{{ChangelogItem|1.5.8-1.20716|Added support for '''vehicle''' and '''object''' types.}} | |||
{{ChangelogItem|1.6.0-9.22868|Added support for '''object-damageable''' type.}} | |||
==See Also== | ==See Also== | ||
{{Engine functions}} | {{Engine functions}} |
Revision as of 18:59, 16 February 2025
This function is used to assign the next available model ID to a certain element type.
Tip: For most cases, you will probably want to add models to your server that are synced with all clients automatically. This is possible with this resource: newmodels |
Important Note: Unlike some other functions, the side-effects of this function aren't reverted on resource stop, so you must manually call engineFreeModel in onClientResourceStop (Just like the example below does) |
Syntax
int engineRequestModel ( string elementType [, int parentID ] )
Required Arguments
- elementType: "ped", "vehicle", "object", "timed-object", "clump", "object-damageable"
Optional Arguments
- parentID: The ID of the parent model (by default this is: 1337 - objects, 400 - vehicles, 7 - peds, 3425 - clump models, 4715 - timed objects, 994 - damageable objects).
Important Note: parentID should be the same model type to prevent crashes. |
Returns
Returns an integer of the model ID that was available to be assigned to the element type, false if no free model ID available or invalid element type. Do not rely on the model numbers returned being consistent across multiple clients or multiple runs of resources. There is no guarantee for the order of the numbers or that the same numbers will always correspond to the same element type. Any patterns are coincidental.
Example
This example creates a ped and then gives you the opportunity to change its model. If the resource stops, then the IDs allocated will be deallocated. Use /cap for creating the ped and /sap to skin the ped. You will need some skins added to a folder and to the meta.xml for /sap to work:
local peds = {} function createAllocatedPed() local x, y, z = getElementPosition(localPlayer) local id = engineRequestModel("ped") peds[id] = createPed(id, x+0.5, y, z+0.5) outputChatBox("New ped with ID "..id.." created.") end addCommandHandler("cap", createAllocatedPed, false, false) function skinAllocatedPeds() local txd, dff; for id,ped in pairs(peds) do if fileExists("skins/" .. id .. ".txd") and fileExists("skins/" .. id .. ".dff") then txd = engineLoadTXD("skins/" .. id .. ".txd") engineImportTXD(txd, id) dff = engineLoadDFF("skins/" .. id .. ".dff") engineReplaceModel(dff, id) outputChatBox("Model ID "..id.." changed correctly.") else outputChatBox("Model ID "..id.." couldn't change. REASON: skins/" .. id .. ".txd or skins/" .. id .. ".dff does not exist.") end end end addCommandHandler("sap", skinAllocatedPeds, false, false) function onStop() for id,ped in pairs(peds) do engineFreeModel(id) end end addEventHandler("onClientResourceStop", resourceRoot, onStop)
Changelog
Version | Description |
---|
1.5.8-1.20716 | Added support for vehicle and object types. |
1.6.0-9.22868 | Added support for object-damageable type. |
See Also
- engineAddImage
- engineApplyShaderToWorldTexture
- engineFreeModel
- engineGetModelFlags
- engineGetModelIDFromName
- engineGetModelLODDistance
- engineGetModelNameFromID
- engineGetModelPhysicalPropertiesGroup
- engineGetModelTextureNames
- engineGetModelTextures
- engineGetModelTXDID
- engineGetModelVisibleTime
- engineGetObjectGroupPhysicalProperty
- engineGetSurfaceProperties
- engineGetVisibleTextureNames
- engineImageGetFilesCount
- engineImageGetFiles
- engineImageGetFile
- engineImageLinkDFF
- engineImageLinkTXD
- engineImportTXD
- engineLoadCOL
- engineLoadDFF
- engineLoadIMG
- engineLoadIFP
- engineLoadTXD
- engineRemoveImage
- engineRemoveShaderFromWorldTexture
- engineReplaceAnimation
- engineReplaceCOL
- engineReplaceModel
- engineRequestModel
- engineResetModelFlags
- engineResetModelLODDistance
- engineResetSurfaceProperties
- engineRestoreAnimation
- engineRestoreCOL
- engineRestoreDFFImage
- engineRestoreModel
- engineRestoreModelPhysicalPropertiesGroup
- engineRestoreObjectGroupPhysicalProperties
- engineRestoreTXDImage
- engineRestreamWorld
- engineSetAsynchronousLoading
- engineSetModelFlag
- engineSetModelFlags
- engineSetModelLODDistance
- engineSetModelPhysicalPropertiesGroup
- engineSetModelVisibleTime
- engineSetObjectGroupPhysicalProperty
- engineSetSurfaceProperties
- engineStreamingFreeUpMemory
- engineStreamingGetUsedMemory