- Documentation
- Shared functions
- engineRequestModel
Function
engineRequestModel
Creates a new model under a new number, shared by every player (also those who join later). An object ("object"/"timed-object", parent 1337 by default) gets a number from the 18631-19999 pool and is a copy of the parent; engineReplaceModel and engineReplaceCOL give it a look and a collision. A vehicle ("vehicle", parent 400), a ped ("ped", parent 7) and a tuning part ("upgrade", parent 1000-1193) get a number 20000-29999 and behave like the parent (seats, sound, handling, tuning), while engineReplaceModel in a client script gives the look. The third argument is a specific number or a name: the same name always gives the same number (stored in the server's model-ids.json), so cars and objects from a database are still that model after a restart, and a named model stays when the resource stops. On the client, the name of a server model returns its shared number. A model requested on the client before the game has loaded its models gets its number at once and is created once loading finishes.
Syntax
Server
int engineRequestModel(string elementType [, int parentID, int|string wantedIDOrName])Client
int engineRequestModel(string elementType [, int parentID, string name])Arguments
elementTypestring"object","timed-object","vehicle","ped"or"upgrade".parentIDint, optional- Parent model.
wantedIDOrNameint|string, optional- A model number or name (only a name on the client).
Returns
The new model number or false.
Example
A new car based on the Elegy, with a look from a file.
local id = engineRequestModel("vehicle", 562, "elegy_drift")
local car = createVehicle(id, 2495, -1670, 13.3)
local id = engineGetModelIDFromName("elegy_drift")
local mesh = engineLoadMesh("modele/elegy_drift.dff")
if id and mesh then engineReplaceModel(mesh, id) end
Notes
Shared models. New models are shared by every player and have stable numbers by name. They also work for vehicles, peds and tuning parts.
See also
engineReplaceModelReplaces the look of a model number: with an engine asset (engineLoadAsset) or a model from a file (engineLoadMesh). Objects, vehicles and peds (skins 0-312; a file model without a skeleton is static) with that number show the new model. An object without its own collision gets one from the.dffor from the model triangles;engineReplaceCOLgives a custom collision. It works for this player, so call it in a client script. Replacing a newengineRequestModelmodel that the game has not created yet (the player is just joining, a resource restart) waits for it; a model number that does not exist givesfalse.engineFreeModelFrees a model fromengineRequestModel. On the server the model is shared: objects, cars and peds using it get the parent model; on the client it frees the local model. A named model keeps its number inmodel-ids.jsonunlessforgetName=true.engineGetModelIDFromNameReturns a model number by name. On the server it finds new named models (engineRequestModel) and vehicles; on the client also game models by name.createVehicleCreates a vehicle in the world: model, position, rotation and number plate text.