# Storing players' team numbers

**URL:** https://discourse.ioquake.org/t/storing-players-team-numbers/897
**Category:** dev
**Created:** [June 6, 2017, 6:09pm UTC](https://discourse.ioquake.org/t/storing-players-team-numbers/897 "2017-06-06T18:09:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sentry](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sentry](https://discourse.ioquake.org/u/sentry)
#### Post date: [June 6, 2017, 6:09pm UTC](https://discourse.ioquake.org/t/storing-players-team-numbers/897/1 "2017-06-06T18:09:21Z")

</div>

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:

```auto
// [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!

---

<div class="post-metadata">

### Author: ![zturtleman](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.ioquake.org/zturtleman/32/718_2.png) [@zturtleman](https://discourse.ioquake.org/u/zturtleman)
#### Post date: [June 7, 2017, 12:57am UTC](https://discourse.ioquake.org/t/storing-players-team-numbers/897/2 "2017-06-07T00:57:01Z")

</div>

You can check if spectator’s team was replaced by team of the client they are following.

```cpp
if (ps->pm_flags & PMF_FOLLOW) {
    team = TEAM_SPECTATOR;
} else {
    team = ps->persistant[PERS_TEAM];
}

```

---

<div class="post-metadata">

### Author: ![sentry](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sentry](https://discourse.ioquake.org/u/sentry)
#### Post date: [June 7, 2017, 1:12am UTC](https://discourse.ioquake.org/t/storing-players-team-numbers/897/3 "2017-06-07T01:12:02Z")

</div>

Perfect! That’s just what I was looking for. Thank you.
