I’ve coded some various functions that need to be able to retrieve each player’s team number (such as a custom /players list). I was initially using persistant[PERS_TEAM], but then I realized if a player is spectating someone, it returns that player’s team number instead of their own.
So, the method I’m using right now to store the player’s team number is:
// [ClientUserinfoChanged: 2 n\Test\t\3\model\ranger/pm\hmodel\ranger/pm\c1\4444\c2\5\hc\100\w\0\l\0\rt\3\st\0
else if( strcmp(first,"ClientUserinfoChanged:") == 0 ){
int x = 1, team = 0;
for (i=0,cl=svs.clients; i < sv_maxclients->integer; i++,cl++){
if(!cl->state){ continue; }
if( i == atoi(second) ) {
// Retrieve team number
while( strRemoveAll(line," ") );
char *pch;
pch = strtok( line, "\\" );
while (pch != NULL) {
if( x == 4 ) {
team = atoi(pch);
pch = NULL;
} else {
pch = strtok(NULL, "\\");
}
x++;
}
// If client joined a different team, update team number and timestamp of join
if( cl->teamNum != team ) {
cl->teamNum = team;
}
}
}
}
However, I don’t really like this solution and was wondering if there’s a better way. Does anyone have any suggestions? Thanks!