Page 3 of 7 FirstFirst
1
2
3
4
5
... LastLast
  1. #41
    Deleted
    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

  2. #42
    Blademaster
    10+ Year Old Account
    Join Date
    Jan 2011
    Location
    Seattle, WA
    Posts
    41
    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

  3. #43
    Thank you for the guide, it's a useful read!

  4. #44
    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

  5. #45
    Deleted
    Hand me that code I gave you.

  6. #46
    Quote Originally Posted by Treeston View Post
    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

  7. #47
    Deleted
    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
    The self:Hide() line does the out-of-instance hiding (I think).

  8. #48
    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

  9. #49
    High Overlord Qelkhandras's Avatar
    10+ Year Old Account
    Join Date
    Mar 2010
    Location
    beneath your bed, so, don´t troll or i´ll notice
    Posts
    148

    Help!, coding is not my friend...

    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....

    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)
    Screenshoot:



    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
    Quote Originally Posted by Idaho
    so if bolvar is on fire how is he in the frozen throne shouldnt it melt cause hes on fire and fire is hot so the frozen throne which is made of ice and is cold shouldnt it melt
    Apparently Physics applies where we are cows that become chickens then becomes cats then do you /kill and /lololololol.....yep. ^^
    Quote Originally Posted by SPF18
    If Bolvar turns out to be a dragon, I'll put a pancake on my face and wave at traffic for 10 minutes.
    God, if you can hear me, make it to be a dragon...
    Quote Originally Posted by Spectro
    dude where have you been? we´ve porn streaming websites now!

  10. #50
    Deleted
    You need to re-fetch your XP every time your OnEvent runs. Also, use locals.

  11. #51
    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:
    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)
    As far as the weird side effect you are getting, I have no idea lol.

    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.

  12. #52
    Deleted
    Quote Originally Posted by Pwnzorz View Post
    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:
    <snip>
    Lua is case sensitive. Your code would just produce enormous amounts of errors.

  13. #53
    High Overlord Qelkhandras's Avatar
    10+ Year Old Account
    Join Date
    Mar 2010
    Location
    beneath your bed, so, don´t troll or i´ll notice
    Posts
    148
    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.....
    Quote Originally Posted by Idaho
    so if bolvar is on fire how is he in the frozen throne shouldnt it melt cause hes on fire and fire is hot so the frozen throne which is made of ice and is cold shouldnt it melt
    Apparently Physics applies where we are cows that become chickens then becomes cats then do you /kill and /lololololol.....yep. ^^
    Quote Originally Posted by SPF18
    If Bolvar turns out to be a dragon, I'll put a pancake on my face and wave at traffic for 10 minutes.
    God, if you can hear me, make it to be a dragon...
    Quote Originally Posted by Spectro
    dude where have you been? we´ve porn streaming websites now!

  14. #54
    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.

  15. #55
    Deleted
    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)
    would be more efficient.

  16. #56
    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.

  17. #57
    Deleted
    My hello world script isn't working:

    Code:
    local f = CreateFrame("Frame")
    f:EventFrame:RegisterEvent("PLAYER_LOGIN")
    f:SetScript("OnEvent", function(self,event,...)
         	ChatFrame1:AddMessage('WhyHelloThar')
    end)
    So I understand it should do /say WhyHelloThar when I login.
    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:

    Code:
    local function print_f(arguments)
    	--do stuff
    end
    Would be great to give an example.

    Code:
    local EventFrame = CreateFrame("Frame")
    EventFrame:RegisterEvent("PLAYER_LOGIN")
    EventFrame:SetScript("OnEvent", function(self,event,...) 
         	ChatFrame1:AddMessage('WhyHelloThar ".. UnitName("Player"))
    end)
    The "Player" needs to be renamed in a specific name?

    If you could give a concrete example for my addon with the hiding stuff.
    Thanks

  18. #58
    Quote Originally Posted by Tangent View Post
    Theres a Visual studio based wow addon creator called "Addon Studio". It lets you create the windows and menus in a visual way such as with visual basic and similar languages. Has all Lua built in to it for help with auto correction and things like that. Auto generates TOC and things like that I believe also.
    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.

  19. #59
    Deleted
    Quote Originally Posted by Muruguru View Post
    My hello world script isn't working:

    <snip>

    If you could give a concrete example for my addon with the hiding stuff.
    Thanks
    Your code won't /say, it will print it to the first chat frame.
    Your error is in line 2:
    Code:
    f:EventFrame:RegisterEvent("PLAYER_LOGIN")
    That should be
    Code:
    f:RegisterEvent("PLAYER_LOGIN")

  20. #60
    Deleted
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •