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
+21
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},