What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Set Watched Faction by Faction ID or Name

AtticusG3

New Member
Joined
Aug 27, 2011
Messages
425
Reaction score
11
Hi Guys,

I'm not very adept in the world of LUA or the WoW API in general, but I'm trying to write a macro to, as the thread title suggests, set my "Watched Faction" (IE the one that shows up as an XP Bar) given the Factions ID or name (Preff Faction ID)

Currently I can only work out how to set it by the Index
Code:
/run SetWatchedFactionID(42)
however this is going to be different on all of my toons, so I'd rather have it set it from the factions ID (IE 42 in my index is faction 369, gadgetzan)

I'm at a loss to work out how to do this, I can get the factions name given the index with GetFactionInfoByID() but how do I get the Index?

Basically I'm asking someone to write me a LUA script to do this. Or help me work through the logic at least. So i can implement it in my profile to display the relevant faction rep bar when grinding the faction out.
 
Does that macro you wrote in OP actually work?
I can't find any api called SetWatchedFactionID, only SetWatchedFactionIndex
Well it doesn't matter really, I'll just use the one I found.
 
ahh sorry, it was SetWatchedFactionIndex, mistype on my part.
 
Meh.. Blizzards API is gay when it comes to this.. As far as I can see - it's not possible to get the factionID from a faction by ID. You can get all information except ID. Woud it be ok for you to use faction name instead of id? Also, does it have to be in a form so short that it fits in an ingame macro? Or is a longer script ok (which can be run by plugins (e.g. PB))?
 
Last edited:
Name would be fine, and a LUA script is fine. I intend to run it from HB anyway.
 
Code:
local factionName = "Guardians of Hyjal"
local i = 1
local lastFactionName
repeat
  local name, description, standingId, bottomValue, topValue, earnedValue, atWarWith,
    canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild = GetFactionInfo(i)
  if name == lastFactionName then break end
  lastFactionName  = name
  if factionName:lower() == lastFactionName:lower() then SetWatchedFactionIndex(i) end
  i = i + 1
until i > 200
hopefully that should do the trick.
There is an easier method to do it - but that request all headers to be expanded, as it will only search through expanded headers.
This will go through all.
 
You could also use this, which will expand all headers for you:
Code:
local factionName = "Guardians of Hyjal" 
ExpandAllFactionHeaders()
for i=1, GetNumFactions()
    local name = select(1, GetFactionInfo(i))
    if factionName:lower() == name:lower() then 
        SetWatchedFactionIndex(i) 
    end
end
 
Awesome work Inrego, I'll test this when I get home tomorrow. :-D And let you know how it goes.
 
Code:
local factionName = "Guardians of Hyjal"
local i = 1
local lastFactionName
repeat
  local name, description, standingId, bottomValue, topValue, earnedValue, atWarWith,
    canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild = GetFactionInfo(i)
  if name == lastFactionName then break end
  lastFactionName  = name
  if factionName:lower() == lastFactionName:lower() then SetWatchedFactionIndex(i) end
  i = i + 1
until i > 200
hopefully that should do the trick.
There is an easier method to do it - but that request all headers to be expanded, as it will only search through expanded headers.
This will go through all.

This works, now I need to implement it where I want :-D. Thans for your help Inrego.

PS the second method didn't work for me.
 
This works, now I need to implement it where I want :-D. Thans for your help Inrego.

PS the second method didn't work for me.
I had a suspicion that the second wouldn't work, as expanding all headers probably isn't instant.
 
Back
Top