CreateVehicle

From GTA Network Wiki
Jump to: navigation, search

CreateVehicle
Server-Side Function

utilities-terminal.png Server-Side csharp.png C#

Creates a vehicle. There are four different ways to spawn a vehicle.

Syntax

Vehicle NAPI.Vehicle.CreateVehicle(uint/int/VehicleHash model, Vector3 pos, float rot, int color1, int color2 [, string numberPlate = "", byte alpha = 255, bool locked = false, bool engine = true, uint dimension = NAPI.GlobalDimension ])
Vehicle NAPI.Vehicle.CreateVehicle(int/VehicleHash model, Vector3 pos, Vector3 rot, int color1, int color2 [, string numberPlate = "", byte alpha = 255, bool locked = false, bool engine = true, uint dimension = NAPI.GlobalDimension ])
Vehicle NAPI.Vehicle.CreateVehicle(VehicleHash model, Vector3 pos, float rot, Color color1, Color color2 [, string numberPlate = "", byte alpha = 255, bool locked = false, bool engine = true, uint dimension = NAPI.GlobalDimension ])


Required Arguments:

  • model: parameter input should be in VehicleHash, uint or int type.
  • pos: parameter input should be in Vector3 type. This will decide where the vehicle spawns.
  • rot: parameter input should be in float or Vector3 type. This decides the vehicle's angle upon spawning.
  • color1: parameter input should be in Color or int type.
  • color2: parameter input should be in Color or int type.


Optional Arguments:

  • numberPlate: parameter input should in string type.'
  • alpha: parameter input should be in byte type.
  • locked: parameter input should be in bool type.'
  • engine: parameter input should be in bool type.
  • dimension: parameter input should be in uint type.


NOTE: This function returns data in Vehicle type.

IMPORTANT: Try to not using overload method with rotation given as Vector3. Linux C# plugin gives AccessViolationException (and Aborted with force process kill) when this method is used.


icon-info.png

Vehicle position can be changed without recreating the vehicle again with SetEntityPosition

Usage examples

  • Example 1
NAPI.Vehicle.CreateVehicle(VehicleHash.Adder, new Vector3(2f, 3f, 4f), 0f, 0, 0); //Spawned vehicle is visible in all Dimensions
  • Example 2
Vehicle myVeh1 = NAPI.Vehicle.CreateVehicle(VehicleHash.Adder, new Vector3(0, 0, 0), 100f, 0, 0, dimension: 5); //Spawned vehicle is visible only in Dimension 5
Vehicle myVeh2 = NAPI.Vehicle.CreateVehicle(VehicleHash.Adder, new Vector3(0, 5, 1), 2f, new Color(0, 255, 100), new Color(0)); //Spawned vehicle is visible in all Dimensions

Changelog

Version Description
1.0 Release.

References