1 float COLOR_TEAM1 = 5; // red
2 float COLOR_TEAM2 = 14; // blue
3 float COLOR_TEAM3 = 10; // pink
4 float COLOR_TEAM4 = 13; // yellow
7 float GAME_DEATHMATCH = 1;
8 float GAME_TEAM_DEATHMATCH = 2;
9 float GAME_DOMINATION = 3;
11 float GAME_RUNEMATCH = 5;
16 // client counts for each team
18 // # of bots on those teams
19 float cb1, cb2, cb3, cb4;
21 float g_domination, g_ctf, g_tdm;
23 float audit_teams_time;
26 string TeamName(float t)
28 // fixme: Search for team entities and get their .netname's!
37 return "Neutral Team";
39 string ColoredTeamName(float t)
41 // fixme: Search for team entities and get their .netname's!
43 return "^1Red Team^7";
45 return "^4Blue Team^7";
47 return "^6Pink Team^7";
49 return "^3Yellow Team^7";
50 return "Neutral Team";
52 string TeamNoName(float t)
54 // fixme: Search for team entities and get their .netname's!
63 return "Neutral Team";
68 void runematch_init();
71 void(entity pl) LogTeamchange =
74 if(!cvar("sv_eventlog"))
78 str = strcat(":team:", ftos(pl.playerid), ":");
79 str = strcat(str, ftos(pl.team));
80 GameLogEcho(str, FALSE);
85 cvar_set("g_tdm", "0");
86 cvar_set("g_domination", "0");
87 cvar_set("g_ctf", "0");
88 cvar_set("g_runematch", "0");
89 cvar_set("g_lms", "0");
90 cvar_set("g_arena", "0");
91 cvar_set("teamplay", "0");
94 cvar_set("exit_cfg", "");
97 void ActivateTeamplay()
99 float teamplay_default;
100 teamplay_default = cvar("teamplay_default");
103 cvar_set("teamplay", ftos(teamplay_default));
105 cvar_set("teamplay", "3");
108 string gamemode_name;
111 void InitGameplayMode()
113 float fraglimit_override, timelimit_override;
117 game = cvar ("gamecfg"); // load game options
119 // game cvars get reset before map changes
120 // then map's cfg sets them as desired
122 // FIXME: also set a message or game mode name to print to players when the join
124 // set both here, gamemode can override it later
125 timelimit_override = cvar("timelimit_override");
126 fraglimit_override = cvar("fraglimit_override");
128 if(game == GAME_DOMINATION || cvar("g_domination"))
131 game = GAME_DOMINATION;
132 cvar_set("g_domination", "1");
136 fraglimit_override = cvar("g_domination_point_limit");
138 gamemode_name = "Domination";
141 else if(game == GAME_CTF || cvar("g_ctf"))
145 cvar_set("g_ctf", "1");
149 fraglimit_override = cvar("g_ctf_capture_limit");
151 gamemode_name = "Capture the Flag";
154 else if((game == GAME_RUNEMATCH || cvar("g_runematch")) && !cvar("g_minstagib"))
156 game = GAME_RUNEMATCH;
157 cvar_set("g_runematch", "1");
159 if(cvar("deathmatch_force_teamplay"))
162 fraglimit_override = cvar("g_runematch_point_limit");
164 gamemode_name = "Rune Match";
170 else if(game == GAME_DEATHMATCH || game == GAME_TEAM_DEATHMATCH || cvar("g_tdm"))
172 if(!cvar("deathmatch"))
173 cvar_set("deathmatch", "1");
176 if(game == GAME_TEAM_DEATHMATCH || cvar("g_tdm") || cvar("deathmatch_force_teamplay"))
179 game = GAME_TEAM_DEATHMATCH;
180 gamemode_name = "Team Deathmatch";
183 cvar_set("g_tdm", "1");
188 game = GAME_DEATHMATCH;
189 gamemode_name = "Deathmatch";
193 fraglimit_override = cvar("fraglimit_override");
195 else if(game == GAME_LMS || cvar("g_lms"))
199 cvar_set("g_lms", "1");
200 fraglimit_override = cvar("g_lms_lives_override");
201 if(fraglimit_override == 0)
202 fraglimit_override = -1;
203 gamemode_name = "Last Man Standing";
205 lms_lowest_lives = 999;
207 else if(game == GAME_ARENA || cvar("g_arena"))
211 cvar_set("g_arena", "1");
212 fraglimit_override = cvar("g_arena_point_limit");
213 maxspawned = cvar("g_arena_maxspawned");
216 arena_roundbased = cvar("g_arena_roundbased");
217 gamemode_name = "Arena";
222 // we can only assume...
224 gamemode_name = "Deathmatch";
227 /* else if(game == GAME_TEAM_DEATHMATCH)
229 if(!cvar("deathmatch"))
230 cvar_set("deathmatch", "1");
232 //if(!cvar("teamplay"))
233 // cvar_set("teamplay", "3");
236 fraglimit_override = cvar("fraglimit_override");
239 // enforce the server's universal frag/time limits
240 if(!cvar("g_campaign"))
242 if(fraglimit_override >= 0)
243 cvar_set("fraglimit", ftos(fraglimit_override));
244 if(timelimit_override >= 0)
245 cvar_set("timelimit", ftos(timelimit_override));
248 if (game == GAME_DOMINATION)//cvar("g_domination"))
250 else if (game == GAME_CTF)//cvar("g_ctf"))
252 else if (game == GAME_RUNEMATCH)//cvar("g_runematch"))
254 else if (game == GAME_TEAM_DEATHMATCH)//cvar("g_runematch"))
257 // those mutators rule each other out
258 if(cvar("g_minstagib"))
260 cvar_set("g_instagib", "0");
261 cvar_set("g_rocketarena", "0");
263 if(cvar("g_instagib"))
265 cvar_set("g_minstagib", "0");
266 cvar_set("g_rocketarena", "0");
268 if(cvar("g_rocketarena"))
270 cvar_set("g_instagib", "0");
271 cvar_set("g_minstagib", "0");
274 registercvar("_motd", "");
275 registercvar("_mutatormsg", "");
276 cvar_set("_motd", linewrap(cvar_string("sv_motd"), 50));
277 cvar_set("_mutatormsg", linewrap(cvar_string("g_mutatormsg"), 50));
280 string GetClientVersionMessage(float v) {
281 local string versionmsg;
283 versionmsg = "^1client is too old to get versioninfo.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nUPDATE!!! (http://www.nexuiz.com)^8";
284 // either that or someone wants to be funny
285 } else if (v != cvar("gameversion")) {
286 if(v < cvar("gameversion")) {
287 versionmsg = "^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8";
289 versionmsg = "^3This server is using an outdated Nexuiz version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8";
292 versionmsg = "^2client version and server version are compatible.^8";
294 return strzone(versionmsg);
299 void PrintWelcomeMessage(entity pl)
301 string s, mutator, modifications;
303 /*if(self.welcomemessage_time < time)
305 if(self.welcomemessage_time2 > time)
307 self.welcomemessage_time2 = time + 0.8; */
309 if(self.classname == "observer")
311 if(cvar("g_lms") && self.frags <= 0 && self.frags > -666)
312 return centerprint(self, strcat(newlines, "^1You have no more lives left\nwait for next round\n\n\n^7press attack to spectate other players"));
313 else if(cvar("g_lms") && self.frags == -666)
314 return centerprint(self, strcat(newlines, "^1Match has already begun\nwait for next round\n\n\n^7press attack to spectate other players"));
316 else if(self.classname == "spectator")
318 if ((cvar("g_lms") && self.frags < 1) || cvar("g_arena"))
319 return centerprint(self, strcat(newlines, "spectating ", self.enemy.netname, "\n\n\n^7press attack for next player\npress attack2 for free fly mode"));
321 return centerprint(self, strcat(newlines, "spectating ", self.enemy.netname, "\n\n\n^7press jump to play\n^7press attack for next player\npress attack2 for free fly mode"));
325 if(self.welcomemessage_time2 > time) return;
326 self.welcomemessage_time2 = time + 1.0;
328 if(cvar("g_campaign"))
330 centerprint(pl, campaign_message);
334 if(cvar("g_minstagib"))
335 mutator = "^2Minstagib ^1";
336 else if(cvar("g_instagib"))
337 mutator = "^2Instagib ^1";
338 else if(cvar("g_rocketarena"))
339 mutator = "^2Rocketarena ^1";
341 if(cvar("g_midair")) {
342 // to protect against unheedingly made changes
344 modifications = strcat(modifications, ", ");
346 modifications = "midair";
348 if(cvar("g_vampire")) {
350 modifications = strcat(modifications, ", ");
352 modifications = strcat(modifications, "vampire");
354 if(cvar("g_laserguided_missile")) {
356 modifications = strcat(modifications, ", ");
358 modifications = strcat(modifications, "laser-guided-missiles");
361 local string versionmessage;
362 versionmessage = GetClientVersionMessage(self.version);
364 s = strcat(s, newlines, "This is Nexuiz ", cvar_string("g_nexuizversion"), "\n", versionmessage);
365 s = strcat(s, "^8\n\nmatch type is ^1", mutator, gamemode_name, "^8\n");
367 if(modifications != "")
368 s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
370 if((self.classname == "observer" || self.classname == "spectator") && self.version == cvar("gameversion")) {
372 s = strcat(s,"^7\n\n\npress jump to play\npress attack to spectate other players\n\n");
373 else if(player_count < 2 && arena_roundbased)
375 s = strcat(s, "\n\n\n^1waiting for second player to start match^7\n\n");
379 s = strcat(s, "\n\n\n");
381 s = strcat(s, "^7current champion is: ", champion.netname, "\n\n");
382 s = strcat(s,"^7press attack to spectate other players\n\n");
389 if (cvar("g_grappling_hook"))
390 s = strcat(s, "\n\n^8grappling hook is enabled, press 'e' to use it\n");
392 if (cvar_string("_mutatormsg") != "") {
393 s = strcat(s, "\n\n^8special gameplay tips: ^7", cvar_string("_mutatormsg"));
396 if (cvar_string("_motd") != "") {
397 s = strcat(s, "\n\n^8MOTD: ^7", cvar_string("_motd"));
409 void SetPlayerColors(entity pl, float _color)
413 stuffcmd(pl, strcat("color ", s, " ", s, "\n") );
415 //pl.clientcolors = pl.clientcolors - (pl.clientcolors & 15) + cl;
416 pl.clientcolors = 16*cl + cl;*/
419 pants = _color & 0x0F;
420 shirt = _color & 0xF0;
424 setcolor(pl, 16*pants + pants);
426 setcolor(pl, shirt + pants);
430 void SetPlayerTeam(entity pl, float t, float s, float noprint)
435 _color = COLOR_TEAM4 - 1;
437 _color = COLOR_TEAM3 - 1;
439 _color = COLOR_TEAM2 - 1;
441 _color = COLOR_TEAM1 - 1;
443 SetPlayerColors(pl,_color);
445 if(!noprint && t != s)
447 //bprint(strcat(pl.netname, " has changed to ", TeamNoName(t), "\n"));
448 bprint(strcat(pl.netname, "^7 has changed from ", TeamNoName(s), " to ", TeamNoName(t), "\n"));
460 // set c1...c4 to show what teams are allowed
461 void CheckAllowedTeams ()
470 c1 = c2 = c3 = c4 = -1;
471 cb1 = cb2 = cb3 = cb4 = 0;
474 teament_name = "dom_team";
476 teament_name = "ctf_team";
478 teament_name = "tdm_team";
481 // cover anything else by treating it like tdm with no teams spawned
482 dm = cvar("g_tdm_teams");
484 error("g_tdm_teams < 2, not enough teams to play team deathmatch\n");
488 c1 = c2 = c3 = c4 = 0;
501 // first find out what teams are allowed
502 head = find(world, classname, teament_name);
505 if(!(g_domination && head.netname == ""))
507 if(head.team == COLOR_TEAM1)
511 if(head.team == COLOR_TEAM2)
515 if(head.team == COLOR_TEAM3)
519 if(head.team == COLOR_TEAM4)
524 head = find(head, classname, teament_name);
528 // c1...c4 should be set to -1 (not allowed) or 0 (allowed).
529 // teams that are allowed will now have their player counts stored in c1...c4
530 void GetTeamCounts(entity ignore)
533 // now count how many players are on each team already
535 // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
536 // also remember the lowest-scoring player
538 head = find(world, classname, "player");
541 if(head != ignore)// && head.netname != "")
543 if(head.team == COLOR_TEAM1)
551 if(head.team == COLOR_TEAM2)
559 if(head.team == COLOR_TEAM3)
567 if(head.team == COLOR_TEAM4)
576 head = find(head, classname, "player");
580 // returns # of smallest team (1, 2, 3, 4)
581 // NOTE: Assumes CheckAllowedTeams has already been called!
582 float FindSmallestTeam(entity pl, float ignore_pl)
584 float totalteams, smallestteam, smallestteam_count, balance_type;
587 // find out what teams are available
588 //CheckAllowedTeams();
590 // make sure there are at least 2 teams to join
592 totalteams = totalteams + 1;
594 totalteams = totalteams + 1;
596 totalteams = totalteams + 1;
598 totalteams = totalteams + 1;
603 error("Too few teams available for domination\n");
605 error("Too few teams available for ctf\n");
607 error("Too few teams available for team deathmatch\n");
611 // count how many players are in each team
615 GetTeamCounts(world);
617 // c1...c4 now have counts of each team
618 // figure out which is smallest, giving priority to the team the player is already on as a tie-breaker
621 smallestteam_count = 999;
623 // 2 gives priority to what team you're already on, 1 goes in order
624 // 2 doesn't seem to work though...
627 if(balance_type == 1)
629 if(c1 >= 0 && c1 < smallestteam_count)
632 smallestteam_count = c1;
634 if(c2 >= 0 && c2 < smallestteam_count)
637 smallestteam_count = c2;
639 if(c3 >= 0 && c3 < smallestteam_count)
642 smallestteam_count = c3;
644 if(c4 >= 0 && c4 < smallestteam_count)
647 smallestteam_count = c4;
652 if(c1 >= 0 && (c1 < smallestteam_count ||
653 (c1 == smallestteam_count && self.team == COLOR_TEAM1) ) )
656 smallestteam_count = c1;
658 if(c2 >= 0 && c2 < (c2 < smallestteam_count ||
659 (c2 == smallestteam_count && self.team == COLOR_TEAM2) ) )
662 smallestteam_count = c2;
664 if(c3 >= 0 && c3 < (c3 < smallestteam_count ||
665 (c3 == smallestteam_count && self.team == COLOR_TEAM3) ) )
668 smallestteam_count = c3;
670 if(c4 >= 0 && c4 < (c4 < smallestteam_count ||
671 (c4 == smallestteam_count && self.team == COLOR_TEAM4) ) )
674 smallestteam_count = c4;
681 float JoinBestTeam(entity pl, float only_return_best)
683 float smallest, selectedteam;
685 g_domination = cvar("g_domination");
686 g_ctf = cvar("g_ctf");
688 // don't join a team if we're not playing a team game
689 if(!cvar("teamplay") && !g_domination && !g_ctf)
692 // find out what teams are available
695 if(cvar("g_domination"))
697 if(cvar("g_domination_default_teams") < 3)
699 if(cvar("g_domination_default_teams") < 4)
703 // if we don't care what team he ends up on, put him on whatever team he entered as.
704 // if he's not on a valid team, then let other code put him on the smallest team
705 if(!cvar("g_campaign") && !cvar("g_balance_teams") && !cvar("g_balance_teams_force"))
707 if( c1 >= 0 && pl.team == COLOR_TEAM1)
708 selectedteam = pl.team;
709 else if(c2 >= 0 && pl.team == COLOR_TEAM2)
710 selectedteam = pl.team;
711 else if(c3 >= 0 && pl.team == COLOR_TEAM3)
712 selectedteam = pl.team;
713 else if(c4 >= 0 && pl.team == COLOR_TEAM4)
714 selectedteam = pl.team;
719 if(!only_return_best)
721 SetPlayerColors(pl, selectedteam - 1);
726 // otherwise end up on the smallest team (handled below)
729 smallest = FindSmallestTeam(pl, TRUE);
732 if(!only_return_best)
736 SetPlayerColors(pl, COLOR_TEAM1 - 1);
738 else if(smallest == 2)
740 SetPlayerColors(pl, COLOR_TEAM2 - 1);
742 else if(smallest == 3)
744 SetPlayerColors(pl, COLOR_TEAM3 - 1);
746 else if(smallest == 4)
748 SetPlayerColors(pl, COLOR_TEAM4 - 1);
752 error("smallest team: invalid team\n");
755 if(pl.deadflag == DEAD_NO)
756 Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE, pl.origin, '0 0 0');
763 void SV_ChangeTeam(float _color)
765 float scolor, dcolor, steam, dteam, dbotcount, scount, dcount;
767 // in normal deathmatch we can just apply the color and we're done
768 if(!cvar("teamplay")) {
769 SetPlayerColors(self, _color);
773 scolor = self.clientcolors & 0x0F;
774 dcolor = _color & 0x0F;
776 if(scolor == COLOR_TEAM1 - 1)
778 else if(scolor == COLOR_TEAM2 - 1)
780 else if(scolor == COLOR_TEAM3 - 1)
782 else if(scolor == COLOR_TEAM4 - 1)
784 if(dcolor == COLOR_TEAM1 - 1)
786 else if(dcolor == COLOR_TEAM2 - 1)
788 else if(dcolor == COLOR_TEAM3 - 1)
790 else if(dcolor == COLOR_TEAM4 - 1)
793 // remap invalid teams in dom & ctf
794 if(cvar("g_ctf") && dteam == 3)
796 else if(cvar("g_ctf") && dteam == 4)
798 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 3) || (cvar("g_tdm") && cvar("g_tdm_teams") < 3))
805 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 4) || (cvar("g_tdm") && cvar("g_tdm_teams") < 4))
811 // not changing teams
814 //bprint("same team change\n");
815 SetPlayerTeam(self, dteam, steam, TRUE);
821 if(cvar("g_campaign") || cvar("g_changeteam_banned"))
823 sprint(self, "Team changes not allowed\n");
824 return; // changing teams is not allowed
827 if(!cvar("g_campaign") && cvar("g_balance_teams_prevent_imbalance"))
829 // only allow changing to a smaller or equal size team
831 // find out what teams are available
833 // count how many players on each team
834 GetTeamCounts(world);
837 if(dteam == 1 && c1 >= 0)//dcolor == COLOR_TEAM1 - 1)
842 else if(dteam == 2 && c2 >= 0)//dcolor == COLOR_TEAM2 - 1)
847 else if(dteam == 3 && c3 >= 0)//dcolor == COLOR_TEAM3 - 1)
852 else if(dteam == 4 && c4 >= 0)//dcolor == COLOR_TEAM4 - 1)
859 sprint(self, "Cannot change to an invalid team\n");
865 if(steam == 1)//scolor == COLOR_TEAM1 - 1)
867 else if(steam == 2)//scolor == COLOR_TEAM2 - 1)
869 else if(steam == 3)//scolor == COLOR_TEAM3 - 1)
871 else if(steam == 4)//scolor == COLOR_TEAM4 - 1)
874 if(scount) // started at a valid, nonempty team
876 // check if we're trying to change to a larger team that doens't have bots to swap with
877 if(dcount >= scount && dbotcount <= 0)
879 sprint(self, "Cannot change to a larger team\n");
880 return; // can't change to a larger team
886 // bprint(strcat("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n"));
888 SetPlayerTeam(self, dteam, steam, FALSE);
889 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
891 // kill player when changing teams
892 if(self.deadflag == DEAD_NO)
893 Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
894 // reduce frags during a team change
895 self.frags = floor(self.frags * (cvar("g_changeteam_fragtransfer") / 100));
900 void ShufflePlayerOutOfTeam (float source_team)
902 float smallestteam, smallestteam_count, steam;
903 float lowest_bot_score, lowest_player_score;
904 entity head, lowest_bot, lowest_player, selected;
908 smallestteam_count = 999;
910 if(c1 >= 0 && c1 < smallestteam_count)
913 smallestteam_count = c1;
915 if(c2 >= 0 && c2 < smallestteam_count)
918 smallestteam_count = c2;
920 if(c3 >= 0 && c3 < smallestteam_count)
923 smallestteam_count = c3;
925 if(c4 >= 0 && c4 < smallestteam_count)
928 smallestteam_count = c4;
933 bprint("warning: no smallest team\n");
939 else if(source_team == 2)
941 else if(source_team == 3)
943 else if(source_team == 4)
947 lowest_bot_score = 9999;
948 lowest_player = world;
949 lowest_player_score = 9999;
951 // find the lowest-scoring player & bot of that team
952 head = find(world, classname, "player");
955 if(head.team == steam)
959 if(head.frags < lowest_bot_score)
962 lowest_bot_score = head.frags;
967 if(head.frags < lowest_player_score)
969 lowest_player = head;
970 lowest_player_score = head.frags;
974 head = find(head, classname, "player");
977 // prefers to move a bot...
978 if(lowest_bot != world)
979 selected = lowest_bot;
980 // but it will move a player if it has to
982 selected = lowest_player;
983 // don't do anything if it couldn't find anyone
986 bprint("warning: couldn't find a player to move from team\n");
990 // smallest team gains a member
991 if(smallestteam == 1)
995 else if(smallestteam == 2)
999 else if(smallestteam == 3)
1003 else if(smallestteam == 4)
1009 bprint("warning: destination team invalid\n");
1012 // source team loses a member
1013 if(source_team == 1)
1017 else if(source_team == 2)
1021 else if(source_team == 3)
1025 else if(source_team == 4)
1031 bprint("warning: source team invalid\n");
1035 // move the player to the new team
1036 SetPlayerTeam(selected, smallestteam, source_team, FALSE);
1038 if(selected.deadflag == DEAD_NO)
1039 Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0');
1040 m = "You have been moved into a different team to improve team balance\nYou are now on: ";
1041 if (selected.team == 5)
1042 m = strcat(m, "^1Red Team");
1043 else if (selected.team == 14)
1044 m = strcat(m, "^4Blue Team");
1045 else if (selected.team == 10)
1046 m = strcat(m, "^6Pink Team");
1047 else if (selected.team == 13)
1048 m = strcat(m, "^3Yellow Team");
1049 centerprint(selected, m);
1052 // part of g_balance_teams_force
1053 // occasionally perform an audit of the teams to make
1054 // sure they're more or less balanced in player count.
1057 float numplayers, numteams, average;
1058 if(cvar("g_campaign"))
1060 if(!cvar("g_balance_teams_force"))
1062 if(!cvar("teamplay"))
1065 if(audit_teams_time > time)
1068 audit_teams_time = time + 4 + random();
1070 // bprint("Auditing teams\n");
1072 CheckAllowedTeams();
1073 GetTeamCounts(world);
1076 numteams = numplayers = 0;
1079 numteams = numteams + 1;
1080 numplayers = numplayers + c1;
1084 numteams = numteams + 1;
1085 numplayers = numplayers + c2;
1089 numteams = numteams + 1;
1090 numplayers = numplayers + c3;
1094 numteams = numteams + 1;
1095 numplayers = numplayers + c4;
1099 return; // no players to move around
1101 return; // don't bother shuffling if for some reason there aren't any teams
1103 average = ceil(numplayers / numteams);
1106 return; // that's weird...
1108 if(c1 && c1 > average)
1110 bprint("Rebalancing Teams\n");
1111 //bprint("Shuffle from team 1\n");
1112 ShufflePlayerOutOfTeam(1);
1114 if(c2 && c2 > average)
1116 bprint("Rebalancing Teams\n");
1117 //bprint("Shuffle from team 2\n");
1118 ShufflePlayerOutOfTeam(2);
1120 if(c3 && c3 > average)
1122 bprint("Rebalancing Teams\n");
1123 //bprint("Shuffle from team 3\n");
1124 ShufflePlayerOutOfTeam(3);
1126 if(c4 && c4 > average)
1128 bprint("Rebalancing Teams\n");
1129 //bprint("Shuffle from team 4\n");
1130 ShufflePlayerOutOfTeam(4);
1133 // if teams are still unbalanced, balance them further in the next audit,
1134 // which will happen sooner (keep doing rapid audits until things are in order)
1135 audit_teams_time = time + 0.7 + random()*0.3;
1140 /*void(entity e, float first) UpdateTeamScore =
1145 WriteByte (MSG_ALL, SVC_UPDATENAME);
1146 WriteByte (MSG_ALL, clientno);
1147 WriteString (MSG_ALL, e.netname);
1149 WriteByte (MSG_ALL, SVC_UPDATECOLORS);
1150 WriteByte (MSG_ALL, clientno);
1151 WriteByte (MSG_ALL, e.b_shirt * 16 + who.b_pants);
1154 WriteByte (MSG_ALL, SVC_UPDATEFRAGS);
1155 WriteByte (MSG_ALL, clientno);
1156 WriteShort (MSG_ALL, e.frags + 10000);
1162 // code from here on is just to support maps that don't have team entities
1163 void tdm_spawnteam (string teamname, float teamcolor)
1167 e.classname = "tdm_team";
1168 e.netname = teamname;
1173 // spawn some default teams if the map is not set up for tdm
1174 void() tdm_spawnteams =
1178 numteams = cvar("g_tdm_teams");
1180 tdm_spawnteam("Red", 4);
1181 tdm_spawnteam("Blue", 13);
1184 void() tdm_delayedinit =
1186 self.think = SUB_Remove;
1187 self.nextthink = time;
1188 // if no teams are found, spawn defaults
1189 if (find(world, classname, "tdm_team") == world)
1197 e.think = tdm_delayedinit;
1198 e.nextthink = time + 0.1;