Implemented amb296 - Added HookEventEx() which does not generate a runtime error if the event does not exist and returns false instead.
Implemented
amb296 - Added HookEventEx() which does not generate a runtime error if the event does not exist and returns false instead.
1.1 --- a/core/smn_events.cpp Wed May 16 01:17:14 2007 +0000
1.2 +++ b/core/smn_events.cpp Wed May 16 04:09:31 2007 +0000
1.3 @@ -38,6 +38,26 @@
1.4 return 1;
1.5 }
1.6
1.7 +static cell_t sm_HookEventEx(IPluginContext *pContext, const cell_t *params)
1.8 +{
1.9 + char *name;
1.10 + IPluginFunction *pFunction;
1.11 +
1.12 + pContext->LocalToString(params[1], &name);
1.13 +
1.14 + if (!pFunction)
1.15 + {
1.16 + return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
1.17 + }
1.18 +
1.19 + if (g_EventManager.HookEvent(name, pFunction, static_cast<EventHookMode>(params[3])) == EventHookErr_InvalidEvent)
1.20 + {
1.21 + return 0;
1.22 + }
1.23 +
1.24 + return 1;
1.25 +}
1.26 +
1.27 static cell_t sm_UnhookEvent(IPluginContext *pContext, const cell_t *params)
1.28 {
1.29 char *name;
1.30 @@ -313,6 +333,7 @@
1.31 REGISTER_NATIVES(gameEventNatives)
1.32 {
1.33 {"HookEvent", sm_HookEvent},
1.34 + {"HookEventEx", sm_HookEventEx},
1.35 {"UnhookEvent", sm_UnhookEvent},
1.36 {"CreateEvent", sm_CreateEvent},
1.37 {"FireEvent", sm_FireEvent},
2.1 --- a/plugins/include/events.inc Wed May 16 01:17:14 2007 +0000
2.2 +++ b/plugins/include/events.inc Wed May 16 04:09:31 2007 +0000
2.3 @@ -67,6 +67,17 @@
2.4 native HookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
2.5
2.6 /**
2.7 + * Creates a hook for when a game event is fired.
2.8 + *
2.9 + * @param name Name of event.
2.10 + * @param callback An EventHook function pointer.
2.11 + * @param mode Optional EventHookMode determining the type of hook.
2.12 + * @return True if event exists and was hooked successfully, false otherwise.
2.13 + * @error Invalid callback function.
2.14 + */
2.15 +native bool:HookEventEx(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
2.16 +
2.17 +/**
2.18 * Removes a hook for when a game event is fired.
2.19 *
2.20 * @param name Name of event.