Of course. You should also do that when checking for existance of the saved var table (make sure you do it in the ADDON_LOADED though)
Code:local c = UnitName("player") mySavedVar = mySavedVar or {} mySavedVar[c] = (mySavedVar[c] or 0)+1
Of course. You should also do that when checking for existance of the saved var table (make sure you do it in the ADDON_LOADED though)
Code:local c = UnitName("player") mySavedVar = mySavedVar or {} mySavedVar[c] = (mySavedVar[c] or 0)+1
A better example of 'for in pairs()' might be:
Code:if table.getn(mySavedVar) > 1 then -- if we've logged in as more than one character local player = UnitName("Player") ChatFrame1:AddMessage('I believe I've also seen you:') for name,number in pairs(mySavedVar) do if name ~= player then if number = 1 then ChatFrame1:AddMessage('...once as '..name..'.') else ChatFrame1:AddMessage('...'..number..' times as '..name..'.') end end end end
Thank you for the guide, it's a useful read!
Nice info here
1 question:
Can you test the addon live? like without reloading the addon ? or restart the game ?
also. I have this addon that shows XP gained in an dungeon. I downloaded it from some guy here ^^ @ treeston
however . the window was very small .. so I located the source of the window and increased it by 2 times.
but .. now it has 1 big window with larger font( also increased the size) and 1 smaller window with the txt runXP
is it possible to show the window while not in an dungeon ? (I know it can be done but how ? just some tips maybe I come up with it myself
Signature removed. Please read our guidelines. Venara
Hand me that code I gave you.
downloaded it from your MY work link ^^ but here you go
Code:local curXP = UnitXP("player") local curMaxXP = UnitXPMax("player") local function calcxpgain(new) if new > curXP then local d = new-curXP curXP = new return d else local d = curMaxXP-curXP+new curXP = new curMaxXP = UnitXPMax("player") return d end end local an = ... local a = CreateFrame("Frame", nil, UIParent) --[===[@debug@ THEFRAME = a --@end-debug@]===] a:SetScript("OnShow", function(self) if UnitLevel("player") == MAX_PLAYER_LEVEL then self:Hide() end end) a:SetFrameStrata("DIALOG") a:SetScript("OnEvent", function(self, event, ...) local args = {...} if event == "ADDON_LOADED" and args[1] == an then RunXPData = RunXPData or {curInstanceXP = 0} if RunXPData.curInstance and GetLFGMode() ~= nil then self:RegisterEvent("PLAYER_XP_UPDATE") self:Show() self.text:Update() end if not RunXPData.point then a.header:SetPoint("CENTER", UIParent, "CENTER") else a.header:SetPoint(RunXPData.point, UIParent, RunXPData.relative, RunXPData.x, RunXPData.y) end self:UnregisterEvent("ADDON_LOADED") end if event == "LFG_COMPLETION_REWARD" and RunXPData.curInstance then RunXPData.instanceFinished = true a.text:Update() end if event == "LFG_UPDATE" or event == "PLAYER_LOGIN" then local status, substatus = GetLFGMode() local instanceName, instanceType, difficulty, maxpl, maxpl2, playerdiff, isdynamic = GetInstanceInfo() if (not RunXPData.curInstance) and (instanceType == "party") and (status == "lfgparty") and GetNumPartyMembers() == 4 then RunXPData.curInstance = instanceName self:RegisterEvent("PLAYER_XP_UPDATE") self:Show() self.text:Update() end if RunXPData.curInstance and status == nil then RunXPData.curInstance = nil RunXPData.instanceFinished = nil RunXPData.curInstanceXP = 0 self:UnregisterEvent("PLAYER_XP_UPDATE") self:Hide() end end if event == "PLAYER_XP_UPDATE" then RunXPData.curInstanceXP = RunXPData.curInstanceXP + calcxpgain(UnitXP("player")) self.text:Update() end end) a:RegisterEvent("ADDON_LOADED") a:RegisterEvent("LFG_COMPLETION_REWARD") a:RegisterEvent("LFG_UPDATE") a:RegisterEvent("PLAYER_XP_UPDATE") a:RegisterEvent("PLAYER_LOGIN") a:SetBackdrop({ bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border", tileSize=32, tile=true, insets={ top=4, bottom=4, right=4, left=4, }, }) a:SetSize(300,190) a:Hide() a.header = CreateFrame("Button", nil, a) a.header:SetNormalTexture("Interface\\DialogFrame\\UI-DialogBox-Header") a:SetPoint("TOP",a.header, "TOP", 0, -6) a.header:SetSize(200,68) a.header.text = a.header:CreateFontString() a.header.text:SetPoint("TOP",0,-7) a.header.text:SetFont("Fonts\\FRIZQT__.TTF", 16, "") a.header.text:SetText("RunXP") a.header:SetScript("OnMouseDown", function(self) if not InCombatLockdown() then self:StartMoving() end end) a.header:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() RunXPData.point,_,RunXPData.relative, RunXPData.x, RunXPData.y = self:GetPoint() end) a.header:SetMovable(true) a.text = a:CreateFontString() a.text:SetFont("Fonts\\FRIZQT__.TTF", 16, "") a.text:SetTextColor(1,0.8,0) a.text:SetPoint("TOPLEFT", 15, -15) a.text:SetJustifyH("LEFT") function a.text:Update() if RunXPData.instanceFinished and RunXPData.curInstanceXP > 0 then local runsUntilLvl = math.ceil((UnitXPMax("player")-UnitXP("player"))/RunXPData.curInstanceXP) self:SetText(RunXPData.curInstance.."\n"..RunXPData.curInstanceXP.." XP gained\n"..runsUntilLvl.." runs until level") self:Show() elseif RunXPData.curInstance then self:SetText(RunXPData.curInstance.."\n"..RunXPData.curInstanceXP.." XP gained") self:Show() else self:Hide() end a:SetSize(self:GetStringWidth()+30, self:GetStringHeight()+30) end
---------- Post added 2011-01-05 at 09:35 PM ----------
I just want to add some things to that addon ( a timer and maybe gold gained) but I think a timer is easier
Signature removed. Please read our guidelines. Venara
The self:Hide() line does the out-of-instance hiding (I think).Code:if event == "LFG_UPDATE" or event == "PLAYER_LOGIN" then local status, substatus = GetLFGMode() local instanceName, instanceType, difficulty, maxpl, maxpl2, playerdiff, isdynamic = GetInstanceInfo() if (not RunXPData.curInstance) and (instanceType == "party") and (status == "lfgparty") and GetNumPartyMembers() == 4 then RunXPData.curInstance = instanceName self:RegisterEvent("PLAYER_XP_UPDATE") self:Show() self.text:Update() end if RunXPData.curInstance and status == nil then RunXPData.curInstance = nil RunXPData.instanceFinished = nil RunXPData.curInstanceXP = 0 self:UnregisterEvent("PLAYER_XP_UPDATE") self:Hide() end end
editted to self:Show()
editted all self:Hide()'s to show
even deleted all shows
nothing worked
I think it really needs an instance or something .. maybe rewrite the whole thing that it shows XP always but with a button to reset it or something :d
EDIT: it does work .. l2activate the addon changed all hide;s to show
Last edited by Solidseal; 2011-01-05 at 09:14 PM.
Signature removed. Please read our guidelines. Venara
Ok guys, this is a wonderfulll guide, and reading this i went to the stables , hoped on ma big white horse and said "IM GONNA CREATE A WHYHELLOTHAR!!!!!!! " .......which aftera while (2 or so hours) and 1000 reloadui´s WORKS, but "not as intended" i´ll paste the code here, and the thing is that i have an XP Broker in Fortress , and when my code works the numbers do not match, my code just cant record correctly the mobs im killing, so....care to help?...ill post a screenshot too, maybe it´ll explain better....
Screenshoot:Code:-- RidOfMe: First try at making an addon, let´s see if may be done having zero programming skills.... ;) -- Purpose: Displaying a really annoying message each time your character gains any experience, telling you how many points you need to level up. -- Work Variables XP = UnitXP("player") TotalXP = UnitXPMax("player") MyLvl = UnitLevel("player") -- Code local f = CreateFrame("Frame") f:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN") f:SetScript("OnEvent", function(self,event,...) ChatFrame1:AddMessage(" Yes I´m annoying, but you are only " ..(TotalXP - XP).. " points away from getting rid of me, so move on to Level " ..(MyLvl + 1).. " ,NOW.") end)
Thanks for the help!
Qelk
---------- Post added 2011-01-06 at 01:30 AM ----------
Oh another thing, this coding provoked some weird side effect: Now when i kill anything instead of saying for example "2515" on the floating purple text above my head, it displays "430987:2515" indicating my current experience and the experience gotten from the kill....dunno...:P
Last edited by mmocba105e19de; 2011-01-06 at 12:47 AM. Reason: L2 post links
Apparently Physics applies where we are cows that become chickens then becomes cats then do you /kill and /lololololol.....yep. ^^Originally Posted by Idaho
God, if you can hear me, make it to be a dragon...Originally Posted by SPF18
Originally Posted by Spectro
You need to re-fetch your XP every time your OnEvent runs. Also, use locals.
I believe you need to put the 3 variables into where the chat message is added. By defining the variables before the function, they are only defined once. When you put them inside the function, the variables will be updated every time the function is triggered. So it should look like this:
As far as the weird side effect you are getting, I have no idea lol.Code:-- RidOfMe: First try at making an addon, let´s see if may be done having zero programming skills.... ;) -- Purpose: Displaying a really annoying message each time your character gains any experience, telling you how many points you need to level up. -- Code local f = CreateFrame("Frame") f:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN") f:SetScript("OnEvent", function(self,event,...) XP = UnitXP("player") TotalXP = UnitXPMax("player") MyLvl = UnitLevel("player") ChatFrame1:AddMessage(" Yes I´m annoying, but you are only " ..(TotalXP - XP).. " points away from getting rid of me, so move on to Level " ..(MyLvl + 1).. " ,NOW.") end)
EDIT: Sorry about that, made sure the cases were correct. I guess when I quoted the code it made everything lowercase.
Last edited by Pwnzorz; 2011-01-06 at 01:50 AM.
THAKS GUYS!, works like a charm now (its not like it useful, but knowing ZERO about programming, it makes me happy as a TMNT with a pizza). Now, for the sake of notice, i had to change the event from ""CHAT_MSG_COMBAT_XP_GAIN" to "PLAYER_XP_UPDATE" because it didn´t account XP from exploring or farming materials....
Quick question, originally, I wanted it to say "Yes i´m annoying but you are X points nearer to level Y , and of getting rid of me" where X should be the number of XP points that just were aerned a moment ago, but checking the list of functions on WowWiki i couldnt find one that read THAT number , example:
Kill a mob: 3498 XP earned,
"Yes I´m annoying but you are 3498 points nearer to level 82, and of getting rid of me"
So i had to work around and use "UnitXPMax("player") - UnitXP("player")" as an alternative, so anyone knows what event reads the XP amount you win in a given moment by killing,exploring,questing,farming?....or it cannot be read directly?.
PD: The side effect i named before still lingers, Pygmies knows why.....
Apparently Physics applies where we are cows that become chickens then becomes cats then do you /kill and /lololololol.....yep. ^^Originally Posted by Idaho
God, if you can hear me, make it to be a dragon...Originally Posted by SPF18
Originally Posted by Spectro
You could always store in a variable the value of UnitXP("player"), and then use that when calculating the change. Something like:
Code:-- RidOfMe: First try at making an addon, let´s see if may be done having zero programming skills.... ;) -- Purpose: Displaying a really annoying message each time your character gains any experience, telling you how many points you need to level up. -- Code RidOfMe = {} RidOfMe.old_xp = UnitXP("player") local f = CreateFrame("Frame") f:RegisterEvent("PLAYER_XP_UPDATE") f:SetScript("OnEvent", function(self,event,...) RidOfMe.XP = UnitXP("player") RidOfMe.MyLvl = UnitLevel("player") ChatFrame1:AddMessage(" Yes I´m annoying, but you are "..RidOfMe.XP - RidOfMe.old_xp.." points nearer to level "..RidOfMe.MyLvl+1..", and of getting rid of me") RidOfMe.old_xp = RidOfMe.XP end)
Of course, this is just based off of the last version of the code you used.
Last edited by Brusalk; 2011-01-06 at 03:31 PM.
would be more efficient.Code:local UnitXP, UnitLevel = UnitXP, UnitLevel local f = CreateFrame("Frame", "RidOfMe") f:RegisterEvent("PLAYER_XP_UPDATE") f.oldxp = UnitXP("player") f:SetScript("OnEvent", function(self) local xp = UnitXP("player") print("Yes, I'm annoying, but you are "..(xp-self.oldxp).." points nearer to level "..(UnitLevel("player")+1)..", and getting rid of me!") self.oldxp = xp end)
Reading through it I ran across a nitpicky detail in the If statements section going over operators. You state "== variable is equal to variable2" which is fine, though I personally prefer using the phrase "same as" rather than "equal to".
However, what occurred to me as potentially useful for the guide would be a note on the difference between "=" and "==". I searched, admittedly rather quickly, through the guide for a distinction between the two, but was unable to find it made anywhere. I would expect anyone with scripting experience to know the difference, but if this guide is intended to be used by those new to programming then this difference should be made clear. It's one of the easiest mistakes to make and one of the most frustrating to solve if you don't have an understanding on the differences between the two.
For those who might not understand, "=" is used to set the value of a variable. Thus, an if statement like "if x = y" will set the value of x to y rather than check to see if the values of the two variables are equivalent. It will also always return true (and thus perform whatever code is contained in the if statement), unless y is equivalent to 0. On the other hand, an if statement like "if x == y" will compare the values of x and y and only proceed with the code in the if statement if the two variables are equivalent in value.
It might also be useful to note that when checking for equality it will compare variable type. This might be a little more advanced than this guide warrants, but 0 == "0" will return false as the first is a number and the latter is a string.
My hello world script isn't working:
So I understand it should do /say WhyHelloThar when I login.Code:local f = CreateFrame("Frame") f:EventFrame:RegisterEvent("PLAYER_LOGIN") f:SetScript("OnEvent", function(self,event,...) ChatFrame1:AddMessage('WhyHelloThar') end)
But isn't working.
The thing is I wanted to create an addon that will hide my hunter bar using this: /script ShapeshiftBarFrame:Hide()
I write that in game to hide the bar, however if I teleport, or logount-login I neet to write it again.
It should be piece of cake, however I still don't understand function(self,event,...) those needs to be named? .... <- the dots needs to be removed?
In your tutorial you said:
Would be great to give an example.Code:local function print_f(arguments) --do stuff end
The "Player" needs to be renamed in a specific name?Code:local EventFrame = CreateFrame("Frame") EventFrame:RegisterEvent("PLAYER_LOGIN") EventFrame:SetScript("OnEvent", function(self,event,...) ChatFrame1:AddMessage('WhyHelloThar ".. UnitName("Player")) end)
If you could give a concrete example for my addon with the hiding stuff.
Thanks
Apparantly broke back in 3.3.5, having last seen an update February 2009.
There is however the intent to introduce a new version based on Visual Studio 2010 "soon".
Discussed at Evolution of Addon Studio for World of Warcraft @ Codeplex.
First of all, awesome guide!
Thats what I needed to finally start creating my own AddOns.
I've made a frame with 2 buttons with help of Ace3. Is there any way to lock the frame size? (something like frame:LockWidth() )
I dont want to be able to resize the frame with my mouse.