Howdy, I've been working on putting together some basic code to do checks on if I am in a group, BG, arena, instance or raid and have code that works but I fear it's not as efficient or as elegant as it could be. I am an LUA novice but I grasp the logic enough to put this together when looking at examples.
Do any of you guys have any idea how I could shorten this coding or at least make it more efficient?
The check message relating to leaving a group seems to be called twice also, is there any obvious reason for that?
Code:
-- Instance checking for dungeon finder, raid finder and battleground/arena
local InstanceCheck_Frame = CreateFrame("Frame")
InstanceCheck_Frame:RegisterEvent("PLAYER_ENTERING_WORLD")
InstanceCheck_Frame:SetScript("OnEvent", function(...)
local inInstance, instanceType = IsInInstance()
-- Perform logic check for instances
if instanceType == "pvp" then
-- We're in a BG
ChatFrame1:AddMessage("In a BG")
elseif instanceType == "arena" then
-- We're in an arena
ChatFrame1:AddMessage("In Arena")
elseif instanceType == "party" then
-- We're in a dungeon
ChatFrame1:AddMessage("In a dungeon")
elseif instanceType == "raid" then
-- We're in a raid
ChatFrame1:AddMessage("In a raid")
else
-- We're not in a group
ChatFrame1:AddMessage("Not in a group")
end
end)
-- Seperate checking for group outside of an instance
local Group_Frame = CreateFrame("Frame")
Group_Frame:RegisterEvent("GROUP_ROSTER_UPDATE")
Group_Frame:SetScript("OnEvent", function(...)
local numParty = GetNumGroupMembers(LE_PARTY_CATEGORY_HOME)
if numParty > 1 then
-- Code for group
ChatFrame1:AddMessage("You have joined a group")
else
-- Code for non group
ChatFrame1:AddMessage("You have left a group")
end
end)
I have done the raid, arena, instance and BG seperate because those generally involve a call of player_entering_world whereas I have used group_roster_update because that was the best way to check for a group without needing to change zone or reload the interface.
Any help you guys could give would be great, would you tackle this code a different way perhaps? I'd like to learn.
Thanks!