CreateObject

From GT-MP
Jump to: navigation, search
CreateObject
Shared Function
Utilities-terminal.png Server-Side System-users.png Client-Side
Csharp.png C# Javascript.png JavaScript

Creates an object. External websites that displays objects with pictures and their model integer can be found below.

Dialog-warning.png

Note: If shared API was used when creating, then the created entities are not deleted on ResourceStop


Syntax

In C#
Server-Side Function

Icon-info.png
This method is asynchronous. There is no guarantee the entity will be known to the client when working with it after creation (e.g. setting properties). Use waitForSynchronization() to make sure it's known.

waitForSynchronization() does not guarantee that the entity is streamed in on the client, it just means that the entity is known (and can be updated serverside). If you need to work with it on clientside you will need to check if the entity is streamed in (e.g. by hooking to the onEntityStreamIn event). Entities that are not streamed in can not be accessed using the clientside API. (Version 0.1.7)

This function has 4 overloads. (Overload 3 and 4 will be available with version 0.1.7)

API.createObject(int model, Vector3 pos, Vector3 rot, int dimension = 0);
API.createObject(int model, Vector3 pos, Quaternion rot, int dimension = 0);
API.createObject(uint model, Vector3 pos, Vector3 rot, int dimension = 0);
API.createObject(uint model, Vector3 pos, Quaternion rot, int dimension = 0);

Required Arguments

  • model: parameter input should be in int or uint type.
  • pos: parameter input should be in Vector3 type.
  • rot: parameter input should be in Vector3 or Quaternion type.

Optional Arguments

  • dimension: parameter input should be in int type, Default value: 0

In Javascript
Client-Side Function

This function has 2 overloads. (Overload 2 will be available with version 0.1.7)

API.createObject(int model, Vector3 pos, Vector3 rotation);
API.createObject(uint model, Vector3 pos, Vector3 rotation);

Required Arguments

  • model: parameter input should be in int or uint type.
  • pos: parameter input should be in Vector3 type.
  • rotation: parameter input should be in Vector3 type.

NOTE: This function returns data in NetHandle type, you can delete created objects using deleteEntity.

Usage examples

  • example 1
API.createObject(model, oPos, oRot); //Spawned object is visible in all Dimensions
API.createObject(model, oPos, oRot, 10); //Spawned object is visible only in Dimension 10
  • example 2
NetHandle object1 = API.createObject(model, oPos, oRot); //Spawned object is visible in all Dimensions
NetHandle object2 = API.createObject(model, oPos, oRot, 10); //Spawned object is visible only in Dimension 10
  • example 3
var myObject= API.createObject(model, pos, rot);
  • example 4 (for objects with an uint-model)
var myObject= API.createObject(unchecked((int)model), pos, rot);