Thread Tools Display Modes
06-02-07, 04:21 PM   #1
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
Auto-Tonggle Helm Visibility Addon

I'm a bit of a RPer, and I wonder if an addon can be made that can switch the visibility of helm/cloak graphic when entering/exiting combat. I know a bit of .lua, so any tips are welcome.

Thanks
  Reply With Quote
06-02-07, 04:43 PM   #2
Rollak
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 36
I'd use LUA and make a frame, and register:

PLAYER_ENTER_COMBAT
PLAYER_LEAVE_COMBAT

Then in the event handler.

if event == PLAYER_ENTER_COMBAT then ShowHelm('true') else ShowHelm('false');

Hope that points you in the right direction
Obviously it's Pseudo code, but it outlines the basic idea behind it.

I'm fairly sure addons are allowed to do that with no interaction. Might be wrong though.
  Reply With Quote
06-02-07, 05:04 PM   #3
Llivavin
A Black Drake
Join Date: Jun 2007
Posts: 89
Originally Posted by Rollak
I'd use LUA and make a frame, and register:

PLAYER_ENTER_COMBAT
PLAYER_LEAVE_COMBAT

Then in the event handler.

if event == PLAYER_ENTER_COMBAT then ShowHelm('true') else ShowHelm('false');

Hope that points you in the right direction
Obviously it's Pseudo code, but it outlines the basic idea behind it.

I'm fairly sure addons are allowed to do that with no interaction. Might be wrong though.
Nope you need to have interaction so make it into a macro with one of the spells you spam alot!

wait strike that Its an option so im gonna go with probly not seeing as its not equiping or de-equiping things

but yeah get someone to make it into a macro for you and put it with a spell you spam alot

Last edited by Llivavin : 06-02-07 at 05:11 PM.
  Reply With Quote
06-02-07, 05:11 PM   #4
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by Llivavin
Nope you need to have interaction so make it into a macro with one of the spells you spam alot!
No, that's what we have addons with event catchers for.

wait strike that Its an option so im gonna go with probly not seeing as its not equiping or de-equiping things
What?!
__________________
Grab your sword and fight the Horde!

Last edited by Lombra : 06-02-07 at 05:17 PM.
  Reply With Quote
06-02-07, 06:40 PM   #5
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
bah, for the life of me i can;t bring it even close on working, apparently i overestimated my knowledge of lua

Anyone can help?
  Reply With Quote
06-03-07, 05:03 AM   #6
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
What do you have so far?
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-03-07, 05:38 AM   #7
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
i made the function that tonggles the helm/cloack options (got some parts of code from a addon called zCloakHelmCyrcle) What i dont know how to do is to make a function that checks when i enter/exit combat. If this is done i think its a simple "if" loop then, right?
  Reply With Quote
06-03-07, 05:49 AM   #8
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Almost. You gotta register a couple of events as suggested above, then call your function whenever an event fires.

Look here for better and further explanation.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-03-07, 06:44 AM   #9
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
That link was a great help, thanks

I wrote some code that i though it should work, but it doesnt. Although it appears on the addon selection list, it doesnt make the message "HelmInCombat Loaded." when i log in.

----

function HelmInCombat_OnLoad()
if ( DEFAULT_CHAT_FRAME ) then
DEFAULT_CHAT_FRAME:AddMessage("HelmInCombat Loaded.");
end

function HelmInCombat()
if(event=="PLAYER_REGEN_DISABLED") then
H=1;
elseif(event=="PLAYER_REGEN_ENABLED") then
H=0;
end
end


local frame = CreateFrame("HelmInCombatFrame");
frame:SetScript("OnEvent", HelmInCombat);
frame:RegisterEvent("PLAYER_REGEN_DISABLED");
frame:RegisterEvent("PLAYER_REGEN_ENABLED");

function HelmInCombat_GetValues()
if ShowingHelm() then Helm_Show=1 else Helm_Show=0 end;
end

function HelmInCombat_SetValues(H)
ShowHelm(H);
end
-------
Any help again, greatly appreciated

Last edited by darkra : 06-03-07 at 07:39 AM.
  Reply With Quote
06-03-07, 07:36 AM   #10
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
Also pasting the xml and toc files, just in case i did sthing wrond with them:

XML:
----
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="HelmInCombat.lua"/>
<Frame name="HelmInCombatFrame" hidden="true">
<Scripts>
<OnLoad>
HelmInCombat_OnLoad();
</OnLoad>
</Scripts>
</Frame>
</Script>
</Ui>
----

TOC:
---
## Interface: 20100
## Title: HelmInCombat
## Notes: Enables your helm graphic when you enter combat.
## Author: DarkRa
## OptionalDeps:
## Dependencies:
HelmInCombat.xml
---
  Reply With Quote
06-03-07, 09:31 AM   #11
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Try setting the OnLoad function in the lua-file too, like you did the OnEvent function, leaving out the XML-file entirely.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-03-07, 09:47 AM   #12
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
local frame = CreateFrame("HelmInCombatFrame");
frame:SetScript("OnLoad", HelmInCombat_OnLoad);
frame:SetScript("OnEvent", HelmInCombat);
frame:RegisterEvent("PLAYER_REGEN_DISABLED");
frame:RegisterEvent("PLAYER_REGEN_ENABLED");

you meant like that? it doesnt work
  Reply With Quote
06-03-07, 10:37 AM   #13
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
You cannot set OnLoad for a dynamically created frame, it doesn't make sense. The frame will be loaded before you will ever be able to SetScript on it.

OP: I recommend you try the chat message during the event PLAYER_ENTERING_WORLD, not during OnLoad. You can't guarantee the existance of anything during OnLoad, which is probably why it's not showing up.

Concurrently, the use of a global H is a horrible idea:
function HelmInCombat()
if(event=="PLAYER_REGEN_DISABLED") then
H=1;
elseif(event=="PLAYER_REGEN_ENABLED") then
H=0;
end
end
Please, either change the name of your variable or put
Code:
local H;
before the function. Otherwise you're just asking for addons to conflict. Similarly, what is GetValues() and SetValues()? I would just do this stuff during the PLAYER_REGEN_XXX events. Finally, last thing you need to do, don't register for events in the Lua file if you're doing it outside of a function, you should do it in OnLoad or inside a Lua function that will be called by OnLoad. Otherwise you have the potential to not have the frame in existance when you do the registration.
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
06-03-07, 11:16 AM   #14
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
Now i'm totally confused :S As i said, i have very little experience with lua...

Is any of the code salvagable or it's so far from working that it's not worth bothering?
  Reply With Quote
06-03-07, 01:16 PM   #15
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Originally Posted by darkra
Now i'm totally confused :S As i said, i have very little experience with lua...

Is any of the code salvagable or it's so far from working that it's not worth bothering?
No, you're pretty close.

Instead of H=1 and H=0, why don't you just show and hide the helm there?
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
06-03-07, 01:52 PM   #16
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
ok, i removed Get/SetValue and i got:
---
function HelmInCombat_OnLoad()
if ( DEFAULT_CHAT_FRAME ) then
DEFAULT_CHAT_FRAME:AddMessage("HelmInCombat Loaded.");
end

function HelmInCombat()
if(event=="PLAYER_REGEN_DISABLED") then
ShowHelm()='true';
elseif(event=="PLAYER_REGEN_ENABLED") then
ShowHelm()='false';
end
end

local frame = CreateFrame("HelmInCombatFrame");
frame:SetScript("OnEvent", HelmInCombat);
frame:RegisterEvent("PLAYER_REGEN_DISABLED");
frame:RegisterEvent("PLAYER_REGEN_ENABLED");
---
How do i change OnLoad with the event PLAYER_ENTERING_WORLD?
And what about the xml? i keep it/change it/throw it away completely?

Last edited by darkra : 06-03-07 at 01:58 PM.
  Reply With Quote
06-03-07, 01:58 PM   #17
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
It's the same as the way you're watching for PLAYER_REGEN_DISABLED and PLAYER_REGEN_ENABLED. Register for the PLAYER_ENTERING_WORLD event and in your OnEvent script (HelmInCombat()) check for event == "PLAYER_ENTERING_WORLD" and do what you need to do.
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
06-03-07, 02:55 PM   #18
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
i removed function HelmInCombat_OnLoad() completely and i changed the frame to:

local frame = CreateFrame("HelmInCombatFrame");
frame:SetScript("PLAYER_ENTERING_WORLD",HelmInCombat);
frame:RegisterEvent("PLAYER_REGEN_DISABLED");
frame:RegisterEvent("PLAYER_REGEN_ENABLED");
frame:RegisterEvent("PLAYER_ENTERING_WORLD");

Still not sure what to do with the .xml file
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Auto-Tonggle Helm Visibility Addon


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