EntityCreated: Difference between revisions
m (double by mistake) |
mNo edit summary |
||
| 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. | ||
{{ | |||
{{ServersideJsEvent}} | |||
{{JSContainer| | {{JSContainer| | ||
{{Parameters}} | {{Parameters}} | ||
* '''entity''' - the entity that was created | * '''entity''': {{RageType|Entity}} - the [[:Category:Entity|entity]] that was created | ||
{{Example}} | {{Example}} | ||
| Line 14: | Line 16: | ||
</pre> | </pre> | ||
}} | }} | ||
{{ClientsideCsEvent}} | {{ClientsideCsEvent}} | ||
{{CSharpContainer| | {{CSharpContainer| | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="csharp"> | ||
public delegate void OnEntityCreatedDelegate(Entity entity); | public delegate void OnEntityCreatedDelegate(Entity entity); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 24: | Line 28: | ||
{{Example}} | {{Example}} | ||
The example below sends a message to client when an entity is created, 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=" | <syntaxhighlight lang="csharp"> | ||
Events.OnEntityCreated += OnEntityCreated; | Events.OnEntityCreated += OnEntityCreated; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="csharp"> | ||
public void OnEntityCreated(RAGE.Elements.Entity entity) | public void OnEntityCreated(RAGE.Elements.Entity entity) | ||
{ | { | ||
| Line 36: | Line 40: | ||
==See also== | ==See also== | ||
* [[entityDestroyed]] | |||
* [[entityModelChange]] | |||
[[Category:Entity API]] | [[Category:Entity API]] | ||
[[Category:Server-side Event]] | [[Category:Server-side Event]] | ||
Revision as of 14:24, 23 May 2019
This event is triggered when an Entity Is Created. From my testing, this event is only accessible on the serverside.
Server-Side Event
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);
Client-Side Event
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}");
}