Need help creating a addon
Greetings,
I'm very new to creating addons in wow. However I do have some experience in programming (being a 4th year student in the programming business) but I can't get things to work yet. Ofcourse this is because I lack the experience and knowlage about programming in LUA. My idea is to create a very simple addon for myself which logs the mobs I kill by ID, Name and level. Currently I have: local frame = CreateFrame("FRAME", "KillCountFrame"); frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED"); local function eventHandler(self, event, ...) local timestamp, type, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags = select(1, ...) if (type == "PARTY_KILL") then print("Event: " .. type); print("You just killed a "..UnitName("target").."("..UnitLevel("target")..")"); end end frame:SetScript("OnEvent", eventHandler); The problem is however that the event is being triggered twice. Were I to put this in a WTF/Account etc file, it would register the kill as twice. How can I fix this? I have tried by setting the timestamp in the first to a global one, and then checking wether the global timestamp matches the current. But this didn't work. Also, I'm looking for a nice tutorial on how to write the information to a text file in the WTF/Account directory. Hope you can help me since i've been working on it for 3 hours also and the above code is all I got. Greetings, Levisaxos |
Addons can't write to text files on their own - however, WoW saves the variable that has the same name as the "SavedVariable" or "SavedVariablePerCharacter" line in the TOC file to a "SavedVariable" file.
|
Quote:
I think it's possible to control which data is being saved as a variable? For instance, when I kill 2 mobs, it should read as 2 in that file? Is this possible? |
Quote:
Code:
## SavedVariables: KillCountDB Code:
local CharID |
Quote:
How can I fix this? |
Quote:
Code:
local Char, PlayerID, Realm |
Quote:
also, it doesn't register party kills anymore. [edit] I've manage to get the UnitName from the destName parameter. However I can't seem to get the Unit level. Is there any way, like via GUID or flags, that I can use to help me get the unit level without him being a target? |
Are you using an XML file and/or loading your Lua file twice?
|
Quote:
The XML file consist of: Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" |
Quote:
|
If you have your Lua file listed in your TOC *and* in your XML file, then yes it would be loaded twice. But, as Nib mentioned, just delete your XML file. All you're using it for is to load the Lua file (which you can do in the TOC) and to create a frame (which you aren't using, because you create another one in the Lua file).
|
Thank you all for your help guys!
Now all I have to find out is how to filter the kills to only kills made by people in my group (Could use party_kills for that, but that doesn't get raid kills!) and people in my raid! So i'm guessing I will have to check the sourceName or sourceGUID to my raidmembers. If anyone wishes to help me with that they are welcome to do so ;) [edit] I noticed that PARTY_KILL event is being triggered before UNIT_DIED.. so when I kill one myself I can just check the sourceGUID with my GUID on a PARTY_KILL event. PARTY_KILL is also triggered when someone from my group kills a mob so that one isn't hard either.. However, how can I register if a mob is killed by a raid member? UNIT_DIED does not give a valid sourceGUID of the person that killed him? |
Quote:
Here is a quick example (borrowing the code from Nibelheim ;)) Code:
local Char, PlayerID, Realm |
Quote:
Currently I have it fixed by checking in which zone I am. If i'm in a raid zone, it only reacts to the UNIT_DEAD event type. It still has some bumbs and bruises, like party members dying are being read as a kill aswell, but slowly i'm getting there ! |
All times are GMT -6. The time now is 11:24 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI