Swap around check to remove nil reference error on already grouped members.

Wobin [06-14-14 - 12:24]
Swap around check to remove nil reference error on already grouped members.
Filename
PartyStarter.lua
diff --git a/PartyStarter.lua b/PartyStarter.lua
index ac65021..e4d48f5 100644
--- a/PartyStarter.lua
+++ b/PartyStarter.lua
@@ -13,6 +13,9 @@ end
 function PartyStarter:AddLines(playerName, rawName)
 	local localPlayerIsGrouped = IsUnitGrouped("player")
     local localPlayerIsGroupLeader = IsUnitGroupLeader("player")
+
+    if localPlayerIsGrouped or localPlayerIsGroupLeader then return end
+
     local menu = ZO_Menu.items
 	local target = 0
 	for i,v in ipairs(menu) do
@@ -21,24 +24,24 @@ function PartyStarter:AddLines(playerName, rawName)
 			target = i
 		end
 	end
-
-	-- This is rather messy, we can't just move menu items around as they're all
-	-- anchored to each other on -add-. So we just swap the functionality instead
-	local storedFunc = menu[target].item.OnSelect
-	local storedText = GetControl(menu[target].item, "Name"):GetText()
-
-	local lastFunc = menu[#menu].item.OnSelect
-	local lastText = GetControl(menu[#menu].item, "Name"):GetText()
-
-	menu[target].item.OnSelect = lastFunc
-	GetControl(menu[target].item, "Name"):SetText(lastText)
-	menu[#menu].item.OnSelect = storedFunc
-	GetControl(menu[#menu].item, "Name"):SetText(storedText)
-
-    -- If we can't find it, then lets add it
+
+ 	-- If we can't find it, then lets add it
 	if target == 0 then
 		AddMenuItem(GetString(SI_CHAT_PLAYER_CONTEXT_ADD_GROUP), function() TryGroupInviteByName(playerName) end)
-	end
+	else
+		-- This is rather messy, we can't just move menu items around as they're all
+		-- anchored to each other on -add-. So we just swap the functionality instead
+		local storedFunc = menu[target].item.OnSelect
+		local storedText = GetControl(menu[target].item, "Name"):GetText()
+
+		local lastFunc = menu[#menu].item.OnSelect
+		local lastText = GetControl(menu[#menu].item, "Name"):GetText()
+
+		menu[target].item.OnSelect = lastFunc
+		GetControl(menu[target].item, "Name"):SetText(lastText)
+		menu[#menu].item.OnSelect = storedFunc
+		GetControl(menu[#menu].item, "Name"):SetText(storedText)
+   	end
 	ShowMenu(nil, 1)
 end