This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Classic Theme
Thottbot Theme
[Addon help] Expanding Hearth
Post Reply
Return to board index
Post by
Fizzles
Last year, I made an addon called
Hearth
. It was very minimalistic, and reminded people to stock up on food/drink/reagents, to sell up and to repair when they used their Hearthstone.
However, due to the lack of code, it would tell you to sell/repair whenever you entered the sub-zone you were bound to.
Here's the LUA file:
Hearth= AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceEvent-2.0")
function Hearth:OnInitialize()
-- Called when the addon is loaded
end
function Hearth:OnEnable()
-- Called when the addon is enabled
self:RegisterEvent("ZONE_CHANGED")
end
function Hearth:OnDisable()
-- Called when the addon is disabled
end
function Hearth:ZONE_CHANGED()
if GetBindLocation() == GetSubZoneText() then
self:Print("Welcome Home! Don't forget to repair your gear and restock on food, bandages, reagents, etc.")
end
end
I'm sure the AceLibs need updating, and something needs adding to Hearth:ZONE_CHANGED() to only let it function after Hearthstone or Astral Recall has been cast.
Any tips? D:
Post by
83344
This post was from a user who has deleted their account.
Post by
Fizzles
The files aren't updated.
Something needs to be added to the Zone_Changed string to make it less spammy.
At the moment is displays a message when you enter the area you're bound to.
It should only display a message right after you HS/AR/SoR.
Post by
83344
This post was from a user who has deleted their account.
Post by
Fizzles
How would I incorporate that?
funtion Hearth:UNIT_SPELLCAST_SUCCEEDED, "player", Hearthstone, 1, self
if GetBindLocation() == GetSubZoneText() then
self:Print("<message>")
end
end
Unit would be player, spell would be Hearthstone, rank would be 1 and target would be self.
I should warn you, I'm not very good at this.
Edit
: I'll do the same with AR and Scrolls, assuming I get the arguments right.
Post by
83344
This post was from a user who has deleted their account.
Post by
Fizzles
I'll give this a try:
function Hearth:UNIT_SPELLCAST_SUCCEEDED
if arg1 == "player" && arg2 == Hearthstone then
self:Print("<message">)
end
end
Edit: Nope, nothing.
Post by
pelf
God that omitting parentheses thing is so fracking obscene.
Post by
83344
This post was from a user who has deleted their account.
Post by
Fizzles
function OnEvent(self, event, ...)
I don't get any of the part in the parenthesis (except for self, I assume it's the target of the event).
And my latest attempt failed. I tried using some of the code from ComeHere, an addon that plays sounds on Death Grip.
function Hearth:OnEvent(event, arg1)
local spellName = GetSpellInfo(8690)
if strfind(spellName) and arg1 == "player" then
self:Print("Welcome Home!")
end
end
Post by
Wanderingfox
I think what you're looking for is:
function Hearth:OnEvent(self, event, ...)
if event == "UNIT_SPELLCAST_SUCCEEDED" then
if arg1 == "player" && arg2 == Hearthstone then
-- STUFF --
end
end
end
I could be wrong though, I haven't touched Lua in a while so I'm a bit rusty.
Post by
83344
This post was from a user who has deleted their account.
Post by
Wanderingfox
I was rushed and just copied the code above.
Anyway, now that I'm home... Here's the proper Ace3 implementation:
Hearth = LibStub("AceAddon-3.0"):NewAddon("Hearth", "AceConsole-3.0", "AceEvent-3.0")
function Hearth:OnInitialize()
-- Called when the addon is loaded
end
function Hearth:OnEnable()
-- Called when the addon is enabled
-- Register UNIT_SPELLCAST_SUCCEEDED
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
end
function Hearth:OnDisable()
-- Called when the addon is disabled
-- Unregister UNIT_SPELLCAST_SUCCEEDED
self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
end
function Hearth:UNIT_SPELLCAST_SUCCEEDED(event, unitID, spell)
if unitID == "player" and spell == GetSpellInfo(8690) then
print("Welcome Home! Don't forget to repair your gear and restock on food, bandages, reagents, etc.")
end
end
Note on optimization: You should probably have the spell names cached in a variable someplace so that you're not calling GetSpellInfo every time a spellcast completes, but I'm just demonstrating how it would be written).
Post by
Fizzles
I had it for a second, but then I had to go and make some changes to incorporate teleports and such.
Now it doesn't work. It's exactly as it is in Wanderingfox's post above, but doesn't seem to be working.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.