Thread Tools Display Modes
04-23-06, 07:39 PM   #1
Vardelm
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 15
help finding a buff's index value?

I'm trying to create a function where I can give the name of a buff and the function will return the value of the index for that buff. Here's what I have so far, but it isn't working.

Code:
function GetBuffIndex(thisBuff)
  local counter = 1
  while (UnitBuff("player", counter)) do
    if (string.find(UnitBuff("player", counter), thisBuff)) then
      local buffIndex = counter;
    end
    counter = counter + 1
  end
  return buffIndex
end
Any suggestions on how to get this working? I've tried a bunch of small changes without luck so far. Maybe someone even has a function out there that does this already....?????
  Reply With Quote
04-24-06, 07:48 AM   #2
Nyrine
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2006
Posts: 23
Try this (no idea if it works!)

Code:
function GetBuffIndex(thisBuff)
  local counter = 1
  local buffIndex = 0
  while (UnitBuff("player", counter)) do
    if (string.find(UnitBuff("player", counter), thisBuff)) then
      buffIndex = counter;
    end
    counter = counter + 1
  end
  return buffIndex
end
In your code, buffIndex was only in scope inside the while loop, so once you dropped out it became undefined

OK... Done some playing around in luapad (great tool for this kind of thing)

With lightning shield, mana spring totem, tranquil air totem buffs on me I ran :
Code:
counter = 1
while (UnitBuff("player", counter)) do
ace:print(counter..":"..UnitBuff("player", counter))
counter = counter + 1
end
And it produced :

1:Interface\Icons\Spell_Nature_LightningShield
2:Interface\Icons\Spell_Nature_ManaRegenTotem
3:Interface\Icons\Spell_Nature_StoneSkinTotem

So... Whilst with a bit of tweaking your code may work, it seems the UnitBuff() call returns the Icon name, not the spell name.

Last edited by Nyrine : 04-24-06 at 07:55 AM.
  Reply With Quote
04-24-06, 09:48 AM   #3
brotherhobbes
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 313
Instead of re-inventing the wheel, why don't you check out IsBuffActive. It returns the Buff Index as the second return value when given a Spell Name. If you are re-inventing the wheel for learning purposes, don't look at this!

If you want to just get the Buff Texture Icon, here's code you can use in a macro (I think I got this from a post Gello made in the forums.worldofwarcraft.com UI section):

/script for i=1,24 do local b=UnitBuff("player",i) if b then GameTooltip:SetUnitBuff("player",i) DEFAULT_CHAT_FRAME:AddMessage((GameTooltipTextLeft1:GetText() or "").."="..b) end end
it's one long continous line when you put it in the macro box
  Reply With Quote
04-24-06, 02:26 PM   #4
Vardelm
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 15
Originally Posted by brotherhobbes
Instead of re-inventing the wheel, why don't you check out IsBuffActive. It returns the Buff Index as the second return value when given a Spell Name. If you are re-inventing the wheel for learning purposes, don't look at this!
I LOVE YOU!!!!!!!!!!

I'm not a big fan of reinventing wheels. I've been looking all over for an addon that had this functionality. I just haven't seen it until now. THANK YOU, THANK YOU, THANK YOU!!!!!!!!!!!
  Reply With Quote
04-24-06, 08:00 PM   #5
brotherhobbes
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 313
Originally Posted by Vardelm
I LOVE YOU!!!!!!!!!!
but we barely know each other! how about dinner and a movie first?
  Reply With Quote
04-25-06, 04:50 AM   #6
Vardelm
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 15
Originally Posted by brotherhobbes
but we barely know each other! how about dinner and a movie first?
Lemme ask my fiance if she minds a little company first...

I got the IsBuffActive() function to work. However, I seem to have run into another issue. I pass the index value to the GetPlayerBuffTimeLeft(buffIndex) function (it'sa stardard API call). All I get back from that function is a value of 0. I even tried just using value like GetPlayerBuffTimeLeft(2) instead of passing the variable, and I still only get 0 back from it. I'm testing it by taking the value I get back from it and outputing it through a chat message. Any chance you know if GetPlayerBuffTimeLeft() is not working, or am I missing something here?
  Reply With Quote
04-25-06, 08:09 PM   #7
Vardelm
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 15
After looking into this more, it looks like the reason GetPlayerBuffTimeLeft() isn't working with IsBuffActive() is that GetPlayerBuffTimeLeft() requires a Buff Index value, which is for PLAYER buffs only. IsBuffActive, on the other hand, is providing a Buff ID value. This is different than Buff Index values. Buff IDs are for working with Units. Buffs & Debuffs are handled differently for players than for other units, which is why you see the Get PlayerBuff... series of functions.

Bugger.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » help finding a buff's index value?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off