ISource2ModEntities

Interface for entity lookup and Source2 Entity I/O system.

Provides:

  • Entity searching (classname, name, picker)
  • Entity creation
  • Input triggering
  • Output listening
Entity I/O is the system used by maps to connect entities together.

Interface for interacting with entities and Entity I/O system.

Interface id ISource2ModEntities004 (SOURCE2MOD_ENTITIES_INTERFACE) · Global g_pSource2ModEntities · Header source2mod/ISource2ModEntities.h

Methods

GetGameRules

virtual CCSGameRules* GetGameRules() = 0;

The active CCSGameRules, or null before the entity exists.

Source2Mod captures this from cs_gamerules as the entity is created, so it is live for the whole map and a plugin does not have to scan for the proxy itself.

FindPickerEntity

virtual CBaseEntity* FindPickerEntity(CBasePlayerController* pPlayer, CCSGameRules* pGameRules = nullptr) = 0;

Finds entity under player's crosshair.

ParameterTypeDefault
pPlayerCBasePlayerController*
pGameRulesCCSGameRules*nullptr

FindEntityByClassname

virtual CBaseEntity* FindEntityByClassname(CEntityInstance* pStart, const char* name) = 0;

Finds entity by classname.

ParameterType
pStartCEntityInstance*
nameconst char*

FindEntityByName

virtual CBaseEntity* FindEntityByName(CEntityInstance* pStartEntity, const char* szName, CEntityInstance* pSearchingEntity = nullptr, CEntityInstance* pActivator = nullptr, CEntityInstance* pCaller = nullptr, IEntityFindFilter* pFilter = nullptr) = 0;

Finds entity by name.

ParameterTypeDefault
pStartEntityCEntityInstance*
szNameconst char*
pSearchingEntityCEntityInstance*nullptr
pActivatorCEntityInstance*nullptr
pCallerCEntityInstance*nullptr
pFilterIEntityFindFilter*nullptr

FindAllEntitiesByDesignerName

virtual std::vector<CBaseEntity*> FindAllEntitiesByDesignerName(const char* pszDesignerName) = 0;

Every entity with this designer name ("prop_dynamic", "cs_player_controller"), in entity-list order; empty when the entity system is not up. UTIL_FindAllEntitiesByDesignerName<T> is the typed form.

ParameterType
pszDesignerNameconst char*

CreateEntityByName

virtual CBaseEntity* CreateEntityByName(const char* pszClassName) = 0;

Creates entity by classname.

ParameterType
pszClassNameconst char*

AcceptInput

virtual void AcceptInput(CEntityInstance* pTarget, const char* pszInput, CEntityInstance* pActivator, CEntityInstance* pCaller, const char* pszValue = "") = 0;

Sends input to entity.

Equivalent to Source engine AcceptInput()
ParameterTypeDefault
pTargetCEntityInstance*
pszInputconst char*
pActivatorCEntityInstance*
pCallerCEntityInstance*
pszValueconst char*""

AddEntityIOEvent

virtual void AddEntityIOEvent(CEntityInstance* pTarget, const char* pszInput, CEntityInstance* pActivator = nullptr, CEntityInstance* pCaller = nullptr, const char* pszValue = "", float flDelay = 0.0f) = 0;

Queues an entity I/O event.

ParameterTypeDefault
pTargetCEntityInstance*
pszInputconst char*
pActivatorCEntityInstance*nullptr
pCallerCEntityInstance*nullptr
pszValueconst char*""
flDelayfloat0.0f

AddEntityListener

virtual void AddEntityListener(IEntityListener* pListener, const char* pszDesignerName = nullptr, CEntityInstance* pEntity = nullptr) = 0;

Entity events: the IEntityListener's OnEntityCreated (keyvalues not applied, not spawned yet), OnEntitySpawned, OnEntityDeleted (the last call for it), OnEntityParentChanged. Override what you need.

The same listener may be added again with other filters; it is then called once per matching registration. Remove drops them all.
ParameterTypeDefaultDescription
pListenerIEntityListener*The plugin whose class it is owns it; dropped for you when that plugin unloads.
pszDesignerNameconst char*nullptrOnly entities of this designer name ("player", "smokegrenade_projectile"); nullptr for every one.
pEntityCEntityInstance*nullptrOnly this one entity; nullptr for every one. Gone with the entity, after its OnEntityDeleted.

RemoveEntityListener

virtual void RemoveEntityListener(IEntityListener* pListener) = 0;

Drops every registration of the listener.

ParameterType
pListenerIEntityListener*

AddEntityOutputListener

virtual void AddEntityOutputListener(IEntityOutputListener* pListener, const char* pszDesignerName = nullptr, const char* pszOutput = nullptr, CEntityInstance* pEntity = nullptr) = 0;

Entity outputs: IEntityOutputListener::OnEntityOutput, pre and post.

The same listener may be added again with other filters. Remove drops them all.
ParameterTypeDefaultDescription
pListenerIEntityOutputListener*The plugin whose class it is owns it; dropped for you when that plugin unloads.
pszDesignerNameconst char*nullptrOnly outputs of entities of this designer name (the caller's); nullptr for every one.
pszOutputconst char*nullptrOnly this output ("OnTrigger", "OnStartTouch"); nullptr for every one.
pEntityCEntityInstance*nullptrOnly outputs of this one entity; nullptr for every one. Gone with the entity.

RemoveEntityOutputListener

virtual void RemoveEntityOutputListener(IEntityOutputListener* pListener) = 0;

Drops every registration of the listener.

ParameterType
pListenerIEntityOutputListener*

IEntityOutputListener

Entity outputs firing (CEntityIOOutput::FireOutputInternal), for ISource2ModEntities::AddEntityOutputListener. Called pre (post = false), before the output's targets get it, and post, after; pre may answer Action::Supersede and the output does not fire. Override and Ignore both let it fire. The strongest answer of all listeners wins.

OnEntityOutput

virtual Action OnEntityOutput(CEntityInstance* pCaller, const char* pszOutput, CEntityInstance* pActivator, float flDelay, bool post) = 0;
ParameterType
pCallerCEntityInstance*
pszOutputconst char*
pActivatorCEntityInstance*
flDelayfloat
postbool

Functions

UTIL_FindAllEntitiesByDesignerName

template <typename T = CBaseEntity> inline std::vector<T*> UTIL_FindAllEntitiesByDesignerName(const char* pszDesignerName);
ParameterType
pszDesignerNameconst char*

Macros

MacroExpands to
GET_GAME_RULES()g_pSource2ModEntities->GetGameRules()
FIND_PICKER_ENTITY(player, ...)g_pSource2ModEntities->FindPickerEntity(player, ##__VA_ARGS__)
FIND_ENTITY_BY_CLASSNAME(start, name)g_pSource2ModEntities->FindEntityByClassname(start, name)
FIND_ENTITY_BY_NAME(start, name, ...)g_pSource2ModEntities->FindEntityByName(start, name, ##__VA_ARGS__)
CREATE_ENTITY(classname)g_pSource2ModEntities->CreateEntityByName(classname)
ADD_ENTITY_LISTENER(l, ...)g_pSource2ModEntities->AddEntityListener(l, ##__VA_ARGS__)
REMOVE_ENTITY_LISTENER(l)g_pSource2ModEntities->RemoveEntityListener(l)
ADD_ENTITY_OUTPUT_LISTENER(l, ...)g_pSource2ModEntities->AddEntityOutputListener(l, ##__VA_ARGS__)
REMOVE_ENTITY_OUTPUT_LISTENER(l)g_pSource2ModEntities->RemoveEntityOutputListener(l)
ACCEPT_INPUT(target, input, ...)g_pSource2ModEntities->AcceptInput(target, input, ##__VA_ARGS__)
ADD_ENTITY_IO_EVENT(target, input, ...)g_pSource2ModEntities->AddEntityIOEvent(target, input, ##__VA_ARGS__)

On this page