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 ISource2ModEntities002 (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

CreateEntityByName

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

Creates entity by classname.

ParameterType
pszClassNameconst char*

AddEntityListener

virtual void AddEntityListener(IEntityListener* pListener) = 0;

Adds listener for entity spawn, creation, deletion and parent change.

Removed for you if the owning plugin unloads. The listener is an object inside that plugin's library and the engine holds it directly, so one left behind is a call into unmapped memory.
ParameterTypeDescription
pListenerIEntityListener*Listener object; the plugin whose class it is owns it

RemoveEntityListener

virtual void RemoveEntityListener(IEntityListener* pListener) = 0;

Removes listener for entity spawn, creation, deletion and parent change.

ParameterType
pListenerIEntityListener*

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

AddEntityIOListener

virtual void AddEntityIOListener(IEntityIOListener* pListener, const char* pchClassName, const char* pchOutputName, bool post = false) = 0;

Adds listener for entity outputs; the plugin whose class the listener is owns it.

Removed for you if the owning plugin unloads, for the same reason as AddEntityListener().
ParameterTypeDefault
pListenerIEntityIOListener*
pchClassNameconst char*
pchOutputNameconst char*
postboolfalse

RemoveEntityIOListener

virtual void RemoveEntityIOListener(IEntityIOListener* pListener, const char* pchClassName, const char* pchOutputName, bool post = false) = 0;

Removes entity output listener.

ParameterTypeDefault
pListenerIEntityIOListener*
pchClassNameconst char*
pchOutputNameconst char*
postboolfalse

Functions

UTIL_FindAllEntitiesByDesignerName

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

Every entity whose designer name matches, cast to T.

Walks the entity system's active list directly rather than going through the engine's finder, so it sees exactly the entities that are live right now and matches on m_designerName -- the name the map gave the entity, which is not always the classname the engine reports.

for (auto* pProp : UTIL_FindAllEntitiesByDesignerName<CDynamicProp>("prop_dynamic"))
    pProp->AcceptInput("Kill");
ParameterTypeDescription
pszDesignerNameconst char*Designer name to match, exactly.

Returns std::vector<T*> — Matches in list order; empty if the entity system is not up yet.

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)
REMOVE_ENTITY_LISTENER(l)g_pSource2ModEntities->RemoveEntityListener(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__)
ADD_ENTITY_IO_LISTENER(l, cls, out, ...)g_pSource2ModEntities->AddEntityIOListener(l, cls, out, ##__VA_ARGS__)
REMOVE_ENTITY_IO_LISTENER(l, cls, out, ...)g_pSource2ModEntities->RemoveEntityIOListener(l, cls, out, ##__VA_ARGS__)

On this page