Perhaps something like this might work. It should only trigger while PvP flagged and ignores when flagged FFA. This should be obvious when you're screwed as everyone is your enemy. I would choose a more personal chat channel as this would alert them to your location as well. The idea is to try to send the alert out before you're dead, and maybe before you're even spotted, but that isn't guaranteed to happen.
Lua Code:
--[[ Localized globals for COMBAT_LOG_EVENT_UNFILTERED ]]
local bit_band=bit.band;
local COMBATLOG_FILTER_HOSTILE_PLAYERS=COMBATLOG_FILTER_HOSTILE_PLAYERS;
local GetTime=GetTime;
local string_format=string.format;
local BitMasks={
COMBATLOG_OBJECT_AFFILIATION_MASK;
COMBATLOG_OBJECT_REACTION_MASK;
COMBATLOG_OBJECT_CONTROL_MASK;
COMBATLOG_OBJECT_TYPE_MASK;
};
--[[ Settings ]]
local MessageThrottle=60;-- Seconds between messages about the same player
local MessageFormat="Warning: Hostile player %s is nearby!";
local MessageChannel,MessageTarget="YELL",nil;
--[[ Internal variables ]]
local AlertedPlayers={};
--[[ Magic stuff ]]
local function HandleAlert(guid,name,flags)
if guid then
-- Is unit hostile player? (Check flags, exit if a field doesn't match)
flags=bit_band(flags,COMBATLOG_FILTER_HOSTILE_PLAYERS)-- Trim unused bits
for _,mask in ipairs(BitMasks) do if bit_band(flags,mask)==0 then return; end end
-- Message throttling (don't want to spam chat)
local now=GetTime();
if now-(AlertedPlayers[guid] or -MessageThrottle)>MessageThrottle then
AlertedPlayers[guid]=now;
SendChatMessage(string_format(MessageFormat,name),nil,MessageChannel,MessageTarget);
end
end
end
local AlertFrame=CreateFrame("Frame");
AlertFrame:RegisterEvent("PLAYER_ENTERING_WORLD");-- Sanity check when logging in or zoning into PvP area via loading screen
AlertFrame:RegisterUnitEvent("UNIT_FACTION","player");-- Neutral player chose faction? PlayerFrame does this to update PvP texture
AlertFrame:RegisterUnitEvent("HONOR_PRESTIGE_UPDATE","player");-- PvP flag update? Only other PvP event PlayerFrame uses
AlertFrame:SetScript("OnEvent",function(self,event,_,_,_,srcguid,srcname,srcflags,_,destguid,destname,destflags)
if event=="COMBAT_LOG_EVENT_UNFILTERED" then
HandleAlert(srcguid,srcname,srcflags);-- Hostile player did something?
HandleAlert(destguid,destname,destflags);-- Something done to hostile player?
else-- Code below this point doesn't run frequently, localized globals is unnecessary
-- Enable based on PvP flag and FFA
if UnitFactionGroup("player")~="Neutral" and UnitIsPVP("player") and not UnitIsPVPFreeForAll("player") then
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
else
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
table.wipe(AlertedPlayers);-- Clean up when disabling
end
end
end);