# CFX::CREATE_VEHICLE_SERVER_SETTER

- **Hash:** `0x6AE51D4B`
- **Namespace:** CFX
- **Runtime name (Lua/JS):** `CreateVehicleServerSetter`
- **Side:** server (Cfx runtime native)
- **Name status:** official
- **Documentation:** described with examples
- **URL:** https://natives.borderlinerp.com/natives/CFX/CREATE_VEHICLE_SERVER_SETTER

## Signature

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

## Parameters

- `modelHash` (`Hash`) — The model of vehicle to spawn.
- `type` (`char*`) — 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`.
- `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

*Source: 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

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

-- always available, by hash
local retval = Citizen.InvokeNative(0x6ae51d4b, modelHash, type, x, y, z, heading, Citizen.ResultAsInteger())
```

### JavaScript

```js
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#

```csharp
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

*Source: Cfx.re native reference*

```lua
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.*
