MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / HookSingleEntityOutput

Function HookSingleEntityOutput

extensions/sdktools/outputnatives.cpp:47–109  ·  view source on GitHub ↗

HookSingleEntityOutput(int ent, const char[] output, EntityOutput function, bool once);

Source from the content-addressed store, hash-verified

45
46// HookSingleEntityOutput(int ent, const char[] output, EntityOutput function, bool once);
47cell_t HookSingleEntityOutput(IPluginContext *pContext, const cell_t *params)
48{
49 if (!g_OutputManager.IsEnabled())
50 {
51 return pContext->ThrowNativeError("Entity Outputs are disabled - See error logs for details");
52 }
53
54 CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[1]);
55 if (!pEntity)
56 {
57 return pContext->ThrowNativeError("Invalid Entity index %i (%i)", gamehelpers->ReferenceToIndex(params[1]), params[1]);
58 }
59
60 const char *classname = gamehelpers->GetEntityClassname(pEntity);
61
62 char *outputname;
63 pContext->LocalToString(params[2], &outputname);
64
65 OutputNameStruct *pOutputName = g_OutputManager.FindOutputPointer((const char *)classname, outputname, true);
66
67 //Check for an existing identical hook
68 SourceHook::List<omg_hooks *>::iterator _iter;
69
70 omg_hooks *hook;
71
72 IPluginFunction *pFunction;
73 pFunction = pContext->GetFunctionById(params[3]);
74
75 for (_iter=pOutputName->hooks.begin(); _iter!=pOutputName->hooks.end(); _iter++)
76 {
77 hook = (omg_hooks *)*_iter;
78 if (hook->pf == pFunction && hook->entity_ref == gamehelpers->EntityToReference(pEntity))
79 {
80 return 0;
81 }
82 }
83
84 hook = g_OutputManager.NewHook();
85
86 hook->entity_ref = gamehelpers->EntityToReference(pEntity);
87 hook->only_once= !!params[4];
88 hook->pf = pFunction;
89 hook->m_parent = pOutputName;
90 hook->in_use = false;
91 hook->delete_me = false;
92
93 pOutputName->hooks.push_back(hook);
94
95 g_OutputManager.OnHookAdded();
96
97 IPlugin *pPlugin = plsys->FindPluginByContext(pContext);
98 SourceHook::List<omg_hooks *> *pList = NULL;
99
100 if (!pPlugin->GetProperty("OutputHookList", (void **)&pList, false) || !pList)
101 {
102 pList = new SourceHook::List<omg_hooks *>;
103 pPlugin->SetProperty("OutputHookList", pList);
104 }

Callers

nothing calls this directly

Calls 14

ReferenceToEntityMethod · 0.80
ReferenceToIndexMethod · 0.80
GetEntityClassnameMethod · 0.80
FindOutputPointerMethod · 0.80
EntityToReferenceMethod · 0.80
NewHookMethod · 0.80
push_backMethod · 0.80
OnHookAddedMethod · 0.80
GetPropertyMethod · 0.80
SetPropertyMethod · 0.80
IsEnabledMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected