Skip to content

Instantly share code, notes, and snippets.

@AntoinePlu
Created November 19, 2020 10:41
Show Gist options
  • Save AntoinePlu/282e5d9ed7dfc8a62cc769357d9c2117 to your computer and use it in GitHub Desktop.
Save AntoinePlu/282e5d9ed7dfc8a62cc769357d9c2117 to your computer and use it in GitHub Desktop.
C_ChatInfo.RegisterAddonMessagePrefix("WSGFCNamesHP")
str_alliance_flag_drop = "Le drapeau de l'Alliance a été laché par "
str_horde_flag_drop = "Le drapeau de la Horde a été laché par "
str_alliance_flag_cap = "à capturé le drapeau de l'Alliance"
str_horde_flag_cap = "à capturé le drapeau de la Horde"
str_alliance_flag_pickup = "Le drapeau de l'Alliance a été ramassé par "
str_horde_flag_pickup = "Le drapeau de la Horde a été ramassé par "
local name_player, realm_player = UnitFullName("player")
FULLNAME_PLAYER = name_player .. "-" .. realm_player
time_addonmsg = 0
time_announce = 0
hp_tracker = -1
str_faction_player = UnitFactionGroup("player")
WSG_TABLE = {
["Alliance"]={
txt_flag_holder=nil,
str_flag_holder=nil,
str_flag_holder_macro = nil,
time_announce=0,
hp_tracker=1,
hp_msg_send="",
hp_received=nil,
hp_received_ts=0,
},
["Horde"]={
txt_flag_holder=nil,
str_flag_holder=nil,
str_flag_holder_macro = nil,
time_announce=0,
hp_tracker=1,
hp_msg_send="",
hp_received=nil,
hp_received_ts=0,
},
}
GET_FLAG_HOLDER_HP = function(faction_flag)
if str_faction_player ~= faction_flag then
local unitname = WSG_TABLE[faction_flag].str_flag_holder
local hp_cur = UnitHealth(unitname)
local hp_max = UnitHealthMax(unitname)
if hp_max > 0 then
return hp_cur/hp_max
end
else
for ii=1,10 do
local unit = "raid" .. ii .. "target"
if UnitExists(unit) then
local hp_cur = UnitHealth(unit)
local hp_max = UnitHealthMax(unit)
local unitname = GET_NAME_WITH_REALM(unit)
if unitname == WSG_TABLE[str_faction_player].str_flag_holder then
if hp_max > 0 then
return hp_cur/hp_max
end
end
end
end
end
return nil
end
GET_NAME_WITH_REALM = function(unit)
if UnitExists(unit) then
local name,realm = UnitName(unit)
if realm and realm ~= "" then
return name .. "-" .. realm
else
return name
end
else
return nil
end
end
GET_COLORED_NAME_FROM_BG_SCORE = function (playername)
local function GetClassFromBGScore(name_target)
--local numScores = GetNumBattlefieldScores()
for i=1,20 do
local name, killingBlows, honorableKills, deaths, honorGained, faction, rank, race, class, CLASS = GetBattlefieldScore(i);
if name == name_target then
return CLASS
end
end
return nil
end
local function DecimalToHex(r,g,b)
return string.format("|cff%02x%02x%02x", r*255, g*255, b*255)
end
local r,g,b,classcolor,PLAYERCLASS
if UnitInRaid(playername) then
_,PLAYERCLASS = UnitClass(playername)
else
PLAYERCLASS = GetClassFromBGScore(playername)
end
if PLAYERCLASS then
classcolor = RAID_CLASS_COLORS[PLAYERCLASS]
r,g,b = classcolor.r,classcolor.g,classcolor.b
else
r,g,b = 0.5,0.5,0.5
end
local classcolorhex = DecimalToHex(r,g,b)
return classcolorhex..playername.."|r"
end
INITIALIZE_FC_TEXT = function ()
local p = {UIWidgetTopCenterContainerFrame:GetChildren()};
local f
for ii = 1,2 do
f = p[ii]
if f then
if f.tooltip == "Horde flag captures" or f.tooltip == "Alliance flag captures" then
if not f.TXT_FLAG_HOLDER and not InCombatLockdown() then
local text_ = CreateFrame("Button", nil, f, "SecureUnitButtonTemplate")
text_:SetFrameStrata("MEDIUM")
text_:SetFrameLevel(15)
text_:SetPoint("LEFT",85,0)
text_:SetAttribute("type","macro")
text_:RegisterForClicks("AnyUp")
text_:SetAttribute('macrotext', '')
text_.text = text_:CreateFontString(nil,"ARTWORK")
text_.text:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
text_.text:SetPoint("LEFT",0,0)
text_.text:SetText("")
text_:SetSize(text_.text:GetWidth(),text_.text:GetHeight())
f.TXT_FLAG_HOLDER = text_
end
end
if f.TXT_FLAG_HOLDER then
if f.tooltip == "Horde flag captures" then
WSG_TABLE["Alliance"].txt_flag_holder = f.TXT_FLAG_HOLDER
elseif f.tooltip == "Alliance flag captures" then
WSG_TABLE["Horde"].txt_flag_holder = f.TXT_FLAG_HOLDER
end
end
end
end
end
INITIALIZE_FC_TEXT()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment