Quantcast
a combattext lua (no error, but smthng not working) - WoWInterface
Thread Tools Display Modes
12-05-10, 05:27 PM   #1
strickland
An Aku'mai Servant
Join Date: Apr 2007
Posts: 38
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
12-05-10, 07:19 PM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,702
I see no function named "hasFlag", which is used in your piece of code.
  Reply With Quote
12-05-10, 07:26 PM   #3
strickland
An Aku'mai Servant
Join Date: Apr 2007
Posts: 38
Originally Posted by p3lim View Post
I see no function named "hasFlag", which is used in your piece of code.

thanks alot, I am not good in coding in all honesty I just put together two codes from two authers, is there an easy way to add this function, like one line or something , I know coders don't like these questions, hope i'm not troubling you, just want this to work and i'm all done
  Reply With Quote
12-05-10, 08:07 PM   #4
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,702
Originally Posted by strickland View Post
thanks alot, I am not good in coding in all honesty I just put together two codes from two authers, is there an easy way to add this function, like one line or something , I know coders don't like these questions, hope i'm not troubling you, just want this to work and i'm all done
Grab the function and stick it to the top of the file.
  Reply With Quote
12-05-10, 11:19 PM   #5
strickland
An Aku'mai Servant
Join Date: Apr 2007
Posts: 38
Originally Posted by p3lim View Post
Grab the function and stick it to the top of the file.
ok, ive tried my best , and put in the effort to try and make it work, went into evl's code to find the function you meant to put in the top of the file, found this.


Code:
 
function addon:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventType, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, ...)
I put that in the top of file, "No error" but also didn't work. and I looked over the other lines that has NoFlags word in it, all the things that has NoFlags in it, was in the current combattext i'm using. so I didn't add them because theyre already there.... sorry But you tell me to grab the function, and i'm not sure what is the function actually.
  Reply With Quote
12-06-10, 03:56 AM   #6
Wildbreath
A Cyclonian
 
Wildbreath's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 46
Hi, strick

local extraSpellID, extraSpellName = select(12, ...)

and please, use a spell ID's because a localization issues (if you want to send this code to others)
You can get it from wowhead (numbers in url, when you seeing a spell)
  Reply With Quote
12-06-10, 04:33 AM   #7
strickland
An Aku'mai Servant
Join Date: Apr 2007
Posts: 38
Originally Posted by Wildbreath View Post
Hi, strick

local extraSpellID, extraSpellName = select(12, ...)

and please, use a spell ID's because a localization issues (if you want to send this code to others)
You can get it from wowhead (numbers in url, when you seeing a spell)
Hi wild i love u ... thanks but i already guessed this and tried it yesterday and i also try it now to double sure, it didnt work also


EDIT: I'm still stuck into this, could someone nice help me too <3 hehe what am I missing

Last edited by strickland : 12-06-10 at 04:55 PM.
  Reply With Quote

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

Thread Tools
Display Modes

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