Server Help

Bot Questions - Playercount of the teams

Doggeti - Wed Feb 05, 2003 7:04 am
Post subject: Playercount of the teams
How can I figure out how many players are in the teams in MervBot icon_question.gif Is there an array like 'playersInTeam[x]' or is there a possibility to use this playerlist icon_question.gif
Anonymous - Wed Feb 05, 2003 8:32 am
Post subject:
Uint16 teamplayers [MAX_TEAMS]; // Assuming MAX_TEAMS is the max number of teams you wanna check
_listnode<Player> *p = playerlist->head;
while (p)
{
if (p->team < MAX_TEAMS)
teamplayers[p->team]++;
p = p->next;
}
Doggeti - Wed Feb 05, 2003 2:23 pm
Post subject:
In EVENT_PlayerSpec and EVENT_PlayerTeam I have added this line
Code: Show/Hide
checkTeams();
checkTeams looks like this:
Code: Show/Hide
void botInfo::checkTeams()
{
   Uint16 teamplayers[2];
   String s;
   _listnode<Player> *p = playerlist->head;
   while (p)
   {
      if (p->item->team < 2 && p->item->ship != SHIP_Spectator)
      teamplayers[p->item->team]++;
      p = p->next;
   }
   if (teamplayers[0] == teamplayers[1])
   {
      s = "Teams are even. Evens:";
      s += teamplayers[0];
      s += " Odds:";
      s += teamplayers[1];
   }else{
      s = "Teams are uneven. Evens:";
      s += teamplayers[0];
      s += " Odds:";
      s += teamplayers[1];
   }
   sendPublic(s);
}

It doesn't work. Do you see the error icon_question.gif
Anonymous - Wed Feb 05, 2003 10:19 pm
Post subject:
try initializing:

teamplayers[0] = 0;
teamplayers[1] = 0;

before you use them.
Doggeti - Fri Feb 07, 2003 9:35 am
Post subject:
Thank you. That was the solution. I first learned VB (I know, I know: It's not good starting with VB and then changing to C sa_tongue.gif )and there it's not necessary to initialize the variables to get the programs work properly.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group