ESE_Entities Class - NarcoMarshDev/Enforce-Script-Extensions GitHub Wiki

Category: Static
Path: scripts/Game/ESE_Entities.c

ESE static methods for handling entities. Versions of these may appear on a modded IEntity class in the future, if this happens it will be mentioned here and be made obvious on the home page.

Overview

The methods in this class primarily handle the following aspects of working with entities:

  • Spawning and deleting entities
  • Manipulating entities
  • Entity physics and collision
  • Materials and models

Methods

Name⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ Return⠀⠀⠀⠀⠀ Description
SpawnPrefab (vector transform[4], ResourceName resName) IEntity Spawns .et entity prefab at given transform, and returns reference to created entity.
SpawnPrefabOnPlayer (int playerId, ResourceName resName) IEntity Same as SpawnPrefab() but will spawn entity directly on the player referenced by the playerId.
DeleteEntity (IEntity ent) void EDeletes given entity server side, replicating to all connected clients.
DeleteEntityByRplId (RplId id) void Same as DeleteEntity() but finds entity based on RplId instead of using a direct reference.
DisableCollisions (IEntity ent) void Disables collisions of entity by destroying it's Physics if it has one, otherwise does nothing.
EnableCollisions (IEntity ent, int layerMask = 0xffffffff) void Adds collision to entity if it doesn't have any by creating new CollisionObject using given bit mask, leave layerMask as default for general use.
SnapToGround (out vector mat[4], IEntity ent, int maxHeight, bool noUnderwater=false) void (out) Snaps transform down to the ground, this is similar to SCR_TerrainHelper.SnapToTerrain() but will snap to any object underneath the transform not just the terrain itself. maxHeight is the max distance it will look down for to find a collision and will do nothing if none is found. BE AWARE due to using a raycast for this, higher values of maxHeight will affect performance. Make sure to pass a reference to the entity being moved so it can be excluded from the raycast collision check.
SnapAndOrientToGround (out vector mat[4], IEntity ent, int maxHeight, bool noUnderwater) void (out) Same as SnapToGround() but also orients the output transform to the normal of the raycast collision.
GetMaterial (IEntity ent, out string mats[], out int numMats) void (out) Outputs string of all materials used on the given entities VObject and the number of them.
SetMaterial (IEntity ent, ResourceName mat, bool recursive=true) void Sets all materials of given entity's VObject to the material loaded from mat. With recursive=true all child entities have their material updated as well.
RestoreMaterial (IEntity ent, bool recursive) void Restores given entity's VObject to it's default material by finding the original materials from it's model reference. recursive=true restores materials of all child entities too. This can break sometimes with inherited entities however, check the known issues.
IsEntityOnScreen (IEntity ent) bool Checks if given entity is visible on screen on local machine, returns true if so and false if not or no valid world position for the entity is found. WIP AND CURRENTLY DISABLED BY DEFAULT