EntityCreated: Difference between revisions

From RAGE Multiplayer Wiki
(Created on Entity Created Event Documentation.)
 
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This event is triggered when an Entity Is Created. From my testing, this event is only accessible on the serverside.
This event is triggered when an Entity Is Created. From my testing, this event is only accessible on the serverside.


==Parameters==
{{ServersideCsJsEvent}}
* '''entity''' - the entity that was created


==Example==
{{JSContainer|
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
{{Parameters}}
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
* '''entity''': {{RageType|Entity}} - the [[:Category:Entity API|entity]] that was created
<syntaxhighlight lang="javascript">


{{Example}}
<pre>
function entityCreatedHandler(entity) {
function entityCreatedHandler(entity) {
   console.log(`An Entity with the ID of ${entity.id} was created at ${entity.position}`);
   console.log(`An Entity with the ID of ${entity.id} was created at ${entity.position}`);
Line 14: Line 14:


mp.events.add("entityCreated", entityCreatedHandler);
mp.events.add("entityCreated", entityCreatedHandler);
</pre>
}}
{{CSharpContainer|
{{Parameters}}
* '''entity''': {{RageType|Entity}} - the [[:Category:Entity API|entity]] that was created
{{Example}}
The example below logs in server console when an entity is created, showing the entity model, position and remoteId.
<syntaxhighlight lang="csharp">
[ServerEvent(Event.EntityCreated)]
public void OnEntityCreated(GTANetworkAPI.Entity entity)
{
    NAPI.Util.ConsoleOutput($"{entity.Model} created at {entity.Position} with serverside id:{entity.Id}");
}
</syntaxhighlight>
}}
{{ClientsideCsEvent}}
{{CSharpContainer|
<syntaxhighlight lang="csharp">
public delegate void OnEntityCreatedDelegate(Entity entity);
</syntaxhighlight>
{{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.
<syntaxhighlight lang="csharp">
Events.OnEntityCreated += OnEntityCreated;
</syntaxhighlight>
<syntaxhighlight lang="csharp">
public void OnEntityCreated(RAGE.Elements.Entity entity)
{
  RAGE.Chat.Output($"{entity.Model} created at {entity.Position} with serverside id:{entity.RemoteId}");
}
</syntaxhighlight>
</syntaxhighlight>
</div>
}}


==See also==
==See also==
{{Player_events}}
* [[entityDeleted]]
* [[entityDestroyed]]
* [[entityModelChange]]
 
[[Category:Entity API]]
[[Category:Server-side Event]]

Latest revision as of 17:15, 8 September 2024

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: 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);



C# Syntax

Parameters

  • entity: Entity - the entity that was created

Example

The example below logs in server console when an entity is created, showing the entity model, position and remoteId.

[ServerEvent(Event.EntityCreated)]
public void OnEntityCreated(GTANetworkAPI.Entity entity)
{
    NAPI.Util.ConsoleOutput($"{entity.Model} created at {entity.Position} with serverside id:{entity.Id}");
}



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