Event number of module events - how do I know what number?


I would like to use GetUserDefinedEventNumber for the OnActivateItem event in the module properties events instead of editing the OnActivateItem itself.

However, how would I know what event number is the OnActivateItem event? (or any other event for that matter)


The X2_ITEM_EVENT_* constants as well as the corresponding function GetUserDefinedItemEventNumber() are in “x2_inc_switches”. If you include that library, you will have access to them.

Read this, it’ll help. :slight_smile:


Great! thanks a bunch :slight_smile:


So for OnUserDefined for module events, I have this script


Forget about what XPCookies does. It works if I put it on the OnActivateItem event handle, but it doesn’t work for OnUserDefined. And I do have #include "x2_inc_switches"

I’m thinking to just use the OnActivateItem even handle directly, unless you can see what’s the issue.


X2_ITEM_EVENT_ACTIVATE is an integer constant. It only ever has one value, which cannot be altered ingame. Giving it a glance in the toolset, it looks like that value is set to be zero, so a check for whether X2_ITEM_EVENT_ACTIVATE is equal to literally anything other than zero is always going to be FALSE, and this particular condition will never be fulfilled.

What you want to do is to check whether the value that the function GetUserDefinedItemEventNumber() returns is equal to X2_ITEM_EVENT_ACTIVATE, e.g.:

    if (GetUserDefinedItemEventNumber() == X2_ITEM_EVENT_ACTIVATE)