View Single Post
07-22-13, 02:49 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Malsomnus View Post
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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote