diff --git a/core/smn_events.cpp b/core/smn_events.cpp index 679c4efe..2948dda6 100644 --- a/core/smn_events.cpp +++ b/core/smn_events.cpp @@ -38,6 +38,26 @@ static cell_t sm_HookEvent(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t sm_HookEventEx(IPluginContext *pContext, const cell_t *params) +{ + char *name; + IPluginFunction *pFunction; + + pContext->LocalToString(params[1], &name); + + if (!pFunction) + { + return pContext->ThrowNativeError("Invalid function id (%X)", params[2]); + } + + if (g_EventManager.HookEvent(name, pFunction, static_cast(params[3])) == EventHookErr_InvalidEvent) + { + return 0; + } + + return 1; +} + static cell_t sm_UnhookEvent(IPluginContext *pContext, const cell_t *params) { char *name; @@ -313,6 +333,7 @@ static cell_t sm_SetEventString(IPluginContext *pContext, const cell_t *params) REGISTER_NATIVES(gameEventNatives) { {"HookEvent", sm_HookEvent}, + {"HookEventEx", sm_HookEventEx}, {"UnhookEvent", sm_UnhookEvent}, {"CreateEvent", sm_CreateEvent}, {"FireEvent", sm_FireEvent}, diff --git a/plugins/include/events.inc b/plugins/include/events.inc index d1fd81d9..ede8c3e4 100644 --- a/plugins/include/events.inc +++ b/plugins/include/events.inc @@ -66,6 +66,17 @@ funcenum EventHook */ native HookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post); +/** + * Creates a hook for when a game event is fired. + * + * @param name Name of event. + * @param callback An EventHook function pointer. + * @param mode Optional EventHookMode determining the type of hook. + * @return True if event exists and was hooked successfully, false otherwise. + * @error Invalid callback function. + */ +native bool:HookEventEx(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post); + /** * Removes a hook for when a game event is fired. *