The code I currently have is all over the place and will give you a headache. It's currently functional in my test environment (have not been able to test all bosses yet since I don't lead my raids until the weekend) but I'm starting over from scratch to try do it right.
This is what I have so far. Obviously it's not done, but this is the new direction I'm heading based on the feedback you guys have given.
Lua Code:
local bossNPCID = {
[55294] = true, -- Ultraxion
-- Madness of Deathwing... check combat log next time to see if there's any NPC that shows up regardless of what platform we start at.--
[56846] = true, -- Madness of Deathwing: Arm Tentacle
[56167] = true, -- Madness of Deathwing: Arm Tentacle
[56168] = true, -- Madness of Deathwing: Wing Tentacle (Need to check if there's a second NPCID during raid, only one listed on WoWhead.)
[56173] = true, -- Madness of Deathwing: Deathwing
----------------------------------------------------------------------------------------------------------------------------------------
[52530] = true, -- Alysrazor
[52409] = true, -- Ragnaros
[46753] = true, -- Al'akir
[33136] = true, -- Yogg-Saron: Guardian of Yogg-Saron
[60410] = true, -- Elegon
[36597] = true, -- The Lich King
[10184] = true, -- Onyxia
[16152] = true, -- Attumen the Huntsman
[19622] = true, -- Kael'thas Sunstrider
[28859] = true, -- Malygos
[28860] = true, -- Sartharion
[69712] = true, -- Ji-Kun
--TEST NPCIDS
[12129] = true,
--[[
[] = true,
[] = true,
[] = true,
[] = true,
[] = true,
[] = true,
[] = true,
[] = true,
]]
}
local events = CreateFrame("Frame")
events:RegisterEvent("PLAYER_ENTERING_WORLD")
events:RegisterEvent("PARTY_LEADER_CHANGED")
events:SetScript("OnEvent",function(self,event,...)
if event == "PLAYER_ENTERING_WORLD" or event == "PARTY_LEADER_CHANGED" then
local ininstance, instancetype = IsInInstance("player") -- check if player is in a raid and in an instance
local isgroupleader = UnitIsGroupLeader("player") -- check if player is raid leader
if ininstance == 1 and instancetype == "raid" and isgroupleader then -- if player is group leader in a raid and currently in an instance enable functionality
print("|cff00ff00Niketa's Mount Looter enabled!")
events:RegisterEvent("PLAYER_REGEN_DISABLED")
events:RegisterEvent("PARTY_LOOT_METHOD_CHANGED") --!!!!!!!!!!!!!!!!!! DON'T FORGET TO DISABLE THIS WHEN REVERTING LOOT SETTINGS!!!!!!!!!!!!!!
elseif ininstance == 1 and instancetype == "raid" and not isgroupleader then -- if player is in a raid and in instance but not group leader, "error" message
print("|cff00ff00Niketa's Mount Looter disabled: You need to be raid leader to use this addon.")
end
end
if event == "PLAYER_REGEN_DISABLED" then -- on entering combat, start looking at CLEU
events:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end
if event == "COMBAT_LOG_EVENT_UNFILTERED" and eventType ~= "SPELL_AURA_APPLIED" then
local _, _, _, sourceGUID, sourceName, _, _, destGUID, destName, _, _ = ...
local enemyNPCIDa = tonumber(strsub(sourceGUID, 6, 10), 16)
local enemyNPCIDb = tonumber(strsub(destGUID, 6, 10), 16)
if bossNPCID[enemyNPCIDa] or bossNPCID[enemyNPCIDb] then -- if enemy is in table then set loot and unregister CLEU
events:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
nmlmethod, nmlthreshold = GetLootMethod(), GetLootThreshold()
if nmlmethod == "master" and nmlthreshold ~= 4 then -- only set threshold if already master
print("no thresh")
SetLootThreshold(4)
elseif nmlmethod ~= "master" and nmlthreshold == 4 then -- only set method if already epic
print("no method")
SetLootMethod("master",UnitName("player"))
elseif nmlmethod ~= "master" and nmlthreshold ~= 4 then -- set both
print("no thresh or method")
nmlnodead = 1 -- set nil when reverting settings
nmlsetthreshold = 1 -- trigger PARTY_LOOT_METHOD_CHANGED to set to epic
SetLootMethod("master",UnitName("player"))
-- else do nothing
end
end
end
if event == "PARTY_LOOT_METHOD_CHANGED" and nmlsetthreshold == 1 then
nmlsetthreshold = nil
SetLootThreshold(4)
end
end)
Is this a step in the right direction or am I still way off?
(* I just realized I forgot to add in your suggestion about caching the NPCID so I don't keep calling local enemyNPCID. I don't really understand your code for that [as far as metatables go]; would you mind explaining so I actually understand what I'm writing [we don't want another issue like my local variables for CLEU, lol]? *)