Loading...

Spell Announcement plugin

#1
I found this piece of code (that tells when someone is casting lets say fear and on what target) when I looked at my very old edits back in probably wotlk/cata days and thought that I would see if I could get it working for bfa, im not getting any errors but im not getting any announcements either, if anyone have some time to look at the code that would be cool

Code: Select all

local T, C, L = Tukui:unpack()

local FONT = "Fonts\\ARIALN.TTF"
local FONTSIZE = 18
local POINT = "TOP"
local X = 0
local Y = -300
local sound = false

-- List of spells
local spells = {
	[118] = true, 			-- Polymorph: Sheep
	[61305] = true, 		-- Polymorph: Cat
	[28272] = true, 		-- Polymorph: Pig
	[61721] = true, 		-- Polymorph: Rabbit
	[61780] = true, 		-- Polymorph: Turkey
	[28271] = true, 		-- Polymorph: Turtle
	[5782] = true, 			-- Fear
	[33786] = true, 		-- Cyclone
	[51514] = true, 		-- Hex
	[20066] = true, 		-- Repentance
}

-- Spell Announcement
if Tukui then
	local C = select(2, unpack(Tukui))
	FONT = C.Fonts.UnitFrameFont
end

-- The Main Frame
local frame = CreateFrame("MessageFrame", nil, UIParent)
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
frame:SetPoint("LEFT")
frame:SetPoint("RIGHT")
frame:SetHeight(36)
frame:SetInsertMode("TOP")
frame:SetFrameStrata("HIGH")
frame:SetTimeVisible(1)
frame:SetFadeDuration(3)
frame:SetFont(FONT, FONTSIZE, "OUTLINE")
frame:SetPoint(POINT, X, Y)

local function Message(caster, spell, target, template, spellID)
	if target then
		frame:AddMessage(format(template, "|cffff0000"..caster.."|r", "|cffD7DC23"..spell.."|r", nil, "|cff00ff00"..target.."|r"))
	else
		frame:AddMessage(format(template, "|cffff0000"..caster.."|r", "|cffD7DC23"..spell.."|r", nil, nil))
	end
end

local Update = function(self, event, ...)
	if event == "COMBAT_LOG_EVENT_UNFILTERED" then
		local timestamp, eventType, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID, spellName = ...
		local check = spells[spellID]
		
		if check and (eventType == "SPELL_CAST_SUCCESS" or eventType == "SPELL_CAST_START") then
			if sourceGUID and (bit.band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE) then
				local guid = sourceGUID
				local class, classFilename, race, raceFilename, sex, name, unknown = GetPlayerInfoByGUID(guid)
				
				if check then
					local template
					
					-- Define A MSG To Print According To Which Event
					if eventType == "SPELL_CAST_SUCCESS" then
						if sourceName and destName then
							template = ACTION_SPELL_CAST_SUCCESS_FULL_TEXT
						else
							template = ACTION_SPELL_CAST_SUCCESS_FULL_TEXT_NO_DEST
						end					
					else
						if sourceName and destName then
							template = ACTION_SPELL_CAST_START_FULL_TEXT
						else
							template = ACTION_SPELL_CAST_START_FULL_TEXT_NO_DEST
						end
					end
					
					-- Sent Screen MSG
					Message(name, spellName, destName, template, spellID)
				end
			end
		end
	end
end

-- Look, Activate If BG/Arena And Print On Screen
frame:SetScript("OnEvent", Update)

Spell Announcement plugin

#4
Hi Innervasion

I found your post just this week, and I wrote a plugin based on the posted code to add in my own tukui edit. And since the topic is not marked as resolved, even though it's from almost 6 months ago, I'll post my version here.

I would appreciate any feedback about it, because i do not play pvp very much.

Code: Select all

local T, C, L = Tukui:unpack()

----------------------------------------------------------------
-- PvP Alert
-- Author: Unknown
-- Editor: Luaerror
-- Reference: https://www.tukui.org/forum/viewtopic.php?f=10&t=3142 on January 23th, 2019
----------------------------------------------------------------
if (not C.PvPAlert.Enable) then return end

local Font, FontSize, FontStyle = C.Medias.Font, 18, "THINOUTLINE"
local format = string.format
local band = bit.band
local bor = bit.bor

local PARTY_MEMBER_MASK = bit.bor(COMBATLOG_OBJECT_TYPE_PLAYER, COMBATLOG_OBJECT_REACTION_FRIENDLY, COMBATLOG_OBJECT_AFFILIATION_PARTY)
local ENEMY_PLAYER_MASK = bit.bor(COMBATLOG_OBJECT_TYPE_PLAYER, COMBATLOG_OBJECT_REACTION_HOSTILE)

local playerGUID = UnitGUID("player")
local chatType = "SAY"

local SpellList = {
    -- Mage
    [118] = true,                   -- Polymorph: Sheep
    [28271] = true,                 -- Polymorph: Turtle
    [28272] = true,                 -- Polymorph: Pig
    [61305] = true,                 -- Polymorph: Black Cat
    [61721] = true,                 -- Polymorph: Rabbit
    [61780] = true,                 -- Polymorph: Turkey
    [128819] = true,                -- Polymorph: Porcupine
    [161353] = true,                -- Polymorph: Polar Bear Cub
    [161354] = true,                -- Polymorph: Monkey
    [161355] = true,                -- Polymorph: Penguin
    [161372] = true,                -- Polymorph: Peacock
    [277787] = true,                -- Polymorph: Direhorn
    [277792] = true,                -- Polymorph: Bumblebee

    -- Shaman
    [51514] = true,                 -- Hex: Frog
    [210873] = true,                -- Hex: Compy
    [211004] = true,                -- Hex: Spider
    [211010] = true,                -- Hex: Snake
    [211015] = true,                -- Hex: Cockroach
    [269352] = true,                -- Hex: Skeletal Hatchling
    [277778] = true,                -- Hex: Zandalari Tendonripper
    [277784] = true,                -- Hex: Wicker Mongrel

    -- Warlock
    [5782] = true, 			        -- Fear

    -- Druid
	[33786] = true, 		        -- Cyclone

    -- Paladin
    [20066] = true, 		        -- Repentance

    -- Priest
    [605] = true,                   -- Mind Control
}

local CombatEvents = {
    SPELL_CAST_START = true,
    SPELL_CAST_SUCCESS = true,
}

----------------------------------------------------------------
-- Functions
----------------------------------------------------------------
-- compare unit flag mask
local function CombatLog_Mask(unitFlags, Mask)
    return (band(unitFlags, Mask) == Mask)
end

-- create/send alert message
local function Message(self, caster, target, template, spellID)
    local spellIcon = GetSpellTexture(spellID)
    local spellLink = GetSpellLink(spellID)

    if (caster) then caster = "|cffff0000" .. caster .. "|r" end
    if (target) then target = "|cff00ff00" .. target .. "|r" end

    local msg = format(template, caster, spell, nil, target)

    -- send message to message frame
    self:AddMessage(msg)

    -- send message to chat, if in group
    if (chatType) then
        SendChatMessage(msg, chatType)
    end
end

----------------------------------------------------------------
-- Events
----------------------------------------------------------------
local f = CreateFrame("MessageFrame", nil, UIParent)
f:SetPoint("LEFT")
f:SetPoint("RIGHT")
f:SetPoint("TOP", UIParent, "TOP", 0, -230)
f:SetHeight(1.5 * FontSize)
f:SetFrameStrata("HIGH")
f:SetFont(Font, FontSize, FontStyle)
f:SetInsertMode("TOP")
f:SetTimeVisible(1)
f:SetFadeDuration(3)

f:RegisterEvent("PLAYER_LOGIN")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterEvent("ZONE_CHANGED_NEW_AREA")
f:SetScript("OnEvent", function(self, event, ...)
    -- call one of the functions below
    self[event](self, ...)
end)

function f:Initialize()
    local inInstance, instanceType = IsInInstance()
    if (instanceType and (instanceType == "pvp" or instanceType == "arena")) then
        if (instanceType == "arena") then
            chatType = "ARENA"
        else
            if (IsInGroup(LE_PARTY_CATEGORY_HOME)) then
                chatType = "PARTY"
            else
                chatType = nil
            end
        end
        self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    else
        self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    end
end

function f:PLAYER_LOGIN()
    playerGUID = UnitGUID("player")
end

function f:PLAYER_ENTERING_WORLD()
    self:Initialize()
end

function f:ZONE_CHANGED_NEW_AREA()
    self:Initialize()
end

function f:COMBAT_LOG_EVENT_UNFILTERED()
    local timestamp, eventType, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags,
    destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()

    -- filter combat events type
    if (not CombatEvents[eventType]) then return end

    -- check if caster is a hostile player
    if (not CombatLog_Mask(sourceFlags, ENEMY_PLAYER_MASK)) then return end

    -- check if target is a party member or player
    if (not CombatLog_Mask(destFlags, PARTY_MEMBER_MASK) or destGUID ~= playerGUID) then return end

    local spellID, spellName, spellSchool = select(12, CombatLogGetCurrentEventInfo())

    if (SpellList[spellID]) then
        local template = nil

        if (eventType == "SPELL_CAST_START") then
            if (sourceName and destName) then
                template = ACTION_SPELL_CAST_START_FULL_TEXT
            elseif (sourceName) then
                template = ACTION_SPELL_CAST_START_FULL_TEXT_NO_DEST
            elseif (destName) then
                template = ACTION_SPELL_CAST_START_FULL_TEXT_NO_SOURCE
            end	
        elseif (eventType == "SPELL_CAST_SUCCESS") then
            if (sourceName and destName) then
                template = ACTION_SPELL_CAST_SUCCESS_FULL_TEXT
            elseif (sourceName) then
                template = ACTION_SPELL_CAST_SUCCESS_FULL_TEXT_NO_DEST
            elseif (destName) then
                template = ACTION_SPELL_CAST_SUCCESS_FULL_TEXT_NO_SOURCE
            end	
        end

        -- format message
        Message(self, sourceName, destName, template, spellID)
    end
end
Last edited by Luaerror on Fri Jan 25, 2019 5:29 pm, edited 1 time in total.

Spell Announcement plugin

#6
I forgot two things.
First, I'm not sure if the spell list is complete with all crowd-control spells (not instant).

Second, I let a mistake pass, just change this function:

Code: Select all

function f:Initialize()
    local inInstance, instanceType = IsInInstance()
    if (instanceType and (instanceType == "pvp" or instanceType == "arena")) then
        if (instanceType == "arena") then
            chatType = "ARENA"
        else
            if (IsInGroup(LE_PARTY_CATEGORY_HOME)) then
                chatType = "PARTY"
            else
                chatType = nil
            end
        end
        self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    else
        self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    end
end

Spell Announcement plugin

#9
You might try changing the Startup routine test from:

If,IExists,"Zplugin:UIstate Plugin:Logo",

to:

If,IExists,"Zplugin:UIstate Plugin:Switch06",

So that the check is for the last switch of the interface.

Alternatively, use a memory block instead:

If,MemGetSize,NK_StartupMem,

and create the memblock at the very end of the script:

If,MemGetSize,NK_StartupMem,,MVarDef,NK_StartupMem,1,0

Image
:)

Who is online

Users browsing this forum: No registered users and 2 guests