Thread Tools Display Modes
07-10-16, 07:33 AM   #1
ZikO
An Aku'mai Servant
Join Date: Jun 2008
Posts: 36
List of players in a party problem.

Hi,
Could anyone help me with my code? I register two events: PLAYER_ENTERING_WORLD and GROUP_ROSTER_UPDATE. Then run functions I have assigned to the events but it doesn't do exactly what I need.

A simple code (below) is supposed to do two things: (1) print a welcome message and (2) print a list of players in a group when I join a group as well as a player joins or leaves that group (or a raid I guess). It does prints a welcome message but it always prints: "The list of players is empty"--if someone asks, I tested when being in a party

The last message is in the second if subblock in "getlistofplayers()" function. This part is reached when API's "GetHomePartyInfo()" returns nil. It looks like this API function always returns nil! I cannot find what is wrong: the event or the API function.

I used this source for everything I looked for:
http://wowprogramming.com/docs
and it seems like a decent source. I hope someone can help

Thanks.

The codes are below.

TOC file:
Code:
## Interface: 60200
## Title: Info Addon
## Notes: Bla bla
## SavedVariables: InfoAddonDB
## Author: Me
## Version: 0.1
infoaddon.lua
Code:
local InfoAddonPlayerInfoFrame,events = CreateFrame("FRAME"),{};
local redcolour, defaultcolour = "|cFFFF0000", "|r";

-- local functions
local function getwelcomemessage()
	return "Hello in my very first addon!";
end
local function getlistofplayers()
	return GetHomePartyInfo();
end
local function printlistofplayers(plist)
	if plist then
		local print = print;
		for k,v in pairs(plist) do
			print(v);
		end
	else
		-- print(redcolour .. "The list of players is empty" .. defaultcolour);
		print("The list of players is empty");
	end
end

-- Event handlers
function events:PLAYER_ENTERING_WORLD(...)
	print(getwelcomemessage())
end
function events:GROUP_ROSTER_UPDATE(...)
	printlistofplayers(getlistofplayers());
end
for k,v in pairs(events) do
	InfoAddonPlayerInfoFrame:RegisterEvent(k);
end

-- Set Script
InfoAddonPlayerInfoFrame:SetScript("OnEvent", function (self, event, ...)
	events[event](self, ...);	
end);
  Reply With Quote
07-10-16, 08:22 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Was it a LFG party or a "real" party? From the function name it sounds like it would not work with LFG parties.

Is there a reason you want to use that particular function? Is this just for experimenting, or what do you want to do? It might still be interesting to know whether this function works, but usually people use other methods to get info on group members, I think.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
07-10-16, 09:09 AM   #3
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
I am not familiar with GetHomePartyInfo(), but as Lombra stated and reading documentation, it will only return a manually built party and no raid members or anyone in an instance group, party or raid. I don't know why it returns nil if you tested it in a group you made.

Here's how I suggest you should go through group members.

Code:
local plist={}
if IsInRaid() then
    for i=1,40 do
        if (UnitName('raid'..i)) then
            tinsert(plist,(UnitName('raid'..i)))
        end
    end
elseif IsInGroup() then
    for i=1,4 do
        if (UnitName('party'..i)) then
            tinsert(plist,(UnitName('party'..i)))
        end
    end
end
return plist

Replace return GetHomePartyInfo() with all of that. Otherwise, your code looks fine. I also suggest using PLAYER_LOGIN instead of PLAYER_ENTERING_WORLD for code setup. LOGIN will trigger only after loading the UI, which is after a login or a /reload. ENTERING_WORLD triggers after each loading screen, so you'll see that Hello message after every boat, zeppelin, instance entry, death, etc.

Last edited by Kanegasi : 07-10-16 at 08:24 PM.
  Reply With Quote
07-10-16, 09:57 AM   #4
ZikO
An Aku'mai Servant
Join Date: Jun 2008
Posts: 36
Hi and thanks for responds.

Crap. I did not come to my mind there would be any difference between LFG and real party -.-. I did tests while joining LFG. I should have mentioned that in the first place. Sorry -.-

@Kanegasi, I am going to test your function. Thanks for the code

EDIT. I am not up to anything major so I cannot even say why I would need a list of players. To test if my addon can work, I just wanted to do something else than classic "Hello World"

Last edited by ZikO : 07-10-16 at 10:01 AM.
  Reply With Quote
07-10-16, 12:48 PM   #5
ZikO
An Aku'mai Servant
Join Date: Jun 2008
Posts: 36
Hi again,

Kenegasi, the function works after a couple problems and it now gives me a list of players.

There was an error because I made a typo. If I am given a code like yours, I usually type the whole code manually to test if I can understand everything. What happened was that I typed this:
Code:
tinsert(plist, UnitName('raid'..i))
instead of this:
Code:
tinsert(plist,(UnitName('raid'..i)))
UnitFrame() was not inside the brackets and wow reported error that second parameter of the tinsert() was expected to be a number and was of a string type.

Could you guys explain why brackets solved the problem?

Many thanks.
  Reply With Quote
07-10-16, 02:20 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
UnitName returns two values (the name and the server, if not your character's). When your tinsert function received 3 parameters, it expected the second to be an index to insert the unit name at in the table. Putting the UnitName function call in parentheses used only the first return of the function.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-10-16, 05:24 PM   #7
ZikO
An Aku'mai Servant
Join Date: Jun 2008
Posts: 36
That makes sense. Thanks Seerah
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » List of players in a party problem.


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