API UnitGUID

From Wowpedia
Jump to: navigation, search
Main Menu


WoW API

Returns the GUID of the specified unit.

guid = UnitGUID("unit")

Arguments

unit 
String (unitId) - unit to look up the GUID of.

Returns

guid 
String (GUID) - a string containing the hexadecimal representation of the unit's GUID, e.g. "0xF130C3030000037F2", or nil if the unit does not exist.

Example

The following snippet attempts to figure out what you're targeting based on its GUID:

local guid, name = UnitGUID("target"), UnitName("target")
local knownTypes = {[0]="player", [1]="world object", [3]="NPC", [4]="pet", [5]="vehicle"}
local maskedTypeBit = tonumber(guid:sub(5,5), 16) % 8
print(name .. " is a " .. (knownTypes[maskedTypeBit] or " unknown entity!"));
if knownTypes[maskedTypeBit] == "NPC" then
 print(name .. "'s NPC id is " .. tonumber(guid:sub(6,10), 16))
end

See also

Personal tools
Namespaces
Variants
Actions
Navigation Portals
Interaction
Toolbox