EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Support::Windows Servers (https://www.eqemulator.org/forums/forumdisplay.php?f=587)
-   -   Group server code (https://www.eqemulator.org/forums/showthread.php?t=30558)

lich2594 02-11-2010 10:50 AM

Group server code
 
I am working with the source and I am having an issue with finding out if two players are grouped. If anyone could point me in the right direction, I would be thankful.

What I am trying to do is find out if client 1's group is the same as clients 2's group, or if client 1 (or 2) is not in a group.

Here is what I have atm, that does not work.

int c1_group = c1->GetGroup()->GetID(); // Client 1's group
int c2_group = c2->GetGroup()->GetID(); // Client 2's group

((c1_group != c2_group) || (c1_group == 0) || (c2_group == 0)) // clients grouped?

Can anyone point out to me what is wrong? Thanks!

Derision 02-11-2010 11:10 AM

If either client is not in a group, that code will cause a crash because GetGroup() will return a NULL pointer.

This should work:
Code:

Group *g1 = c1->GetGroup();
Group *g2 = c2->GetGroup();

if(!g1 || !g2 || (g1 != g2)
{
        // One or both clients not in a group, or not in the same group
}


lich2594 02-11-2010 11:24 AM

Thank you! That worked.

I had actually been struggling with that for some time now, haha.


All times are GMT -4. The time now is 03:40 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.