Difference between revisions of "EngineRequestModel"

From Multi Theft Auto: Wiki
(Added an example)
(Syntax)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
 
{{Client function}}
 
{{Client function}}
 
{{New feature/item|3.0160|1.5.7|20147|This function is used to assign the next available model ID to a certain element type. Currently only "ped" is supported.}}
 
{{New feature/item|3.0160|1.5.7|20147|This function is used to assign the next available model ID to a certain element type. Currently only "ped" is supported.}}
{{Note|
 
Needs checking / improving.}}
 
  
 
==Syntax==
 
==Syntax==
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
bool engineRequestModel ( str elementType )
+
int engineRequestModel ( str elementType )
 
</syntaxhighlight>
 
</syntaxhighlight>
 
===Required Arguments===
 
===Required Arguments===

Latest revision as of 12:53, 13 September 2019

FROM VERSION 1.5.7 r20147 ONWARDS
This function is used to assign the next available model ID to a certain element type. Currently only "ped" is supported.

Syntax

int engineRequestModel ( str elementType )

Required Arguments

  • elementType: this must be "ped".

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.

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)

See Also

FROM VERSION 1.5.7 r19626 ONWARDS
FROM VERSION 1.5.7 r20147 ONWARDS