EngineRequestModel: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{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.0158|1.5.7|20147|This function is used to assign the next available model ID to a certain element type. After release 1.5.8-20716 this function supports "vehicle" and "object" too.}}
 
{{note|IMPORTANT:
*before release 1.5.8-20716 this must be "ped".
}}
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool engineRequestModel ( str elementType )
int engineRequestModel ( str elementType [, int parentID ] )
</syntaxhighlight>
</syntaxhighlight>
===Required Arguments===
===Required Arguments===
*'''elementType''': this must be "ped".
*'''elementType''': "ped", "vehicle" and "object".
 
===Optional Arguments===
*'''parentID''': The [[Vehicle IDs|vehicle ID]] of the vehicle being allocated. '''(By default this is: 1337 - objects, 400 - vehicles, 7 or PSYCHO for peds)'''


===Returns===
===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.
{{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


==Example==
==Example==
Line 48: Line 54:
addEventHandler("onClientResourceStop", resourceRoot, onStop)
addEventHandler("onClientResourceStop", resourceRoot, onStop)
</syntaxhighlight>
</syntaxhighlight>
==Requirements==
{{Requirements|n/a|1.5.7-9.20147|}}


==See Also==
==See Also==
{{Engine functions}}
{{Engine functions}}

Revision as of 05:01, 24 November 2020

This function is used to assign the next available model ID to a certain element type. After release 1.5.8-20716 this function supports "vehicle" and "object" too.

[[{{{image}}}|link=|]] Note: IMPORTANT:
  • before release 1.5.8-20716 this must be "ped".

Syntax

int engineRequestModel ( str elementType [, int parentID ] )

Required Arguments

  • elementType: "ped", "vehicle" and "object".

Optional Arguments

  • parentID: The vehicle ID of the vehicle being allocated. (By default this is: 1337 - objects, 400 - vehicles, 7 or PSYCHO for peds)

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)

Requirements

Minimum server version n/a
Minimum client version 1.5.7-9.20147

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.5.7-9.20147" />

See Also