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.
Signature
Vehicle CREATE_VEHICLE_SERVER_SETTER(Hash modelHash, char* type, float x, float y, float z, float heading);Parameters
| Name | Type | Description |
|---|---|---|
modelHash | Hash | The model of vehicle to spawn. |
type | char* | The appropriate vehicle type for the model info. Can be one of |
x | float | Spawn coordinate X component. |
y | float | Spawn coordinate Y component. |
z | float | Spawn coordinate Z component. |
heading | float | Heading to face towards, in degrees. |
Returns Vehicle — A script handle for the vehicle, or 0 if the vehicle failed to be created.
Description
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
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#
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());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.InvokeNativeneeds the number — passjoaat("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. Write10.0orvalue + 0.0. The generated JS wrappers add0.0000001to non-zero floats for the same reason.
Examples
local heli = CreateVehicleServerSetter(`seasparrow`, 'heli', GetEntityCoords(GetPlayerPed(GetPlayers()[1])) + vector3(0, 0, 15), 0.0)
print(GetEntityCoords(heli)) -- should return correct coordinatesSources
Something wrong or missing? Contribute a verified note — corrections ship through pull requests.