HookSingleEntityOutput(int ent, const char[] output, EntityOutput function, bool once);
| 45 | |
| 46 | // HookSingleEntityOutput(int ent, const char[] output, EntityOutput function, bool once); |
| 47 | cell_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 | } |
nothing calls this directly
no test coverage detected