Thread Tools Display Modes
Prev Previous Post   Next Post Next
12-05-10, 05:27 PM   #1
strickland
A Cyclonian
Join Date: Apr 2007
Posts: 40
a combattext lua (no error, but smthng not working)

hi guys, I'm not very good in lua, but what I did to this code is, I've added from another combattext to this combattext, something that I really like. its just a simple on certain buff I get, it puts a MSG in my screen and plays a sound, here's the full code , all credit goes to 1) wild for his code, and 2) evl for the thing that I copied into wild's.


Code:
local addonName, ns = ...

local module = {}
module.name = "CombatText"
module.Init = function()
	if not SCDB.modules[module.name] then return end
	if SCDB[module.name] == nil then SCDB[module.name] = {} end
	if SCDB[module.name]["StartX"] == nil then SCDB[module.name]["StartX"] = 305 end
	if SCDB[module.name]["EndX"] == nil then SCDB[module.name]["EndX"] = 305 end
	if SCDB[module.name]["StartY"] == nil then SCDB[module.name]["StartY"] = 550 end
	if SCDB[module.name]["EndY"] == nil then SCDB[module.name]["EndY"] = 300 end
	if SCDB[module.name]["Raid announce"] == nil then SCDB[module.name]["Raid announce"] = false end
	if SCDB[module.name]["Party announce"] == nil then SCDB[module.name]["Party announce"] = false end
	if SCDB[module.name]["Yell announce"] == nil then SCDB[module.name]["Yell announce"] = true end
	if SCDB[module.name]["Say announce"] == nil then SCDB[module.name]["Say announce"] = false end
	if SCDB[module.name]["Play sounds"] == nil then SCDB[module.name]["Play sounds"] = true end
	local opts = SCDB[module.name]

	local lastKillTime = 0
	local killingStreak = 0
	local multiKill = 0
	local MULTI_KILL_HOLD_TIME = 11.5
	local bit_band = bit.band
	local bit_bor = bit.bor
    local pendingSound

    local spreeSounds = {
        [3] = "Killing_Spree",
        [4] = "Dominating",
        [5] = "Mega_Kill",
        [6] = "Unstoppable",
        [7] = "Wicked_Sick",
        [8] = "Monster_Kill",
        [9] = "Ludicrous_Kill",
        [10] = "God_Like",
        [11] = "Holy_****"
    }

    local multiSounds = {
        [2] = "Double_Kill",
        [3] = "Triple_Kill",
    }
    
    local path = "Interface\\AddOns\\SuperClassic\\media\\sounds\\%s.mp3"
    
	local function hasFlag(flags, flag)
		return bit_band(flags, flag) == flag
	end

    -- by Evl
    local playSounds = function()
        local multiFileName = multiSounds[math.min(3, multiKill)]
        local spreeFileName = spreeSounds[math.min(11, killingStreak)]

        if multiFileName then
            PlaySoundFile(string.format(path, multiFileName))
        end

        if spreeFileName then
            local spreeFilePath = string.format(path, spreeFileName)

            if not multiFileName then
                PlaySoundFile(spreeFilePath)
            else
                pendingSound = spreeFilePath
            end
        end
    end

	local extraCombatText = CreateFrame("Frame")
	extraCombatText:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
	extraCombatText:RegisterEvent("PLAYER_DEAD")
	extraCombatText:RegisterEvent("ADDON_LOADED")
	extraCombatText:SetScript("OnEvent", function(self, event, ...)
		if event == "COMBAT_LOG_EVENT_UNFILTERED" then
			timestamp, eventType, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags = ...
			-- Killing blows
			if eventType == "PARTY_KILL" and hasFlag(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) and hasFlag(destFlags, COMBATLOG_OBJECT_TYPE_PLAYER) then
				if COMBAT_TEXT_TYPE_INFO then
					if SCDB[module.name]["Raid announce"] then
						SendChatMessage("Killing Blow! (" .. destName .. ")", "RAID")
					end
					if SCDB[module.name]["Party announce"] then
						CombatText_AddMessage("Killing Blow! (" .. destName .. ")", COMBAT_TEXT_SCROLL_FUNCTION, .9, .2, .2, "crit", nil)
					end
					if SCDB[module.name]["Yell announce"] then
						SendChatMessage("Killing Blow! (" .. destName .. ")", "YELL")
					end
					if SCDB[module.name]["Say announce"] then
						SendChatMessage("Killing Blow! (" .. destName .. ")", "SAY")
					end
				end

				local now = GetTime()
		
				if lastKillTime + MULTI_KILL_HOLD_TIME > now then
					multiKill = multiKill + 1
				else
					multiKill = 1
				end
		
				lastKillTime = now
				killingStreak = killingStreak + 1
                if opts["Play sounds"] then
                    playSounds()
                end
                
			-- Interrupts
			elseif eventType == "SPELL_INTERRUPT" and hasFlag(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) then
				local extraSpellID, extraSpellName, extraSpellSchool = select(12, ...)
				if SCDB[module.name]["Raid announce"] then
					SendChatMessage(format("%s Interrupted!", GetSpellLink(extraSpellID)), "RAID")
				end
				if SCDB[module.name]["Party announce"] then
					CombatText_AddMessage(format("%s Interrupted!", extraSpellName), COMBAT_TEXT_SCROLL_FUNCTION, .1, .1, 1, nil, nil)
				end
				if SCDB[module.name]["Yell announce"] then
					SendChatMessage(format("%s Interrupted!", GetSpellLink(extraSpellID)), "YELL")
				end
				if SCDB[module.name]["Say announce"] then
					SendChatMessage(format("%s Interrupted!", GetSpellLink(extraSpellID)), "SAY")
				end
			end
			if eventType == "SPELL_AURA_APPLIED" and hasFlag(destFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) then
				local extraSpellID, extraSpellName = ...
		
				-- Clearcasting
				if extraSpellName == "Shield Wall" then
					CombatText_AddMessage("WALL UP!", COMBAT_TEXT_SCROLL_FUNCTION, .7, .7, 1, "crit", nil)
					PlaySoundFile("Interface\\AddOns\\SuperClassic\\media\\sounds\\sohelp02.mp3")
				elseif extraSpellName == "Barkskin" then
					CombatText_AddMessage("Barkskinned!", COMBAT_TEXT_SCROLL_FUNCTION, .7, .7, 1, "crit", nil)
					PlaySoundFile("Interface\\AddOns\\SuperClassic\\media\\sounds\\sohelp02.mp3")
				elseif extraSpellName == "Wrath of Elune" then
					--CombatText_AddMessage("Wrath of Elune!", COMBAT_TEXT_SCROLL_FUNCTION, 255, 204, 0, nil, nil)
					PlaySoundFile("Interface\\AddOns\\SuperClassic\\media\\sounds\\groovy02.mp3")
				elseif extraSpellName =="Shooting Stars" then
					--CombatText_AddMessage("Shooting Stars!", COMBAT_TEXT_SCROLL_FUNCTION, 255, 0, 255, nil, nil)
					PlaySoundFile("Interface\\AddOns\\SuperClassic\\media\\sounds\\groovy02.mp3")
				elseif extraSpellName == "Taste for Blood" then
					CombatText_AddMessage("Overpower!", COMBAT_TEXT_SCROLL_FUNCTION, 255, 204, 0, nil, nil)
					PlaySoundFile("Interface\\AddOns\\SuperClassic\\media\\sounds\\groovy02.mp3")
				elseif extraSpellName == "Nature's Grace" then
					--CombatText_AddMessage("NG!", COMBAT_TEXT_SCROLL_FUNCTION, .7, 0.7, 1, "crit", nil)
					PlaySoundFile("Interface\\AddOns\\SuperClassic\\media\\sounds\\RockBiterImpact.mp3")
				-- Slam!
				elseif extraSpellName == "Slam!" then
					CombatText_AddMessage("Slam!", COMBAT_TEXT_SCROLL_FUNCTION, .7, .7, 1, "crit", nil)
					PlaySoundFile("Interface\\AddOns\\SuperClassic\\media\\sounds\\groovy02.mp3")
				elseif extraSpellName == "Sword and Board!" then
					CombatText_AddMessage("Sword and Board!", COMBAT_TEXT_SCROLL_FUNCTION, .7, .7, 1, "crit", nil)
					PlaySoundFile("Interface\\AddOns\\SuperClassic\\media\\sounds\\groovy02.mp3")
				elseif extraSpellName == "Shield Block" then
					CombatText_AddMessage("BLOCK THAT ****!", COMBAT_TEXT_SCROLL_FUNCTION, .7, .7, 1, "crit", nil)
					PlaySoundFile("Interface\\AddOns\\SuperClassic\\media\\sounds\\sohelp02.mp3")
				end
		elseif event == "PLAYER_DEAD" then
			killingStreak = 0
		end
	end
end)

    extraCombatText:SetScript("OnUpdate", function(self, elapsed)
        if self.lastUpdate == nil then self.lastUpdate = 0 end
        self.lastUpdate = self.lastUpdate + elapsed
        if self.lastUpdate > 2 then
            self.lastUpdate = 0
            if pendingSound then
                PlaySoundFile(pendingSound)
                pendingSound = nil
            end
        end
    end)
	
	--COMBAT_TEXT_TYPE_INFO["ENTERING_COMBAT"] = { r = 0.1, g = 0.1, b = 1 }
	--COMBAT_TEXT_TYPE_INFO["LEAVING_COMBAT"] = { r = 0.1, g = 0.1, b = 1 }
	--COMBAT_TEXT_TYPE_INFO["COMBO_POINTS"] = { r = 0.7, g = 0.7, b = 1 }

	COMBAT_TEXT_TYPE_INFO["ENTERING_COMBAT"].r = 0.1
	COMBAT_TEXT_TYPE_INFO["ENTERING_COMBAT"].g = 0.1
	COMBAT_TEXT_TYPE_INFO["ENTERING_COMBAT"].b = 1
	COMBAT_TEXT_TYPE_INFO["LEAVING_COMBAT"].r = 0.1
	COMBAT_TEXT_TYPE_INFO["LEAVING_COMBAT"].g = 0.1
	COMBAT_TEXT_TYPE_INFO["LEAVING_COMBAT"].b = 1
	COMBAT_TEXT_TYPE_INFO["COMBO_POINTS"].r = 0.7
	COMBAT_TEXT_TYPE_INFO["COMBO_POINTS"].g = 0.7
	COMBAT_TEXT_TYPE_INFO["COMBO_POINTS"].b = 1

	
	COMBAT_TEXT_DEFLECT = "Deflect"
	COMBAT_TEXT_REFLECT = "Reflect"
	COMBAT_TEXT_IMMUNE = "Immune"
	COMBAT_TEXT_RESIST = "Resist"
	COMBAT_TEXT_ABSORB = "Absorb"
	COMBAT_TEXT_BLOCK = "Block"
	COMBAT_TEXT_DODGE = "Dodge"
	COMBAT_TEXT_PARRY = "Parry"
	COMBAT_TEXT_EVADE = "Evade"
	COMBAT_TEXT_MISS = "Miss"

	DEFLECT = "Deflect"
	REFLECT = "Reflect"
	IMMUNE = "Immune"
	RESIST = "Resist"
	ABSORB = "Absorb"
	BLOCK = "Block"
	DODGE = "Dodge"
	PARRY = "Parry"
	EVADE = "Evade"
	MISS = "Miss"

	BLOCK_TRAILER = "(Block %d)"
	ABSORB_TRAILER = "(Absorb %d)"
	RESIST_TRAILER = "(Resist %d)"

	ENTERING_COMBAT = "+COMBAT+"
	LEAVING_COMBAT = "-COMBAT-"
	COMBAT_TEXT_SCROLLSPEED = 2
	
	HEALTH_LOW = "Oh ****!"
	MANA_LOW = "MANA LOW!"
	
	hooksecurefunc("CombatText_UpdateDisplayedMessages", function ()
		COMBAT_TEXT_LOCATIONS = {
			startX  = opts.StartX,
			startY = opts.StartY * COMBAT_TEXT_Y_SCALE,
			endX = opts.EndX,
			endY = opts.EndY * COMBAT_TEXT_Y_SCALE
		}
	end)

end
tinsert(SuperClassic.modules, module) -- finish him!

bear in mind that I get no lua error at all, and everything else working fine, except this COLORED thing which I hilighted for you, its not working at all, and no error at all.

no sound, no msg, and the sound is there in the path.

help would be nice, I really couldn't figure out why its not working for me
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » a combattext lua (no error, but smthng not working)


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off