Originally Posted by Malsomnus
In my add-on, for example, I have a list of unit names ...
|
Using NPC names is a really bad way to do it, as they are not locale-independent, and require hardcoded translations for every language. Instead, you should use mobIDs, and check them against the unit's GUID. To find a mobID, look it up on Wowhead and copy the number out of the URL. For example, the mobID for
Horridon is 68476. And to get the mobID from a GUID inside your CLEU handler:
Code:
local mobID = tonumber(strsub(sourceGUID, 6, 10), 16)
If you're checking all CLEU "damage dealt" events, for example, you should also use a cache table to avoid repeatedly calling the same functions to get the same mobID from the same GUID:
Code:
-- outside CLEU handler:
local mobIDs = setmetatable({}, { __index = function(t, guid)
local mobID = tonumber(strsub(guid, 6, 10), 16)
t[guid] = mobID
return mobID
end })
-- inside CLEU handler:
local mobID = mobIDs[sourceGUID]
The first time you see a particular GUID, it will extract the mobID and add it to the cache; after that, it will return the same mobID via simple table lookup.