EntityCreated: Difference between revisions
(Add server side C# example) |
|||
| Line 56: | Line 56: | ||
==See also== | ==See also== | ||
* [[entityDeleted]] | |||
* [[entityDestroyed]] | * [[entityDestroyed]] | ||
* [[entityModelChange]] | * [[entityModelChange]] | ||
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
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# 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}");
}