Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Tiberian Technologies / Blackhand Studios » Tiberian Technologies Forum » int Get_Team_Player_Count(int Team)
int Get_Team_Player_Count(int Team) [message #339927] Wed, 09 July 2008 08:08 Go to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
int Get_Team_Player_Count(int Team) seemed to always crash for me, it says it's tested, but I wasn't able to use it. here is the stock version of it:

int Get_Team_Player_Count(int Team)
{
	int Total = 0;
	GenericSLNode *x = BaseGameObjList->HeadNode;
	while (x)
	{
		GameObject *o = As_SoldierGameObj((GameObject *)x->NodeData);
		if (o && Get_Object_Type(o) == Team)
		{
			Total++;
		}
		x = x->NodeNext;
	}
	return Total;
}



I altered it so that the while loop doesn't try to do Get_Object_Type on the GameObject *, because this is where it seemed to crash. I think you can only use that function on buildings and players, so I'm sure that's why it was crashing...

I changed it to this:

int Get_Team_Player_Count(int Team)
{
	int Total = 0;
	GenericSLNode *x = BaseGameObjList->HeadNode;
	while (x)
	{
		GameObject *o = (GameObject *)x->NodeData;
		if (o && Commands->Is_A_Star(o))
		{
			if (Get_Team(Get_Player_ID(o)) == Team)
			{
			Total++;
		}
		}
		x = x->NodeNext;
	}
	return Total;
}


And I havn't had a crash yet, maybe you'll look into it for 4.0? Smile



Re: int Get_Team_Player_Count(int Team) [message #339938 is a reply to message #339927] Wed, 09 July 2008 09:30 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
I use this from Hex. ^_^

int TeamCount(int Team)
{
	int Count = 0;
	for (GenericSLNode* PlayerIter = PlayerList->HeadNode; (PlayerIter != NULL); PlayerIter = PlayerIter->NodeNext)
	{
		cPlayer *p = (cPlayer *)PlayerIter->NodeData;
		if (p->IsActive && p->PlayerType.Get() == Team)
		{
			Count++;
		}
	}
	return Count;
}
Re: int Get_Team_Player_Count(int Team) [message #339994 is a reply to message #339927] Wed, 09 July 2008 14:53 Go to previous messageGo to next message
Ghostshaw is currently offline  Ghostshaw
Messages: 709
Registered: September 2006
Karma: 0
Colonel
The As_SoldierGameObj function was bugged and crashed for some items in teh basegameobj's from the list. This has been fixed.

BlackIntel Administrator
Re: int Get_Team_Player_Count(int Team) [message #339995 is a reply to message #339927] Wed, 09 July 2008 14:55 Go to previous messageGo to next message
_SSnipe_ is currently offline  _SSnipe_
Messages: 4121
Registered: May 2007
Location: Riverside Southern Califo...
Karma: 0
General (4 Stars)
whats this for?
Re: int Get_Team_Player_Count(int Team) [message #340007 is a reply to message #339927] Wed, 09 July 2008 16:49 Go to previous message
StealthEye is currently offline  StealthEye
Messages: 2518
Registered: May 2006
Location: The Netherlands
Karma: 0
General (2 Stars)

PlayerType is only defined for smart game objects. You should use As_SmartGameObj to test whether you can call GetPlayerType on an object.

Hex's solution is cleaner though. Wink

[edit]
Oh, I see it already does As_SoldierGameObj... It's probably the As_SoldierGameObj call crashing. For TT it calls As_ScriptableGameObj prior to calling As_SoldierGameObj:

GameObject *As_SoldierGameObj(GameObject *obj)
{
	if (!Commands->Get_ID(obj) || !obj)
		return 0;
	ScriptableGameObj* o2 = ((BaseGameObj *)obj)->As_ScriptableGameObj();
	if (!o2)
		return 0;
	return (GameObject *)o2->As_SoldierGameObj();
}


For older versions it probably does not call As_ScriptableGameObj and therefore crash when calling As_SoldierGameObj on a nonscriptable game object.


BlackIntel admin/founder/coder
Please visit http://www.blackintel.org/

[Updated on: Wed, 09 July 2008 16:55]

Report message to a moderator

Previous Topic: Sooooo...
Next Topic: EA
Goto Forum:
  


Current Time: Fri Jun 07 06:42:35 MST 2024

Total time taken to generate the page: 0.00703 seconds