Need some help with my first addon
So i wanted a really basic addon for my rogue alt, to tell me when to reroll the «roll the bones» buff.
Basically i wanted this functionality: When i enter combat i want the text «ROLL THE BONES» to be displayed in the middle of my screen UNTILL i get either True bearing, Shark infested waters OR 2 or more buffs. I thought that would be really simple, but it's been like 8 hours now and i still dont have it working properly. So i figured i could ask here and hopefully someone can help me understand what i should do. Right now it kinda works even though everything i have done is probably wrong, but i get the «ROLL THE BONES» text whenever i activate another buff and not only when im in combat. I figure this is because of the Lua Code:
but i dont understand how exactly im supposed to deal with these frames and events. So if someone could show me a proper way of doing it, i would really appreciate that. All other improvement tips would be great aswell! Another thing was the text itself, is there not a built in function or something to display the kinda text i want? Do you really need to make it like that from scratch? Here is the lua file, the first 30 lines is only the code i copy pasted for the fading text. http://pastebin.com/Ccw1nXi7 |
Well, UNIT_AURA fires when a unit's auras have changed. So when this fires, it sends you the unit that caused the event to fire. So you'd want to try something like this:
Lua Code:
|
UNIT_AURA fires for all valid units, not just the player. The unit it fires for will be the first argument past the event name itself, and you should check if it is the unit you wish to watch for.
A better method would be to register the event specifically for the player, using Lua Code:
http://wow.gamepedia.com/API_Frame_RegisterUnitEvent Also, you don't need to use HookScript for a frame that you've created. You know which scripts are set to it, which aren't, and what they do. HookScript is good when dealing with other addons' (or the default UI's) frames when you don't want to overwrite (or possibly overwrite) what scripts are already present. |
Quote:
I tried your code but the only difference it made was that the text "ROLL THE BONES" showed all the time when not in combat, while before it would pop up whenever i used a buff like sprint when not in combat. So it didnt really fix my problem, since i would only like to have it show when in combat. Quote:
Lua Code:
|
If you react to PLAYER_REGEN_DISABLED and PLAYER_REGEN_ENABLED events, they fire when you enter or leave combat respectively.
PS: Don't ever run select(1,...), you're wasting CPU time on a call that does absolutely nothing. |
Quote:
|
If you're storing the value for later use: (Additional values in the vararg are ignored)
Code:
local unit=... If you're running it through a function and just want the first value to be passed: (Parenthesis trim the value list to only allow the first to pass through) Code:
somefunc((...)) The reason select(1,...) does nothing is because it's an arg shift function, you're telling it to shift the args so it starts at index 1, which it at the beginning of the vararg list. |
If you know the ordinal then just pad until you reach it
local x = select(1, ...) becomes local x = ... local x = select(3, ...) becomes local _, _, x = ... That said, Gello did some testing that seems to have put paid to the myth about "Don't Use select ever" but "if you know the ordinal" why add overhead. |
Quote:
So i have tried a couple of variants with PLAYER_REGEN_DISABLED\ENABLED. But i cant get the text to show at all when i try to tell it to not show it for out of combat, it wont show in combat either. Would be really cool if someone could help me with how i should be testing with this event to do it properly. One example i tried that didn't work: Lua Code:
|
Lua Code:
Made changes to lines 10, 12, 27, and 29. In the last elseif (line 29), try encapsulating the "or" conditions within brackets. |
Hey.
The reason why it's not working is because you made your "combatcheck" local inside the onevent function. So every time the UNIT_AURA event fires, combatcheck will be false. Also, there a boolean data type you can use instead of string. (true/false without the quotation mark) Try this: Lua Code:
|
Quote:
Quote:
Thanks a lot guys, really appreciate it! |
All times are GMT -6. The time now is 04:43 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI