Script/addon help

I think its something like this. Check for every possible combination, and neutral is the ‘else’ at the very end.

local function getReactionColor(unit)
	if UnitIsFriend(unit, "player") then
		if UnitInParty(unit) or UnitInRaid(unit) then
			return  0, 0.5, 0.5
		elseif UnitIsInMyGuild(unit) then
			return 0, 0.33, 0.33
		elseif UnitIsPVP(unit) then
			return 0, 1, 0
		else
			return 0, 0, 1
		end
	elseif UnitIsEnemy(unit, "player") or UnitIsPVP(unit) or UnitIsPVPFreeForAll(unit) then
		return 1, 0, 0
	elseif UnitIsPlayer(unit) then
		return 0.75, 0.25, 0
	else
		return 0.5, 0.5, 0
	end
end

Yeah, it’s a mess. And that solution, while useful for most, doesn’t do much for the colorblind.

Yeah, and IIRC UnitIsEnemy doesn’t flag neutral units which makes it pretty useless for a lot of things. Realistically, UnitCanAttack covers most of the bases but there are some fringe cases that are annoying. It would be nice to have a better function without needing a convoluted workaround.

Hi, am I supposed to type that code into an in-game macro? Im very confused if someone could walk me through it.