ISource2ModEntities
Interface for entity lookup and Source2 Entity I/O system.
Provides:
- Entity searching (classname, name, picker)
- Entity creation
- Input triggering
- Output listening
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.
| Parameter | Type | Default |
|---|---|---|
pPlayer | CBasePlayerController* | |
pGameRules | CCSGameRules* | nullptr |
FindEntityByClassname
virtual CBaseEntity* FindEntityByClassname(CEntityInstance* pStart, const char* name) = 0;Finds entity by classname.
| Parameter | Type |
|---|---|
pStart | CEntityInstance* |
name | const 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.
| Parameter | Type | Default |
|---|---|---|
pStartEntity | CEntityInstance* | |
szName | const char* | |
pSearchingEntity | CEntityInstance* | nullptr |
pActivator | CEntityInstance* | nullptr |
pCaller | CEntityInstance* | nullptr |
pFilter | IEntityFindFilter* | nullptr |
CreateEntityByName
virtual CBaseEntity* CreateEntityByName(const char* pszClassName) = 0;Creates entity by classname.
| Parameter | Type |
|---|---|
pszClassName | const char* |
AddEntityListener
virtual void AddEntityListener(IEntityListener* pListener) = 0;Adds listener for entity spawn, creation, deletion and parent change.
| Parameter | Type | Description |
|---|---|---|
pListener | IEntityListener* | 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.
| Parameter | Type |
|---|---|
pListener | IEntityListener* |
AcceptInput
virtual void AcceptInput(CEntityInstance* pTarget, const char* pszInput, CEntityInstance* pActivator, CEntityInstance* pCaller, const char* pszValue = "") = 0;Sends input to entity.
| Parameter | Type | Default |
|---|---|---|
pTarget | CEntityInstance* | |
pszInput | const char* | |
pActivator | CEntityInstance* | |
pCaller | CEntityInstance* | |
pszValue | const 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.
| Parameter | Type | Default |
|---|---|---|
pTarget | CEntityInstance* | |
pszInput | const char* | |
pActivator | CEntityInstance* | nullptr |
pCaller | CEntityInstance* | nullptr |
pszValue | const char* | "" |
flDelay | float | 0.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.
| Parameter | Type | Default |
|---|---|---|
pListener | IEntityIOListener* | |
pchClassName | const char* | |
pchOutputName | const char* | |
post | bool | false |
RemoveEntityIOListener
virtual void RemoveEntityIOListener(IEntityIOListener* pListener, const char* pchClassName, const char* pchOutputName, bool post = false) = 0;Removes entity output listener.
| Parameter | Type | Default |
|---|---|---|
pListener | IEntityIOListener* | |
pchClassName | const char* | |
pchOutputName | const char* | |
post | bool | false |
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");| Parameter | Type | Description |
|---|---|---|
pszDesignerName | const char* | Designer name to match, exactly. |
Returns std::vector<T*> — Matches in list order; empty if the entity system is not up yet.
Macros
| Macro | Expands 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__) |