So, I got a bit bored during a work meeting and whipped this up. What does it do? Well, it replaces old RegisterXEvent functions with a new one that will pass an extra argument at the end of callbacks, which is a scope. This scope is unique to your entity, so you can store some information about that entity and it's related state without it leaking (aka, colliding) with other entities. This is not intended for use for storing global variables. Global variables are a code smell and you should avoid them if at all possible.
The usage is exactly the same as other RegisterXEvent functions, just add a 'scope' parameter on to the end of your event callbacks.
Scopes are deduced by looking at the "subject" of the event's GUID. This is important to note because there are a few quirks, listed below.
Be careful when loading this file, as it will replace the functionality of your other RegisterXEvent functions. They should perform the same, but it is another point of failure.
This is not tested using Eluna. I have only tested it using the Lua interpreter on my machine (Lua 5.2.3)
I will add the others if there is demand for it - it would be simple to add them all but certain events have some quirks. Generally speaking, if you look at the docs, the appropriately named variable is used as the subject. For example, if you look in the Creature event docs, the "creature" is used as the subject - this means that event 30 has the 5th argument used for the subject - not the second.
Paste tag isn't working for me, so here's the code: