3 #include "command/common.qh"
4 #include "mutators/all.qh"
5 #include "../common/playerstats.qh"
6 #include "../common/teams.qh"
9 entity teamscorekeepers[16];
10 string scores_label[MAX_SCORE];
11 float scores_flags[MAX_SCORE];
12 string teamscores_label[MAX_TEAMSCORE];
13 float teamscores_flags[MAX_TEAMSCORE];
14 float teamscores_entities_count;
15 var .float scores_primary;
16 var .float teamscores_primary;
17 float scores_flags_primary;
18 float teamscores_flags_primary;
20 vector ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, vector previous, float strict) // returns: cmp value, best prio
22 if(!strict && !(fieldflags & SFL_SORT_PRIO_MASK)) // column does not sort
24 if((fieldflags & SFL_SORT_PRIO_MASK) < previous.y)
26 if (t1.(field) == t2.(field))
29 previous.y = fieldflags & SFL_SORT_PRIO_MASK;
31 if(fieldflags & SFL_ZERO_IS_WORST)
38 else if (t2.(field) == 0)
45 if (fieldflags & SFL_LOWER_IS_BETTER)
46 previous.x = (t2.(field) - t1.(field));
48 previous.x = (t1.(field) - t2.(field));
57 bool TeamScore_SendEntity(entity this, entity to, float sendflags)
59 float i, p, longflags;
61 WriteByte(MSG_ENTITY, ENT_CLIENT_TEAMSCORES);
62 WriteByte(MSG_ENTITY, self.team - 1);
65 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
66 if(self.(teamscores[i]) > 127 || self.(teamscores[i]) <= -128)
69 #if MAX_TEAMSCORE <= 8
70 WriteByte(MSG_ENTITY, sendflags);
71 WriteByte(MSG_ENTITY, longflags);
73 WriteShort(MSG_ENTITY, sendflags);
74 WriteShort(MSG_ENTITY, longflags);
76 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
80 WriteInt24_t(MSG_ENTITY, self.(teamscores[i]));
82 WriteChar(MSG_ENTITY, self.(teamscores[i]));
88 void TeamScore_Spawn(float t, string name)
92 ts.classname = "csqc_score_team";
93 ts.netname = name; // not used yet, FIXME
95 Net_LinkEntity(ts, false, 0, TeamScore_SendEntity);
96 teamscorekeepers[t - 1] = ts;
97 ++teamscores_entities_count;
98 PlayerStats_GameReport_AddTeam(t);
101 float TeamScore_AddToTeam(float t, float scorefield, float score)
108 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
109 if(t <= 0 || t >= 16)
113 error("Adding score to invalid team!");
115 s = teamscorekeepers[t - 1];
120 error("Adding score to unknown team!");
123 if(teamscores_label[scorefield] != "")
124 s.SendFlags |= pow(2, scorefield);
125 return (s.(teamscores[scorefield]) += score);
128 float TeamScore_Add(entity player, float scorefield, float score)
130 return TeamScore_AddToTeam(player.team, scorefield, score);
133 float TeamScore_Compare(entity t1, entity t2, float strict)
135 if(!t1 || !t2) return (!t2) - !t1;
137 vector result = '0 0 0';
139 for(i = 0; i < MAX_TEAMSCORE; ++i)
143 result = ScoreField_Compare(t1, t2, f, teamscores_flags[i], result, strict);
146 if (result.x == 0 && strict)
147 result.x = t1.team - t2.team;
153 * the scoreinfo entity
156 void ScoreInfo_SetLabel_PlayerScore(float i, string label, float scoreflags)
158 scores_label[i] = label;
159 scores_flags[i] = scoreflags;
160 if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
162 scores_primary = scores[i];
163 scores_flags_primary = scoreflags;
167 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_TOTAL, label));
168 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_SCOREBOARD, label));
172 void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags)
174 teamscores_label[i] = label;
175 teamscores_flags[i] = scoreflags;
176 if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
178 teamscores_primary = teamscores[i];
179 teamscores_flags_primary = scoreflags;
183 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_TOTAL, label));
184 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_SCOREBOARD, label));
188 bool ScoreInfo_SendEntity(entity this, entity to, int sf)
191 WriteByte(MSG_ENTITY, ENT_CLIENT_SCORES_INFO);
192 WriteInt24_t(MSG_ENTITY, MapInfo_LoadedGametype);
193 for(i = 0; i < MAX_SCORE; ++i)
195 WriteString(MSG_ENTITY, scores_label[i]);
196 WriteByte(MSG_ENTITY, scores_flags[i]);
198 for(i = 0; i < MAX_TEAMSCORE; ++i)
200 WriteString(MSG_ENTITY, teamscores_label[i]);
201 WriteByte(MSG_ENTITY, teamscores_flags[i]);
206 void ScoreInfo_Init(float teams)
208 if(scores_initialized)
210 scores_initialized.SendFlags |= 1; // force a resend
214 scores_initialized = spawn();
215 scores_initialized.classname = "ent_client_scoreinfo";
216 Net_LinkEntity(scores_initialized, false, 0, ScoreInfo_SendEntity);
219 TeamScore_Spawn(NUM_TEAM_1, "Red");
221 TeamScore_Spawn(NUM_TEAM_2, "Blue");
223 TeamScore_Spawn(NUM_TEAM_3, "Yellow");
225 TeamScore_Spawn(NUM_TEAM_4, "Pink");
229 * per-player score entities
232 bool PlayerScore_SendEntity(entity this, entity to, float sendflags)
234 float i, p, longflags;
236 WriteByte(MSG_ENTITY, ENT_CLIENT_SCORES);
237 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
240 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
241 if(self.(scores[i]) > 127 || self.(scores[i]) <= -128)
245 WriteByte(MSG_ENTITY, sendflags);
246 WriteByte(MSG_ENTITY, longflags);
248 WriteShort(MSG_ENTITY, sendflags);
249 WriteShort(MSG_ENTITY, longflags);
251 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
255 WriteInt24_t(MSG_ENTITY, self.(scores[i]));
257 WriteChar(MSG_ENTITY, self.(scores[i]));
263 float PlayerScore_Clear(entity player)
268 if(teamscores_entities_count)
271 if(MUTATOR_CALLHOOK(ForbidPlayerScore_Clear)) return 0;
273 sk = player.scorekeeper;
274 for(i = 0; i < MAX_SCORE; ++i)
276 if(sk.(scores[i]) != 0)
277 if(scores_label[i] != "")
278 sk.SendFlags |= pow(2, i);
285 void Score_ClearAll()
289 FOR_EACH_CLIENTSLOT(p)
294 for(i = 0; i < MAX_SCORE; ++i)
296 if(sk.(scores[i]) != 0)
297 if(scores_label[i] != "")
298 sk.SendFlags |= pow(2, i);
302 for(t = 0; t < 16; ++t)
304 sk = teamscorekeepers[t];
307 for(i = 0; i < MAX_TEAMSCORE; ++i)
309 if(sk.(teamscores[i]) != 0)
310 if(teamscores_label[i] != "")
311 sk.SendFlags |= pow(2, i);
312 sk.(teamscores[i]) = 0;
317 void PlayerScore_Attach(entity player)
320 if(player.scorekeeper)
321 error("player already has a scorekeeper");
324 Net_LinkEntity(sk, false, 0, PlayerScore_SendEntity);
325 player.scorekeeper = sk;
328 void PlayerScore_Detach(entity player)
330 if(!player.scorekeeper)
331 error("player has no scorekeeper");
332 remove(player.scorekeeper);
333 player.scorekeeper = world;
336 float PlayerScore_Add(entity player, float scorefield, float score)
338 bool mutator_returnvalue = MUTATOR_CALLHOOK(AddPlayerScore, scorefield, score);
342 if(!mutator_returnvalue)
345 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
346 entity s = player.scorekeeper;
351 backtrace("Adding score to unknown player!");
355 if(scores_label[scorefield] != "")
356 s.SendFlags |= pow(2, scorefield);
358 PS_GR_P_ADDVAL(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label[scorefield]), score);
359 return (s.(scores[scorefield]) += score);
362 float PlayerTeamScore_Add(entity player, float pscorefield, float tscorefield, float score)
365 r = PlayerScore_Add(player, pscorefield, score);
366 if(teamscores_entities_count) // only for teamplay
367 r = TeamScore_Add(player, tscorefield, score);
371 float PlayerScore_Compare(entity t1, entity t2, float strict)
373 if(!t1 || !t2) return (!t2) - !t1;
375 vector result = '0 0 0';
377 for(i = 0; i < MAX_SCORE; ++i)
381 result = ScoreField_Compare(t1, t2, f, scores_flags[i], result, strict);
384 if (result.x == 0 && strict)
385 result.x = num_for_edict(t1.owner) - num_for_edict(t2.owner);
390 void WinningConditionHelper()
396 entity winnerscorekeeper;
397 entity secondscorekeeper;
401 // gametype:P<pure>:S<slots>::plabel,plabel:tlabel,tlabel:teamid:tscore,tscore:teamid:tscore,tscore
402 // score labels always start with a symbol or with lower case
403 // so to match pure, match for :P0:
404 // to match full, match for :S0:
406 fullstatus = autocvar_g_full_getstatus_responses;
409 s = strcat(s, ":", autocvar_g_xonoticversion);
410 s = strcat(s, ":P", ftos(cvar_purechanges_count));
411 s = strcat(s, ":S", ftos(nJoinAllowed(world)));
412 s = strcat(s, ":F", ftos(serverflags));
413 s = strcat(s, ":M", modname);
414 s = strcat(s, "::", GetPlayerScoreString(world, (fullstatus ? 1 : 2)));
416 if(teamscores_entities_count)
420 s = strcat(s, ":", GetTeamScoreString(0, 1));
421 for(t = 0; t < 16; ++t)
422 if(teamscorekeepers[t])
423 s = strcat(s, ":", ftos(t+1), ":", GetTeamScoreString(t+1, 1));
425 WinningConditionHelper_winnerteam = -1;
426 WinningConditionHelper_secondteam = -1;
427 winnerscorekeeper = world;
428 secondscorekeeper = world;
429 for(t = 0; t < 16; ++t)
431 sk = teamscorekeepers[t];
432 c = TeamScore_Compare(winnerscorekeeper, sk, 1);
435 WinningConditionHelper_secondteam = WinningConditionHelper_winnerteam;
436 WinningConditionHelper_winnerteam = t + 1;
437 secondscorekeeper = winnerscorekeeper;
438 winnerscorekeeper = sk;
442 c = TeamScore_Compare(secondscorekeeper, sk, 1);
445 WinningConditionHelper_secondteam = t + 1;
446 secondscorekeeper = sk;
451 WinningConditionHelper_equality = (TeamScore_Compare(winnerscorekeeper, secondscorekeeper, 0) == 0);
452 if(WinningConditionHelper_equality)
453 WinningConditionHelper_winnerteam = WinningConditionHelper_secondteam = -1;
455 WinningConditionHelper_topscore = winnerscorekeeper.teamscores_primary;
456 WinningConditionHelper_secondscore = secondscorekeeper.teamscores_primary;
457 WinningConditionHelper_lowerisbetter = (teamscores_flags_primary & SFL_LOWER_IS_BETTER);
458 WinningConditionHelper_zeroisworst = (teamscores_flags_primary & SFL_ZERO_IS_WORST);
460 WinningConditionHelper_winner = world; // not supported in teamplay
461 WinningConditionHelper_second = world; // not supported in teamplay
465 WinningConditionHelper_winner = world;
466 WinningConditionHelper_second = world;
467 winnerscorekeeper = world;
468 secondscorekeeper = world;
472 c = PlayerScore_Compare(winnerscorekeeper, sk, 1);
475 WinningConditionHelper_second = WinningConditionHelper_winner;
476 WinningConditionHelper_winner = p;
477 secondscorekeeper = winnerscorekeeper;
478 winnerscorekeeper = sk;
482 c = PlayerScore_Compare(secondscorekeeper, sk, 1);
485 WinningConditionHelper_second = p;
486 secondscorekeeper = sk;
491 WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, 0) == 0);
492 if(WinningConditionHelper_equality)
493 WinningConditionHelper_winner = WinningConditionHelper_second = world;
495 WinningConditionHelper_topscore = winnerscorekeeper.scores_primary;
496 WinningConditionHelper_secondscore = secondscorekeeper.scores_primary;
497 WinningConditionHelper_lowerisbetter = (scores_flags_primary & SFL_LOWER_IS_BETTER);
498 WinningConditionHelper_zeroisworst = (scores_flags_primary & SFL_ZERO_IS_WORST);
500 WinningConditionHelper_winnerteam = -1; // no teamplay
501 WinningConditionHelper_secondteam = -1; // no teamplay
504 if(WinningConditionHelper_topscore == 0)
506 if(scores_flags_primary & SFL_ZERO_IS_WORST)
508 if(WinningConditionHelper_lowerisbetter)
509 WinningConditionHelper_topscore = 999999999;
511 WinningConditionHelper_topscore = -999999999;
513 WinningConditionHelper_equality = 0;
516 if(WinningConditionHelper_secondscore == 0)
518 if(scores_flags_primary & SFL_ZERO_IS_WORST)
520 if(WinningConditionHelper_lowerisbetter)
521 WinningConditionHelper_secondscore = 999999999;
523 WinningConditionHelper_secondscore = -999999999;
528 strunzone(worldstatus);
529 worldstatus = strzone(s);
535 s = GetPlayerScoreString(p, 1);
536 if(IS_REAL_CLIENT(p))
537 s = strcat(s, ":human");
539 s = strcat(s, ":bot");
540 if(!IS_PLAYER(p) && !MUTATOR_CALLHOOK(GetPlayerStatus, p, s))
541 s = strcat(s, ":spectator");
542 s = strcat(s, ret_string);
546 if(IS_PLAYER(p) || MUTATOR_CALLHOOK(GetPlayerStatus, p, s))
547 s = GetPlayerScoreString(p, 2);
550 s = strcat(s, ret_string);
554 strunzone(p.clientstatus);
555 p.clientstatus = strzone(s);
559 string GetScoreLogLabel(string label, float fl)
561 if(fl & SFL_LOWER_IS_BETTER)
562 label = strcat(label, "<");
563 if((fl & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
564 label = strcat(label, "!!");
565 else if((fl & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
566 label = strcat(label, "!");
570 string GetPlayerScoreString(entity pl, float shortString)
581 for(i = 0; i < MAX_SCORE; ++i)
582 if((scores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
586 out = strcat(out, GetScoreLogLabel(l, f), ",");
589 for(i = 0; i < MAX_SCORE; ++i)
590 if((scores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
594 out = strcat(out, GetScoreLogLabel(l, f), ",");
597 for(i = 0; i < MAX_SCORE; ++i)
598 if((scores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
599 if((scores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
603 out = strcat(out, GetScoreLogLabel(l, f), ",");
605 out = substring(out, 0, strlen(out) - 1);
607 else if((sk = pl.scorekeeper))
609 for(i = 0; i < MAX_SCORE; ++i)
610 if((scores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
611 out = strcat(out, ftos(sk.(scores[i])), ",");
613 for(i = 0; i < MAX_SCORE; ++i)
614 if((scores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
615 out = strcat(out, ftos(sk.(scores[i])), ",");
617 for(i = 0; i < MAX_SCORE; ++i)
618 if((scores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
619 if((scores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
620 out = strcat(out, ftos(sk.(scores[i])), ",");
621 out = substring(out, 0, strlen(out) - 1);
626 string GetTeamScoreString(float tm, float shortString)
637 for(i = 0; i < MAX_TEAMSCORE; ++i)
638 if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
640 f = teamscores_flags[i];
641 l = teamscores_label[i];
642 out = strcat(out, GetScoreLogLabel(l, f), ",");
645 for(i = 0; i < MAX_TEAMSCORE; ++i)
646 if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
648 f = teamscores_flags[i];
649 l = teamscores_label[i];
650 out = strcat(out, GetScoreLogLabel(l, f), ",");
653 for(i = 0; i < MAX_TEAMSCORE; ++i)
654 if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
655 if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
657 f = teamscores_flags[i];
658 l = teamscores_label[i];
659 out = strcat(out, GetScoreLogLabel(l, f), ",");
661 out = substring(out, 0, strlen(out) - 1);
663 else if((sk = teamscorekeepers[tm - 1]))
665 for(i = 0; i < MAX_TEAMSCORE; ++i)
666 if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
667 out = strcat(out, ftos(sk.(teamscores[i])), ",");
669 for(i = 0; i < MAX_TEAMSCORE; ++i)
670 if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
671 out = strcat(out, ftos(sk.(teamscores[i])), ",");
673 for(i = 0; i < MAX_TEAMSCORE; ++i)
674 if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
675 if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
676 out = strcat(out, ftos(sk.(teamscores[i])), ",");
677 out = substring(out, 0, strlen(out) - 1);
682 float PlayerTeamScore_Compare(entity p1, entity p2, float teams, float strict)
684 if(teams && teamscores_entities_count)
686 if(p1.team != p2.team)
690 t1 = teamscorekeepers[p1.team - 1];
691 t2 = teamscorekeepers[p2.team - 1];
692 r = TeamScore_Compare(t1, t2, ((teams >= 0) ? 1 : strict));
699 return PlayerScore_Compare(p1.scorekeeper, p2.scorekeeper, strict);
702 entity PlayerScore_Sort(.float field, float teams, float strict, float nospectators)
704 entity p, plist, pprev, pbest, pbestprev, pfirst, plast;
712 FOR_EACH_CLIENT(p) if(p.scorekeeper)
715 if(p.frags == FRAGS_SPECTATOR)
721 // Now plist points to the whole list.
723 pfirst = plast = world;
728 pprev = pbestprev = world;
730 for(p = plist; (pprev = p), (p = p.chain); )
732 if(PlayerTeamScore_Compare(p, pbest, teams, strict) > 0)
739 // remove pbest out of the chain
740 if(pbestprev == world)
743 pbestprev.chain = pbest.chain;
747 if(!plast || PlayerTeamScore_Compare(plast, pbest, teams, 0))
762 float TeamScore_GetCompareValue(float t)
767 if(t <= 0 || t >= 16)
771 error("Reading score of invalid team!");
774 sk = teamscorekeepers[t - 1];
777 s = sk.teamscores_primary;
778 if(teamscores_flags_primary & SFL_ZERO_IS_WORST)
781 if(teamscores_flags_primary & SFL_LOWER_IS_BETTER)
786 const float NAMEWIDTH = 22;
787 const float SCORESWIDTH = 58;
788 // TODO put this somewhere in common?
789 string Score_NicePrint_ItemColor(float vflags)
791 if(vflags & SFL_SORT_PRIO_PRIMARY)
793 else if(vflags & SFL_SORT_PRIO_SECONDARY)
799 void Score_NicePrint_Team(entity to, float t, float w)
807 sk = teamscorekeepers[t - 1];
810 s = strcat(s, Team_ColoredFullName(t));
811 for(i = 0; i < MAX_TEAMSCORE; ++i)
812 if(teamscores_label[i] != "")
814 fl = teamscores_flags[i];
815 sc = sk.(teamscores[i]);
816 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc));
822 s = strcat(s, strpad(max(0, NAMEWIDTH - strlennocol(s)), ""));
824 for(i = 0; i < MAX_SCORE; ++i)
825 if(scores_label[i] != "")
827 fl = scores_flags[i];
828 s2 = scores_label[i];
829 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, substring(s2, 0, w)));
835 void Score_NicePrint_Player(entity to, entity p, float w)
845 s = strcat(s, p.netname);
848 i = strlennocol(s) - NAMEWIDTH;
850 s = substring(s, 0, strlen(s) - i);
853 s = strcat(s, strpad(i, ""));
858 for(i = 0; i < MAX_SCORE; ++i)
859 if(scores_label[i] != "")
861 fl = scores_flags[i];
863 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc)));
869 void Score_NicePrint_Spectators(entity to)
871 print_to(to, "Spectators:");
874 void Score_NicePrint_Spectator(entity to, entity p)
876 print_to(to, strcat(" ", p.netname));
879 .float score_dummyfield;
880 void Score_NicePrint(entity to)
887 for(i = 0; i < MAX_SCORE; ++i)
888 if(scores_label[i] != "")
890 w = bound(6, floor(SCORESWIDTH / t - 1), 9);
892 p = PlayerScore_Sort(score_dummyfield, 1, 1, 0);
895 if(!teamscores_entities_count)
896 Score_NicePrint_Team(to, t, w);
899 if(teamscores_entities_count)
901 Score_NicePrint_Team(to, p.team, w);
902 Score_NicePrint_Player(to, p, w);
912 Score_NicePrint_Spectators(to);
913 Score_NicePrint_Spectator(to, p);
918 void PlayerScore_PlayerStats(entity p)
924 for(i = 0; i < MAX_SCORE; ++i)
925 if(s.(scores[i]) != 0)
926 if(scores_label[i] != "")
927 PS_GR_P_ADDVAL(s.owner, strcat(PLAYERSTATS_SCOREBOARD, scores_label[i]), s.(scores[i]));
930 void PlayerScore_TeamStats(void)
934 for(t = 0; t < 16; ++t)
936 sk = teamscorekeepers[t];
939 for(i = 0; i < MAX_TEAMSCORE; ++i)
940 if(sk.(teamscores[i]) != 0)
941 if(teamscores_label[i] != "")
942 // the +1 is important here!
943 PS_GR_T_ADDVAL(t+1, strcat(PLAYERSTATS_SCOREBOARD, teamscores_label[i]), sk.(teamscores[i]));