Thread Tools Display Modes
01-11-10, 01:02 PM   #41
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Yes. You can continue with your same file. Making a new file is unnecessary in the beginning. You only ever really need to make a new file if you want to separate major code parts. (Such as the "core" code of an AddOn and the "option" GUI of an AddOn.)

As for the code there, yes you can actually do it just like that. One thing, though. You need to change RAID_WARNING to "RAID_WARNING" (the quotes are necessary). Other than that, the only other issue is the misspelling of "Righteous".

Hope this helps.
__________________
Never be satisfied with satisfactory.
  Reply With Quote
01-11-10, 01:30 PM   #42
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Originally Posted by Cralor View Post
Yes. You can continue with your same file. Making a new file is unnecessary in the beginning. You only ever really need to make a new file if you want to separate major code parts. (Such as the "core" code of an AddOn and the "option" GUI of an AddOn.)

As for the code there, yes you can actually do it just like that. One thing, though. You need to change RAID_WARNING to "RAID_WARNING" (the quotes are necessary). Other than that, the only other issue is the misspelling of "Righteous".

Hope this helps.
Didn't happen anything when i activated Righteous Fury with this code:
Code:
local frame = CreateFrame("Frame", "RFFrame")
frame:RegisterEvent("UNIT_AURA")

local active = UnitBuff('player', 'Righteous Fury')
local hasrf = (active) -- will contain a boolean, true if 'active' contains a string, and false if 'active' contains nothing(nil)

local function eventHandler(self, event, ...)
    active = UnitBuff('player', 'Righteous Fury')
    if not hasrf and active then
        hasrf = true
        RaidNotice_AddMessage(RaidWarningFrame, "Threat Buff Activated", ChatTypeInfo["RAID_WARNING"])
    elseif hasrf and not active then
        hasrf = false
    end
end
frame:SetScript("OnEvent", eventHandler)
Can you see any problem that i did with the code?

Thanks for help anyway.
  Reply With Quote
01-11-10, 02:11 PM   #43
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Okay, just tested this myself, and the reason why it probably isn't working for you is if the buff already exists. The message will only appear after the buff has been added and not if it is already active.

If you try this out you will see what happens when:

Code:
local function eventHandler(self, event, ...)
    active = UnitBuff('player', 'Righteous Fury')
    if not hasrf and active then
        hasrf = true
        RaidNotice_AddMessage(RaidWarningFrame, "Threat Buff Activated", ChatTypeInfo["RAID_WARNING"])
    elseif hasrf and not active then
        hasrf = false
        RaidNotice_AddMessage(RaidWarningFrame, "Threat Buff Deactivated", ChatTypeInfo["RAID_WARNING"])
    elseif hasrf and active
        RaidNotice_AddMessage(RaidWarningFrame, "Threat Buff Refreshed", ChatTypeInfo["RAID_WARNING"])
    end
end
__________________

Last edited by Xrystal : 01-11-10 at 02:13 PM.
  Reply With Quote
01-11-10, 02:44 PM   #44
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Originally Posted by Xrystal View Post
Okay, just tested this myself, and the reason why it probably isn't working for you is if the buff already exists. The message will only appear after the buff has been added and not if it is already active.

If you try this out you will see what happens when:

Code:
local function eventHandler(self, event, ...)
    active = UnitBuff('player', 'Righteous Fury')
    if not hasrf and active then
        hasrf = true
        RaidNotice_AddMessage(RaidWarningFrame, "Threat Buff Activated", ChatTypeInfo["RAID_WARNING"])
    elseif hasrf and not active then
        hasrf = false
        RaidNotice_AddMessage(RaidWarningFrame, "Threat Buff Deactivated", ChatTypeInfo["RAID_WARNING"])
    elseif hasrf and active
        RaidNotice_AddMessage(RaidWarningFrame, "Threat Buff Refreshed", ChatTypeInfo["RAID_WARNING"])
    end
end
That one didnt work either actually.
  Reply With Quote
01-11-10, 02:45 PM   #45
dragonflyy
An Aku'mai Servant
 
dragonflyy's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 32
Also to help a new programmer out, if you want to test while you are programming, alt-tab to your code ... make a change, save the change then go back into WoW and type /console reloadui (or make a macro to do it for you.) Make sure you have the LUA Errors turned on in the interface options so you can see if any of your code has mistakes. Doing the reloadui command forces wow to re-initialize the interface. It helps for testing.

One more thing, if you think of a function as a small program running inside a larger program it sometimes helps in identifying where variables, calls, and other stuff might belong. Also as a final note, make sure you are saving these files with the extension .lua but as a text file and UTF-8 format, otherwise WoW might not interpret them properly.
  Reply With Quote
01-11-10, 03:03 PM   #46
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Originally Posted by opismahname View Post
That one didnt work either actually.
Hmm, it didn't ? Weird.

This is the code I have running on my Paladin. She's low level so not able to test the buff you are playing with. This works fine for me.

Code:
local frame = CreateFrame("Frame", "RFFrame")
frame:RegisterEvent("UNIT_AURA")

local active = UnitBuff("player", "Seal of Righteousness") 
local hasrf = (active) -- will contain a boolean, true if 'active' contains a string, and false if 'active' contains nothing(nil)

local function eventHandler(self, event, ...)
    active = UnitBuff("player", "Seal of Righteousness")
    if not hasrf and active then
        hasrf = true
        RaidNotice_AddMessage(RaidWarningFrame, "Seal of Righteousness Buff Activated", ChatTypeInfo["RAID_WARNING"])
    elseif hasrf and not active then
        hasrf = false
        RaidNotice_AddMessage(RaidWarningFrame, "Seal of Righteousness Buff Deactivated", ChatTypeInfo["RAID_WARNING"])
    elseif active then
        RaidNotice_AddMessage(RaidWarningFrame, "Seal of Righteousness Buff Active", ChatTypeInfo["RAID_WARNING"])
    end
end
frame:SetScript("OnEvent", eventHandler)
Here are some screenshots showing the message appearing. Watch the top center of the screen.

The first image shows the message that appears if you cast the buff while one is already active. The second, when the buff is removed and the third, when a fresh buff is activated.
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_011110_205924.jpg
Views:	766
Size:	333.6 KB
ID:	3836  Click image for larger version

Name:	WoWScrnShot_011110_205933.jpg
Views:	775
Size:	319.7 KB
ID:	3837  Click image for larger version

Name:	WoWScrnShot_011110_205938.jpg
Views:	750
Size:	339.1 KB
ID:	3838  
__________________
  Reply With Quote
01-12-10, 10:13 AM   #47
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Originally Posted by Xrystal View Post
Hmm, it didn't ? Weird.

This is the code I have running on my Paladin. She's low level so not able to test the buff you are playing with. This works fine for me.

Code:
local frame = CreateFrame("Frame", "RFFrame")
frame:RegisterEvent("UNIT_AURA")

local active = UnitBuff("player", "Seal of Righteousness") 
local hasrf = (active) -- will contain a boolean, true if 'active' contains a string, and false if 'active' contains nothing(nil)

local function eventHandler(self, event, ...)
    active = UnitBuff("player", "Seal of Righteousness")
    if not hasrf and active then
        hasrf = true
        RaidNotice_AddMessage(RaidWarningFrame, "Seal of Righteousness Buff Activated", ChatTypeInfo["RAID_WARNING"])
    elseif hasrf and not active then
        hasrf = false
        RaidNotice_AddMessage(RaidWarningFrame, "Seal of Righteousness Buff Deactivated", ChatTypeInfo["RAID_WARNING"])
    elseif active then
        RaidNotice_AddMessage(RaidWarningFrame, "Seal of Righteousness Buff Active", ChatTypeInfo["RAID_WARNING"])
    end
end
frame:SetScript("OnEvent", eventHandler)
Here are some screenshots showing the message appearing. Watch the top center of the screen.

The first image shows the message that appears if you cast the buff while one is already active. The second, when the buff is removed and the third, when a fresh buff is activated.
That one worked perfectly, thanks for helping!

And i got one question, is all these spaces needed like one end is with 4 spaces and 1 its no spaces.
  Reply With Quote
01-12-10, 10:17 AM   #48
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
It's not necessary but it makes reading it clearer as you need to make sure functions include an end. For statements need an end. If statements need an end. Otherwise you will get errors. Lining things up like that helps you to see at a glance where everything is.
__________________
  Reply With Quote
01-12-10, 04:31 PM   #49
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Originally Posted by opismahname View Post
That one worked perfectly, thanks for helping!

And i got one question, is all these spaces needed like one end is with 4 spaces and 1 its no spaces.
Like Xrystal said, the spacing is for code neatness and readability. You will find it is easier to work with code that is like above, rather than something with little to no spacing. It's actually the Tab key that most people use. One tab per "hierarchy".

Hope this helps.
__________________
Never be satisfied with satisfactory.
  Reply With Quote
01-13-10, 10:25 AM   #50
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Can i make own spaces if i want, because everyone is using like 4 spaces then the code, or 8 spaces, then the code, so can i have just 2 spaces and that if i want? ;P

And one more thing, i got this addon with the raiding message working perfectly now, and im wondering if i also can place the icon of the buff casted on yourself or target or whatever?
  Reply With Quote
01-13-10, 10:43 AM   #51
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Yes, the number of spaces you use is up to you. Most of the time I just tab to the next spot but sometimes I just use the space bar. Depends whether I am practising or working on releasable code.

As to the image being displayed. I think it is possible but you will probably have to make some changes for it to work. I haven't personally played with displaying a message with an icon like Miks Scrolling Battle Text but more than likely it is to do with setting up a frame to display with a texture object and a fontstring on there to receive the spell icon and your message and just hide the frame when it doesn't need to be displayed and display it when you want it to. Sounds simple right ?

Take a browse through the wowwiki widget api pages and look at the Frame options. There should be something like Frame:CreateTexture and Frame:CreateFontString or something to that affect, running on memory here rofl. There may even be some examples you could look at.

Make a new addon and copy the files ( renaming them appropriately ) and making the relevant changes to reflect the new addon idea functionality. This way if it doesn't work you can always go back to the one you started off with and rethink your strategy. If you have made the transfer correctly it should run as if you were running the original addon, but just with a different name.

Have fun investigating, try out some ideas and if you can't figure out why it doesn't work the way you want just post here and I'm sure we will be able to point you in the right direction.
__________________
  Reply With Quote
01-13-10, 11:26 AM   #52
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Originally Posted by Xrystal View Post
Yes, the number of spaces you use is up to you. Most of the time I just tab to the next spot but sometimes I just use the space bar. Depends whether I am practising or working on releasable code.

As to the image being displayed. I think it is possible but you will probably have to make some changes for it to work. I haven't personally played with displaying a message with an icon like Miks Scrolling Battle Text but more than likely it is to do with setting up a frame to display with a texture object and a fontstring on there to receive the spell icon and your message and just hide the frame when it doesn't need to be displayed and display it when you want it to. Sounds simple right ?

Take a browse through the wowwiki widget api pages and look at the Frame options. There should be something like Frame:CreateTexture and Frame:CreateFontString or something to that affect, running on memory here rofl. There may even be some examples you could look at.

Make a new addon and copy the files ( renaming them appropriately ) and making the relevant changes to reflect the new addon idea functionality. This way if it doesn't work you can always go back to the one you started off with and rethink your strategy. If you have made the transfer correctly it should run as if you were running the original addon, but just with a different name.

Have fun investigating, try out some ideas and if you can't figure out why it doesn't work the way you want just post here and I'm sure we will be able to point you in the right direction.
Heh, found one thing that might be able to load the icon into the raid message, and thats http://www.wowwiki.com /Queriable_buff_effects (scroll down almost so long as possible and take a look what is written there). But it says something about macros so im not sure :S
  Reply With Quote
01-13-10, 12:18 PM   #53
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Yeah, the macro lists all your buffs and what image files are used for the icons. However, it would only show the name and not the image itself. But it is a step in the direction.

Macro Code:
Code:
/script function m(s) DEFAULT_CHAT_FRAME:AddMessage(s); end for i=1,16 do s=UnitBuff("target", i); if(s) then m("B "..i..": "..s); end s=UnitDebuff("target", i); if(s) then m("D "..i..": "..s); end end
Lua Code:
Code:
function m(s) 
  DEFAULT_CHAT_FRAME:AddMessage(s); 
end 
for i=1,16 
  do s=UnitBuff("target", i); 
  if(s) then 
    m("B "..i..": "..s); 
  end s=UnitDebuff("target", i); 
  if(s) then 
    m("D "..i..": "..s); 
  end 
end
And as it shows on that page the following is what you will see.

B 1: Interface\Icons\Spell_Holy_WordFortitude
D 1: Interface\Icons\Ability_Gouge
B 2: Interface\Icons\INV_Jewelry_Talisman_07

B and D are values denoting they are a buff or debuff aura. The numbers are which of your buff and debuff lists it is. And then finally what image file it uses to display it.

In your example though you shouldn't need to do all that as your addon is looking for a specific buff and whether it is active or not.

If you look at this page you will see that you can retrieve more information from that UnitBuff function. The icon variable shown is one we would need and would return the same as that macro/function code I show above but for just the one buff and not for all 40 available.

http://www.wowwiki.com/API_UnitBuff

Once you have that information your next step is to figure out how to get the actual icon to display with your message and not the filename The following are pages that would be useful for this aspect. These two together will allow you to create a texture object on your visual frame and then set it with a texture file to use.

http://www.wowwiki.com/API_Frame_CreateTexture
http://www.wowwiki.com/API_Texture_SetTexture

Good Luck
__________________
  Reply With Quote
01-13-10, 12:28 PM   #54
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
http://www.wowwiki.com/Escape_sequences
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-13-10, 01:37 PM   #55
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Cool thanks Seerah. Think I'll be visiting that page at some point, somehow missed it in my travels
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » First Addon - need help

Thread Tools
Display Modes

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