RedM Natives

CREATE_VEHICLE_SERVER_SETTER

Equivalent to CREATE_VEHICLE, but it uses 'server setter' logic (like the former CREATE_AUTOMOBILE) as a workaround for reliability concerns regarding entity creation RPC.

Hash0x6AE51D4B
Runtime nameCreateVehicleServerSetter
NamespaceCFX
SideServer
NameOfficial
Docs

Signature

Vehicle CREATE_VEHICLE_SERVER_SETTER(Hash modelHash, char* type, float x, float y, float z, float heading);

Parameters

NameTypeDescription
modelHashHash

The model of vehicle to spawn.

typechar*

The appropriate vehicle type for the model info. Can be one of automobile, bike, boat, heli, plane, submarine, trailer, and (potentially), train. This should be the same type as the type field in vehicles.meta.

xfloat

Spawn coordinate X component.

yfloat

Spawn coordinate Y component.

zfloat

Spawn coordinate Z component.

headingfloat

Heading to face towards, in degrees.

Returns Vehicle — A script handle for the vehicle, or 0 if the vehicle failed to be created.

Description

Cfx.re native reference

Equivalent to CREATE_VEHICLE, but it uses 'server setter' logic (like the former CREATE_AUTOMOBILE) as a workaround for reliability concerns regarding entity creation RPC.

Unlike CREATE_AUTOMOBILE, this supports other vehicle types as well.

Usage

Lua
local retval = CreateVehicleServerSetter(modelHash, type, x, y, z, heading)

-- always works, by hash
local retval = Citizen.InvokeNative(0x6ae51d4b, modelHash, type, x, y, z, heading, Citizen.ResultAsInteger())
JavaScript and C#
JavaScript
const retval = CreateVehicleServerSetter(modelHash, type, x, y, z, heading);

// by hash
const retval = Citizen.invokeNative('0x6ae51d4b', modelHash, type, x + 0.0000001, y + 0.0000001, z + 0.0000001, heading + 0.0000001, Citizen.returnResultAnyway(), Citizen.resultAsInteger());
C#
int retval = Function.Call<int>((Hash)0x6ae51d4b, modelHash, type, x, y, z, heading);
  • Hash parameters: the named function also accepts a string and hashes it for you; Citizen.InvokeNative needs the number — pass joaat("name") or a backtick literal like `name`.
  • Float parameters: Lua integers (10, or whole numbers decoded from NUI/JSON) are sent as ints and read as garbage. Write 10.0 or value + 0.0. The generated JS wrappers add 0.0000001 to non-zero floats for the same reason.

Examples

LUA · Cfx.re native reference
local heli = CreateVehicleServerSetter(`seasparrow`, 'heli', GetEntityCoords(GetPlayerPed(GetPlayers()[1])) + vector3(0, 0, 15), 0.0)
print(GetEntityCoords(heli)) -- should return correct coordinates

Sources

Cfx.re native reference

Something wrong or missing? Contribute a verified note — corrections ship through pull requests.