Thread Tools Display Modes
06-04-07, 05:08 AM   #1
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
Helm Auto-Toggle Addon - Massive help needed

My knowledge of LUA is totally lacking, all i know is some stuff ive read at the WoWwiki tutorials page :S I'm 1st year programming student so i have some idea about programming, but without knowing the language....

This addon is supposed to check if the player is in combat, if yes to show helm graphic, and if not to hide it.
----.LUA file---
function HelmInCombatFrame_OnLoad()
this:RegisterEvent("PLAYER_ENTERING_WORLD");
this:SetScript("PLAYER_ENTERING_WORLD",HelmInCombat);
end

function HelmInCombat()
this:RegisterEvent("PLAYER_REGEN_DISABLED");
this:RegisterEvent("PLAYER_REGEN_ENABLED");
if(event=="PLAYER_REGEN_DISABLED") then
if(event=="PLAYER_REGEN_DISABLED") then
ShowHelm();
elseif(event=="PLAYER_REGEN_ENABLED") then
ShowHelm('false');
end
end
---
---.TOC file---
## Interface: 20100
## Title: HelmInCombat
## Notes: Enables your helm graphic when you enter combat.
## Author: DarkRa
## OptionalDeps:
## Dependencies:
HelmInCombat.lua
---
My main questions:
1) Syntax/logic. Is it correct? do i need to change something?
2) XML file. Do I need to create one? What should I put in it?

Last edited by darkra : 06-04-07 at 05:52 AM.
  Reply With Quote
06-04-07, 06:13 AM   #2
Jazradel
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 39
You actually need a frame to trigger the events.
You can create a frame in the .lua. Look at http://ui.worldofwar.net/ui.php?id=3876 for a good example. Or you can create an xml file that defines the frame.

I don't think you want to register the events everytime HelmInCombat() runs, only when you load. Maybe something like this:
Code:
local HIC = CreateFrame("Frame","HIC_Frame");
HIC:RegisterEvent("PLAYER_REGEN_ENABLED");
HIC:RegisterEvent("PLAYER_REGEN_DISABLED");
HIC:SetScript("OnEvent", function() FixIncombatPetBar() end);

function HelmInCombat()
if(event=="PLAYER_REGEN_DISABLED") then
ShowHelm();
elseif(event=="PLAYER_REGEN_ENABLED") then
ShowHelm('false');
end
end
Edit: Don't trust me on this, I'm not even a first year programming student.

Last edited by Jazradel : 06-04-07 at 06:19 AM.
  Reply With Quote
06-04-07, 06:35 AM   #3
darkra
A Deviate Faerie Dragon
Join Date: Jun 2007
Posts: 11
local HIC = CreateFrame("Frame","HIC_Frame");
HIC:RegisterEvent("PLAYER_REGEN_ENABLED");
HIC:RegisterEvent("PLAYER_REGEN_DISABLED");
HIC:SetScript("OnEvent", function() HelmInCombat() end);

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

Works like a charm mate, thanks a lot
  Reply With Quote
06-04-07, 03:08 PM   #4
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Originally Posted by darkra
local HIC = CreateFrame("Frame","HIC_Frame");
HIC:RegisterEvent("PLAYER_REGEN_ENABLED");
HIC:RegisterEvent("PLAYER_REGEN_DISABLED");
HIC:SetScript("OnEvent", function() HelmInCombat() end);

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

Works like a charm mate, thanks a lot
For efficiency purposes (globals are evil):

change
Code:
HIC:SetScript("OnEvent", function() HelmInCombat() end);
to
Code:
HIC:SetScript("OnEvent", HelmInCombat)
and
Code:
function HelmInCombat()
to
Code:
function HelmInCombat(self, event)
Get in the habit of doing this, otherwise you're going to see your mods start breaking when they take out the event/arg1 globals in a future patch (they are already deprecated)
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Helm Auto-Toggle Addon - Massive help needed


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