public
Last active

Custom script for oUF_NeavRaid that automatically positions and scales the raid frames based on spec and size of the raid

  • Download Gist
custom.lua
Lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
--[[
Slash command usage:
/raidscale 1.2
/raidscale reset
/rs 1.2
/rs reset
]]--
 
--[ CONFIG ]--
 
local healerPosition = {'LEFT', UIParent, 'CENTER', 200, 0}
local dpsPosition = {'RIGHT', UIParent, 'RIGHT', -350, 0}
 
local scaleThreshold = 28 -- Number of players needed to change the raid scale
local largeRaidScale = 0.95 -- Scale
 
--[ ENDCONFIG ]--
 
if IsAddOnLoaded('Aptechka') then return end
 
local _, ns = ...
local config = ns.Config
 
local userSetScale = false -- Don't do automatic scaling if the user set a custom value by slash command
 
local function MoveRaidFrames(point, parent, parentPoint, xOffset, yOffset)
for i = 1, config.units.raid.layout.numGroups do
_G['oUF_Neav_Raid'..i]:ClearAllPoints()
if (i == 1) then
_G['oUF_Neav_Raid'..i]:SetPoint(point, parent, parentPoint, xOffset, yOffset)
else
_G['oUF_Neav_Raid'..i]:SetPoint('TOPLEFT', 'oUF_Neav_Raid'..i-1, 'TOPRIGHT', 7, 0)
end
end
end
 
local function ScaleRaidFrames(scale)
scale = tonumber(scale)
scale = math.abs(scale)
 
-- Scaling the raid frames causes taint/errors during combat
if InCombatLockdown() or UnitAffectingCombat('player') or UnitAffectingCombat('pet') then
return
end
 
if scale then
for i = 1, config.units.raid.layout.numGroups do
_G['oUF_Neav_Raid'..i]:SetScale(scale)
end
end
end
 
local function IsHealer()
return GetSpecialization() and GetSpecializationRole(GetSpecialization()) == 'HEALER'
end
 
local f = CreateFrame('Frame')
f:RegisterEvent('PLAYER_ENTERING_WORLD')
 
local function OnEvent(self, event, ...)
if event == 'PLAYER_ENTERING_WORLD' then
self:UnregisterEvent('PLAYER_ENTERING_WORLD')
self:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')
self:RegisterEvent('GROUP_ROSTER_UPDATE')
end
 
if event == 'ACTIVE_TALENT_GROUP_CHANGED' or event == 'PLAYER_ENTERING_WORLD' then
if IsHealer() then
MoveRaidFrames(unpack(healerPosition))
else
MoveRaidFrames(unpack(dpsPosition))
end
end
 
if event == 'GROUP_ROSTER_UPDATE' and not userSetScale then
if GetNumGroupMembers() >= scaleThreshold then
ScaleRaidFrames(largeRaidScale)
else
ScaleRaidFrames(config.units.raid.scale)
end
end
end
f:SetScript('OnEvent', OnEvent)
 
-- SLASH COMMANDS
 
SlashCmdList['RAIDSCALE'] = function(scale)
if InCombatLockdown() or UnitAffectingCombat('player') or UnitAffectingCombat('pet') then
return
end
 
if scale == 'reset' then
ScaleRaidFrames(config.units.raid.scale)
userSetScale = false
return
end
 
if tonumber(scale) then
ScaleRaidFrames(scale)
userSetScale = true
else
DEFAULT_CHAT_FRAME:AddMessage('Usage: "/raidscale 1.2" or "/raidscale reset"', 255, 0, 0)
end
end
 
SLASH_RAIDSCALE1 = '/raidscale'
SLASH_RAIDSCALE2 = '/rs'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.