wowpedia
Main Menu


Unit flags contain information for a unit in the combat log. They are returned from COMBAT_LOG_EVENT sourceFlags and destFlags params.

A unit can only be one type from each of the following four categories:

  1. Type: The way the unit is currently being controlled.
  2. Controller: Who currently controls this unit - an NPC or a player.
  3. Reaction: The unit's reaction, relative to you - hostile, friendly or neutral.
  4. Affiliation: If the unit belongs to you (your character, pet, mind controlled) or is in your party or raid, or neither.

Constants

Source: FrameXML/Constants.lua

Constant Bit field Description
Affiliation
COMBATLOG_OBJECT_AFFILIATION_MINE 0x 0 0 0 0 0 0 0 1
COMBATLOG_OBJECT_AFFILIATION_PARTY 0x 0 0 0 0 0 0 0 2
COMBATLOG_OBJECT_AFFILIATION_RAID 0x 0 0 0 0 0 0 0 4
COMBATLOG_OBJECT_AFFILIATION_OUTSIDER 0x 0 0 0 0 0 0 0 8
COMBATLOG_OBJECT_AFFILIATION_MASK 0x 0 0 0 0 0 0 0 F
Reaction
COMBATLOG_OBJECT_REACTION_FRIENDLY 0x 0 0 0 0 0 0 1 0
COMBATLOG_OBJECT_REACTION_NEUTRAL 0x 0 0 0 0 0 0 2 0
COMBATLOG_OBJECT_REACTION_HOSTILE 0x 0 0 0 0 0 0 4 0
COMBATLOG_OBJECT_REACTION_MASK 0x 0 0 0 0 0 0 F 0
Controller
COMBATLOG_OBJECT_CONTROL_PLAYER 0x 0 0 0 0 0 1 0 0
COMBATLOG_OBJECT_CONTROL_NPC 0x 0 0 0 0 0 2 0 0
COMBATLOG_OBJECT_CONTROL_MASK 0x 0 0 0 0 0 3 0 0
Type
COMBATLOG_OBJECT_TYPE_PLAYER 0x 0 0 0 0 0 4 0 0 Units directly controlled by players.
COMBATLOG_OBJECT_TYPE_NPC 0x 0 0 0 0 0 8 0 0 Units controlled by the server.
COMBATLOG_OBJECT_TYPE_PET 0x 0 0 0 0 1 0 0 0 Pets are units controlled by a player or NPC, including via mind control.
COMBATLOG_OBJECT_TYPE_GUARDIAN 0x 0 0 0 0 2 0 0 0 Units that are not controlled, but automatically defend their master.
COMBATLOG_OBJECT_TYPE_OBJECT 0x 0 0 0 0 4 0 0 0 Objects are everything else, such as traps and totems.
COMBATLOG_OBJECT_TYPE_MASK 0x 0 0 0 0 F C 0 0
Special cases (non-exclusive)
COMBATLOG_OBJECT_TARGET 0x 0 0 0 1 0 0 0 0
COMBATLOG_OBJECT_FOCUS 0x 0 0 0 2 0 0 0 0
COMBATLOG_OBJECT_MAINTANK 0x 0 0 0 4 0 0 0 0
COMBATLOG_OBJECT_MAINASSIST 0x 0 0 0 8 0 0 0 0
COMBATLOG_OBJECT_NONE 0x 8 0 0 0 0 0 0 0 Whether the unit does not exist.
COMBATLOG_OBJECT_SPECIAL_MASK 0x F F F F 0 0 0 0

Example

if bit.band(unitFlag, COMBATLOG_OBJECT_REACTION_FRIENDLY) > 0 then
	print("unit is friendly")
end
local flags = {
	[COMBATLOG_OBJECT_AFFILIATION_MASK] = {
		[COMBATLOG_OBJECT_AFFILIATION_MINE] = "Affiliation: Mine",
		[COMBATLOG_OBJECT_AFFILIATION_PARTY] = "Affiliation: Party",
		[COMBATLOG_OBJECT_AFFILIATION_RAID] = "Affiliation: Raid",
		[COMBATLOG_OBJECT_AFFILIATION_OUTSIDER] = "Affiliation: Outsider",
	},
	[COMBATLOG_OBJECT_REACTION_MASK] = {
		[COMBATLOG_OBJECT_REACTION_FRIENDLY] = "Reaction: Friendly",
		[COMBATLOG_OBJECT_REACTION_NEUTRAL] = "Reaction: Neutral",
		[COMBATLOG_OBJECT_REACTION_HOSTILE] = "Reaction: Hostile",
	},
	[COMBATLOG_OBJECT_CONTROL_MASK] = {
		[COMBATLOG_OBJECT_CONTROL_PLAYER] = "Control: Player",
		[COMBATLOG_OBJECT_CONTROL_NPC] = "Control: NPC",
	},
	[COMBATLOG_OBJECT_TYPE_MASK] = {
		[COMBATLOG_OBJECT_TYPE_PLAYER] = "Type: Player",
		[COMBATLOG_OBJECT_TYPE_NPC] = "Type: NPC",
		[COMBATLOG_OBJECT_TYPE_PET] = "Type: Pet",
		[COMBATLOG_OBJECT_TYPE_GUARDIAN] = "Type: Guardian",
		[COMBATLOG_OBJECT_TYPE_OBJECT] = "Type: Object",
	},
}
local order = {"TYPE", "CONTROL", "REACTION", "AFFILIATION"}

local f = CreateFrame("Frame")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:SetScript("OnEvent", function(self, event)
	self:COMBAT_LOG_EVENT_UNFILTERED(CombatLogGetCurrentEventInfo())
end)

function f:COMBAT_LOG_EVENT_UNFILTERED(...)
	local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = ...
	if destName then
		local t = {}
		table.insert(t, subevent)
		table.insert(t, destName)
		table.insert(t, format("0x%X", destFlags))
		for _, v in pairs(order) do
			local mask = _G["COMBATLOG_OBJECT_"..v.."_MASK"]
			local bitfield = bit.band(destFlags, mask)
			local info = flags[mask][bitfield]
			table.insert(t, (info:gsub(": (%a+)", ": |cff71d5ff%1|r"))) -- add some coloring
		end
		print(table.concat(t, ", "))
	end
end

A few of these example situations were with the unit targeted (COMBATLOG_OBJECT_TARGET). Some situations are not distinguishable from each other without additional checks.

UnitFlag1
UnitFlag2
UnitFlag3
Your mind controlled NPC.
UnitFlag4
UnitFlag7
UnitFlag5
A party member mind controlled by a friendly player (who is not in your party) in a duel.
UnitFlag6

Filters

It's convenient to use CombatLog_Object_IsA() for checking multiple bitfields.

Prints if the combat log source unit is a hostile NPC.

local f = CreateFrame("Frame")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:SetScript("OnEvent", function(self, event)
	local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags = CombatLogGetCurrentEventInfo()
	if CombatLog_Object_IsA(sourceFlags, COMBATLOG_FILTER_HOSTILE_UNITS) then
		print(subevent, sourceName, format("0x%X", sourceFlags), "is a hostile NPC")
	end
end)

Patch changes

They were previously part of the special cases section as follows:

Icon Constant Bit field
IconSmall RaidStar COMBATLOG_OBJECT_RAIDTARGET1 0x 0 0 1 0 0 0 0 0
IconSmall RaidCircle COMBATLOG_OBJECT_RAIDTARGET2 0x 0 0 2 0 0 0 0 0
IconSmall RaidDiamond COMBATLOG_OBJECT_RAIDTARGET3 0x 0 0 4 0 0 0 0 0
IconSmall RaidTriangle COMBATLOG_OBJECT_RAIDTARGET4 0x 0 0 8 0 0 0 0 0
IconSmall RaidMoon COMBATLOG_OBJECT_RAIDTARGET5 0x 0 1 0 0 0 0 0 0
IconSmall RaidSquare COMBATLOG_OBJECT_RAIDTARGET6 0x 0 2 0 0 0 0 0 0
IconSmall RaidCross COMBATLOG_OBJECT_RAIDTARGET7 0x 0 4 0 0 0 0 0 0
IconSmall RaidSkull COMBATLOG_OBJECT_RAIDTARGET8 0x 0 8 0 0 0 0 0 0
COMBATLOG_OBJECT_SPECIAL_MASK 0x F F F F 0 0 0 0