Thread Tools Display Modes
04-20-15, 01:50 PM   #1
ctrlaltdeny
A Murloc Raider
Join Date: Jun 2013
Posts: 9
BG/Arena/Instance/Group Check

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!
  Reply With Quote
04-21-15, 08:14 AM   #2
TOM_RUS
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 95
http://wowprogramming.com/docs/api/IsInGroup
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » BG/Arena/Instance/Group Check


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