Difference between revisions of "Entity Basics"

From Sven Co-op
Jump to navigation Jump to search
(Created page with "Entities are objects in the game that are effectively small programs which serve a specific function or represent an actual thing: players, NPCs, platforms, triggers, etc. CB...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Entities are objects in the game that are effectively small programs which serve a specific function or represent an actual thing: players, NPCs, platforms, triggers, etc.
+
 
 +
== What are entities? ==
 +
Entities are objects in the game that are effectively small programs which serve a specific function or represent an actual thing: players, NPCs, platforms, triggers, markers, etc.
  
 
CBaseEntity is the type used to represent entities themselves. All entities derive from CBaseEntity, so you can do most things with this interface. It has a rather large amount of methods and variables, so be sure to check out the documentation for it.
 
CBaseEntity is the type used to represent entities themselves. All entities derive from CBaseEntity, so you can do most things with this interface. It has a rather large amount of methods and variables, so be sure to check out the documentation for it.
Line 33: Line 35:
 
* CBaseDoor
 
* CBaseDoor
  
Note: Entity handles are not reference counted, which means that unlike most objects in AngelScript, they will not exist as long as you still have a handle to it. This also means that a handle can point to an entity that no longer exists. For this reason you should avoid using entity handles for storage and use [[EHandle]] instead. The game will scan for entity handles declared as global variables, and will prevent compilation from succeeding if it detects any of them.
+
'''Note''': Entity handles are not reference counted, which means that unlike most objects in AngelScript, they will not exist as long as you still have a handle to it. This also means that a handle can point to an entity that no longer exists. For this reason you should avoid using entity handles for storage and use [[EHandle]] instead.
 +
 
 +
The game will scan for entity handles declared as global variables, and will prevent compilation from succeeding if it detects any of them. Entity handles as member variables are just as dangerous, even if the compiler does not catch these. Arrays of entity handles are also not caught by the compiler but are still subject to the same risks. Passing entity handles through scheduled functions/methods is equally dangerous and should be avoided.
 +
In all these scenarios you must use EHandle.
 +
 
 +
== Entity Variables ==
 +
All entities have a entvars_t instance
 +
<nowiki>entvars_t@ pev</nowiki>
 +
which contains many important variables. It used by the engine to access variables in entities that should be networked, and/or used for rendering and physics. Everything from the entity's origin and angles, to the bounds, movement type and solidity, to render mode and render amount can be found here.
 +
The entvars_t instance can be obtained via:
 +
<nowiki>pEntity.pev;</nowiki>
 +
where pEntity is a valid CBaseEntity@ instance.
 +
 
 +
The list of variables is too large to show again here, so you should consult the documentation for this type for more information.
 +
 
 +
[[Category:Scripting]]

Latest revision as of 03:46, 15 February 2025

1 What are entities?

Entities are objects in the game that are effectively small programs which serve a specific function or represent an actual thing: players, NPCs, platforms, triggers, markers, etc.

CBaseEntity is the type used to represent entities themselves. All entities derive from CBaseEntity, so you can do most things with this interface. It has a rather large amount of methods and variables, so be sure to check out the documentation for it.

There are several subclasses that extend functionality for different types of entities:

CBaseToggle provides support for toggled behaviour, found in doors, buttons, trains, and platforms. CBaseAnimating provides support for entities using studio models. CBaseMonster provides the basis for all monsters and the player. This includes navigation, scheduling of tasks like movement, combat, and more. There are many more classes available in the API, so be sure to check them out of as well. Here's a list of all entities in the API:

  • CBaseEntity
  • CBaseDelay
  • CBaseAnimating
  • CBaseToggle
  • CBasePlayerItem
  • CBasePlayerWeapon
  • CBasePlayerAmmo
  • CItemInventory
  • CItem
  • CGrenade
  • CBaseMonster
  • CCineMonster
  • CBasePlayer
  • CSprite
  • CTalkMonster
  • CPathTrack
  • CBeam
  • CLaser
  • CBaseTank
  • CPathCondition
  • CBaseButton
  • CBaseDoor

Note: Entity handles are not reference counted, which means that unlike most objects in AngelScript, they will not exist as long as you still have a handle to it. This also means that a handle can point to an entity that no longer exists. For this reason you should avoid using entity handles for storage and use EHandle instead.

The game will scan for entity handles declared as global variables, and will prevent compilation from succeeding if it detects any of them. Entity handles as member variables are just as dangerous, even if the compiler does not catch these. Arrays of entity handles are also not caught by the compiler but are still subject to the same risks. Passing entity handles through scheduled functions/methods is equally dangerous and should be avoided. In all these scenarios you must use EHandle.

2 Entity Variables

All entities have a entvars_t instance

entvars_t@ pev

which contains many important variables. It used by the engine to access variables in entities that should be networked, and/or used for rendering and physics. Everything from the entity's origin and angles, to the bounds, movement type and solidity, to render mode and render amount can be found here. The entvars_t instance can be obtained via:

pEntity.pev;

where pEntity is a valid CBaseEntity@ instance.

The list of variables is too large to show again here, so you should consult the documentation for this type for more information.