EntityCreated: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
Line 23: Line 23:


{{Example}}
{{Example}}
The example below sends a message to client when an entity comes within stream range, showing the entity model, position and remoteId.
The example below sends a message to client when an entity is created, showing the entity model, position and remoteId.
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Events.OnEntityCreated += OnEntityCreated;
Events.OnEntityCreated += OnEntityCreated;

Revision as of 14:32, 29 November 2018

This event is triggered when an Entity Is Created. From my testing, this event is only accessible on the serverside.

Server-Side
Event

 C#  JavaScript



JavaScript Syntax

Parameters

  • entity - the entity that was created

Example

function entityCreatedHandler(entity) {
  console.log(`An Entity with the ID of ${entity.id} was created at ${entity.position}`);
}

mp.events.add("entityCreated", entityCreatedHandler);


Client-Side
Event

 C#



C# Syntax

public delegate void OnEntityCreatedDelegate(Entity entity);

Parameters

  • entity - the streamed in entity, expects RAGE.Elements.Entity

Example

The example below sends a message to client when an entity is created, showing the entity model, position and remoteId.

Events.OnEntityCreated += OnEntityCreated;
public void OnEntityCreated(RAGE.Elements.Entity entity)
{
   RAGE.Chat.Output($"{entity.Model} created at {entity.Position} with serverside id:{entity.RemoteId}");
}


See also

Checkpoint

Colshape

Entity

Player

Streaming

Vehicle

Waypoint