1. #1

    Help needed by integrating two scripts into one.

    Greetings,

    This script works as standalone lua file perfectly but when i integrate it with my other settings i get errors i wonder if anyone could help me out fixing this.

    I want to get this script:
    Code:
    local trinkets = {} 
    local events = CreateFrame("Frame")
    function events:ADDON_LOADED(addonName)
        if addonName ~= "Blizzard_ArenaUI" then
            return
        end
    
        -- ArenaEnemyFrame1:ClearAllPoints()
        -- ArenaEnemyFrame1:SetPoint("TOPRIGHT", UIParent, -189, -200)
        -- ArenaEnemyFrames:SetScale(1.3)
    
        local arenaFrame, trinket
        for i = 1, MAX_ARENA_ENEMIES do
            arenaFrame = "ArenaEnemyFrame"..i
            trinket = CreateFrame("Cooldown", arenaFrame.."Trinket", ArenaEnemyFrames)
            trinket:SetPoint("TOPRIGHT", arenaFrame, 32, -6)
            trinket:SetSize(24, 24)
            trinket.icon = trinket:CreateTexture(nil, "BACKGROUND")
            trinket.icon:SetAllPoints()
            trinket.icon:SetTexture("Interface\\Icons\\inv_jewelry_trinketpvp_01")
            trinket:Hide()
            trinkets["arena"..i] = trinket
        end
    
        self:UnregisterEvent("ADDON_LOADED")
    end
    
    function events:UNIT_SPELLCAST_SUCCEEDED(unitID, spell, rank, lineID, spellID)
        if not trinkets[unitID] then
            return
        end
        if spellID == 59752 or spellID == 42292 then
            CooldownFrame_SetTimer(trinkets[unitID], GetTime(), 120, 1)
            SendChatMessage("Trinket used by: "..GetUnitName(unitID, true), "PARTY")
        elseif spellID == 7744 then
            CooldownFrame_SetTimer(trinkets[unitID], GetTime(), 30, 1)
            SendChatMessage("WotF used by: "..GetUnitName(unitID, true), "PARTY")
        end
    end
    
    function events:PLAYER_ENTERING_WORLD()
        local _, instanceType = IsInInstance()
        if instanceType == "arena" then
            self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
        elseif self:IsEventRegistered("UNIT_SPELLCAST_SUCCEEDED") then
            self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
            for _, trinket in pairs(trinkets) do
                trinket:SetCooldown(0, 0)
                trinket:Hide()
            end
        end
    end
     
    SLASH_TESTAEF1 = "/testaef"
    SlashCmdList["TESTAEF"] = function(msg, editBox)
        if not IsAddOnLoaded("Blizzard_ArenaUI") then
            LoadAddOn("Blizzard_ArenaUI")
        end
    
        ArenaEnemyFrames:Show()
        local arenaFrame
        for i = 1, MAX_ARENA_ENEMIES do
            arenaFrame = _G["ArenaEnemyFrame"..i]
            arenaFrame.classPortrait:SetTexture("Interface\\TargetingFrame\\UI-Classes-Circles")
            arenaFrame.classPortrait:SetTexCoord(unpack(CLASS_ICON_TCOORDS["WARRIOR"]))
            arenaFrame.name:SetText("Dispelme")
            arenaFrame:Show()
            CooldownFrame_SetTimer(trinkets["arena"..i], GetTime(), 120, 1)
        end
    end
    
    events:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
    events:RegisterEvent("ADDON_LOADED")
    events:RegisterEvent("PLAYER_ENTERING_WORLD")
    Into this script:
    Code:
    local frame = CreateFrame("FRAME", "AwZ")
    frame:RegisterEvent("PLAYER_LOGIN")
    frame:RegisterEvent("PLAYER_ENTERING_WORLD")
    local function eventHandler(self, event, ...)
    
    -- Arena Frames --
    
    local ARF = true
    if ARF == true then
            LoadAddOn("Blizzard_ArenaUI")
    
            ArenaEnemyFrame1:ClearAllPoints()
            ArenaEnemyFrame1:SetPoint("RIGHT", -295, -230)
            ArenaEnemyFrame2:ClearAllPoints()
            ArenaEnemyFrame2:SetPoint("RIGHT", -295, -178)
            ArenaEnemyFrame3:ClearAllPoints()
            ArenaEnemyFrame3:SetPoint("RIGHT", -295, -126)
            ArenaEnemyFrame4:ClearAllPoints()
            ArenaEnemyFrame4:SetPoint("RIGHT", -295, -74)
            ArenaEnemyFrame5:ClearAllPoints()
            ArenaEnemyFrame5:SetPoint("RIGHT", -295, -22)
    end
    
    -- Class Colors --
    
    local CLC = true
    if CLC == true then
    	local UnitIsPlayer, UnitIsConnected, UnitClass, RAID_CLASS_COLORS =
    	UnitIsPlayer, UnitIsConnected, UnitClass, RAID_CLASS_COLORS
    	local _, class, c
    
    	local function colour(statusbar, unit)
    	if UnitIsPlayer(unit) and UnitIsConnected(unit) and unit == statusbar.unit and UnitClass(unit) then
    	_, class = UnitClass(unit)
    	c = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[class] or RAID_CLASS_COLORS[class]
    	statusbar:SetStatusBarColor(c.r, c.g, c.B)
    	end
    	end
    
    	hooksecurefunc("UnitFrameHealthBar_Update", colour)
    	hooksecurefunc("HealthBar_OnValueChanged", function(self)
    	colour(self, self.unit)
    	end)
    
    	local sb = _G.GameTooltipStatusBar
    	local addon = CreateFrame("Frame", "StatusColour")
    	addon:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
    	addon:SetScript("OnEvent", function()
    	colour(sb, "mouseover")
    	end) 
    end
    
    -- Class Icons --
    
    local CLI = true
    if CLI == true then
    	hooksecurefunc("UnitFramePortrait_Update",function(self)
    	if self.portrait then
    	if UnitIsPlayer(self.unit) then			
    	local t = CLASS_ICON_TCOORDS[select(2,UnitClass(self.unit))]
    	if t then
    	self.portrait:SetTexture("Interface\\TargetingFrame\\UI-Classes-Circles")
    	self.portrait:SetTexCoord(unpack(t))
            end
    	else
    	self.portrait:SetTexCoord(0,1,0,1)
    	end
    	end
    	end)
    end
    
    -- Focus Frame --
    
    local FOF = true
    if FOF == true then
            FocusFrame:ClearAllPoints()
            FocusFrame:SetPoint("RIGHT", -380, -25)
            FocusFrameToT:ClearAllPoints()
            FocusFrameToT:SetPoint("RIGHT", "FocusFrame", -35, -37)
    end
    
    -- Out of Range --
    
    local OOR = true
    if OOR == true then
    
            hooksecurefunc("ActionButton_OnEvent",function(self, event, ...)
            if ( event == "PLAYER_TARGET_CHANGED" ) then                        
            self.newTimer = self.rangeTimer               
            end        
            end)        
    
            hooksecurefunc("ActionButton_UpdateUsable",function(self)                
            local icon = _G[self:GetName().."Icon"]                
            local valid = IsActionInRange(self.action)                
            if ( valid == 0 ) then                        
            icon:SetVertexColor(1.0, 0.1, 0.1)                
            end        
            end)        
    
            hooksecurefunc("ActionButton_OnUpdate",function(self, elapsed)                
            local rangeTimer = self.newTimer                
            if ( rangeTimer ) then                        
            rangeTimer = rangeTimer - elapsed                         
            if ( rangeTimer <= 0 ) then                                
            ActionButton_UpdateUsable(self)                                
            rangeTimer = TOOLTIP_UPDATE_TIME                        
            end                        
            self.newTimer = rangeTimer               
            end        
            end)
    end
    
    -- Party Frames --
    
    local PAF = true
    if PAF == true then
            PartyMemberFrame1:ClearAllPoints()
            PartyMemberFrame1:SetPoint("LEFT", 370, 95)
            PartyMemberFrame2:ClearAllPoints()
            PartyMemberFrame2:SetPoint("LEFT", 370, 158)
            PartyMemberFrame3:ClearAllPoints()
            PartyMemberFrame3:SetPoint("LEFT", 370, 221)
            PartyMemberFrame4:ClearAllPoints()
            PartyMemberFrame4:SetPoint("LEFT", 370, 284)
    end
    
    -- Pet Frame --
    
    local PEF = true
    if PEF == true then
            PetFrame:ClearAllPoints()
            PetFrame:SetPoint("LEFT", 60, 59)
    end
    
    -- Player Frame --
    
    local PLF = true
    if PLF == true then
            PlayerFrame:ClearAllPoints()
            PlayerFrame:SetPoint("LEFT", 380, -25)
    end
    
    -- Target Frame --
    
    local TAF = true
    if TAF == true then
            TargetFrame:ClearAllPoints() 
            TargetFrame:SetPoint("LEFT", 480, -70)
            TargetFrameToT:ClearAllPoints() 
            TargetFrameToT:SetPoint("RIGHT", "TargetFrame", -35, -37)
    end
    end
    frame:SetScript("OnEvent", eventHandler)
    I remind again, both scripts works perfectly as standalone lua files i just want to make them all into one file so anyone who could help with this i'll be gladful.

    Note: Errors arrive when i /testaef

    Thanks ahead.

  2. #2
    An error message would be appreciated. What kind of error are we talking about?
    UI & AddOns expert | Interface & Macros moderator - My work

  3. #3
    Quote Originally Posted by Treeston View Post
    An error message would be appreciated. What kind of error are we talking about?
    Errors are:
    Code:
    Message: Interface\FrameXML\Cooldown.lua:4: attempt to index local 'self' (a nil value)
    Time: 02/14/12 09:17:58
    Count: 2
    Stack: [C]: ?
    Interface\FrameXML\Cooldown.lua:4: in function `CooldownFrame_SetTimer'
    Interface\AddOns\AwZ\AwZ.lua:212: in function `?'
    Interface\FrameXML\ChatFrame.lua:4293: in function `ChatEdit_ParseText'
    Interface\FrameXML\ChatFrame.lua:3992: in function `ChatEdit_SendText'
    Interface\FrameXML\ChatFrame.lua:4031: in function `ChatEdit_OnEnterPressed'
    [string "*:OnEnterPressed"]:1: in function <[string "*:OnEnterPressed"]:1>
    
    Locals:

  4. #4
    Second script calls LoadAddOn("Blizzard_ArenaUI") - the ADDON_LOADED event hook of the first script is not yet in place when this happens, thus it never fires - the table 'trinkets' is never populated, thus causing a nil error when you test (passing trinkets["arena1"] to CooldownFrame_SetTimer).

    To resolve this, try adding:
    Code:
    if IsAddOnLoaded("Blizzard_ArenaUI") then events:ADDON_LOADED("Blizzard_ArenaUI") end
    right after the 'events:SetScript("OnEvent",...)' call.
    UI & AddOns expert | Interface & Macros moderator - My work

  5. #5
    Quote Originally Posted by Treeston View Post
    Second script calls LoadAddOn("Blizzard_ArenaUI") - the ADDON_LOADED event hook of the first script is not yet in place when this happens, thus it never fires - the table 'trinkets' is never populated, thus causing a nil error when you test (passing trinkets["arena1"] to CooldownFrame_SetTimer).

    To resolve this, try adding:
    Code:
    if IsAddOnLoaded("Blizzard_ArenaUI") then events:ADDON_LOADED("Blizzard_ArenaUI") end
    right after the 'events:SetScript("OnEvent",...)' call.


    Worked flawlessly, many thanks to you Treeston.
    Last edited by Ashmedy; 2012-02-15 at 09:51 AM.

Posting Permissions

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