Implemented amb296 - Added HookEventEx() which does not generate a runtime error if the event does not exist and returns false instead.

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40807
This commit is contained in:
Scott Ehlert 2007-05-16 04:09:31 +00:00
parent 1a77530c93
commit 4ed2d6e515
2 changed files with 32 additions and 0 deletions

View File

@ -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<EventHookMode>(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},

View File

@ -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.
*