3 float Nagger_SendEntity(entity to, float sendflags)
7 WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER);
28 WriteByte(MSG_ENTITY, nags);
33 WriteString(MSG_ENTITY, votecalledvote_display);
35 WriteString(MSG_ENTITY, "");
40 for(i = 1; i <= maxclients; i += 8)
42 for(f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e))
43 if(clienttype(e) != CLIENTTYPE_REAL || e.ready)
45 WriteByte(MSG_ENTITY, f);
53 Net_LinkEntity(nagger = spawn(), FALSE, 0, Nagger_SendEntity);
55 void Nagger_VoteChanged()
58 nagger.SendFlags |= 128;
60 void Nagger_VoteCountChanged()
63 nagger.SendFlags |= 1;
65 void Nagger_ReadyCounted()
68 nagger.SendFlags |= 1;
72 string MapVote_Suggest(string m);
74 entity GetPlayer(string name)
80 if(substring(name, 0, 1) == "#") {
81 num = stof(substring(name, 1, 999));
82 if(num >= 1 && num <= maxclients) {
83 for((e = world); num > 0; --num, (e = nextent(e)))
85 //if(clienttype(e) == CLIENTTYPE_REAL)
86 if(e.classname == "player")
90 ns = strdecolorize(name);
91 FOR_EACH_REALPLAYER(e) {
92 if(!strcasecmp(strdecolorize(e.netname), ns)) {
103 if(self.aiment && self.enemy)
105 self.origin_x = (self.aiment.origin_x + self.enemy.origin_x) * 0.5;
106 self.origin_y = (self.aiment.origin_y + self.enemy.origin_y) * 0.5;
107 self.origin_z = (self.aiment.origin_z + self.enemy.origin_z) * 0.5;
108 self.maxs_x = fabs(self.aiment.origin_x - self.enemy.origin_x) * 0.5;
109 self.maxs_y = fabs(self.aiment.origin_y - self.enemy.origin_y) * 0.5;
110 self.maxs_z = fabs(self.aiment.origin_z - self.enemy.origin_z) * 0.5;
111 self.mins = -1 * self.maxs;
112 setorigin(self, self.origin); setsize(self, self.mins, self.maxs); // link edict
115 if(self.cnt == -1) // actually race_place -1
117 // show "10 10" for qualifying spawns
118 setmodel(self.killindicator, "models/sprites/10.spr32");
119 setmodel(self.killindicator.killindicator, "models/sprites/10.spr32");
121 else if(self.cnt == -2) // actually race_place 0
123 // show "10 0" for loser spawns
124 setmodel(self.killindicator, "models/sprites/10.spr32");
125 setmodel(self.killindicator.killindicator, "models/sprites/0.spr32");
129 setmodel(self.killindicator, strcat("models/sprites/", ftos(mod(self.cnt, 10)), ".spr32"));
130 setmodel(self.killindicator.killindicator, strcat("models/sprites/", ftos(floor(self.cnt / 10)), ".spr32"));
133 self.nextthink = time;
136 //float ctf_clientcommand();
137 float readyrestart_happened;
138 .float lms_spectate_warning;
139 void spawnfunc_func_breakable();
141 .float cmd_floodtime;
142 .float cmd_floodcount;
143 float cmd_floodcheck()
145 if (timeoutStatus != 2)
147 if(time == self.cmd_floodtime)
149 self.cmd_floodcount += 1;
150 if(self.cmd_floodcount > 8)
155 self.cmd_floodtime = time;
156 self.cmd_floodcount = 1;
162 void SV_ParseClientCommand(string s) {
164 float tokens, f, effectnum;
168 tokens = tokenize_console(s);
171 if(cmd != "reportcvar")
172 if(cmd != "sentcvar")
174 if(cmd != "prespawn")
182 if(GameCommand_Vote(s, self)) {
184 } else if(GameCommand_MapVote(argv(0))) {
186 } else if(cmd == "autoswitch") {
187 // be backwards compatible with older clients (enabled)
188 self.autoswitch = ("0" != argv(1));
189 local string autoswitchmsg;
190 if (self.autoswitch) {
191 autoswitchmsg = "on";
193 autoswitchmsg = "off";
195 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
196 } else if(cmd == "clientversion") {
197 if not(self.flags & FL_CLIENT)
199 if (argv(1) == "$gameversion") {
200 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
201 // either that or someone wants to be funny
204 self.version = stof(argv(1));
206 if(self.version != cvar("gameversion"))
208 self.classname = "observer";
209 self.version_mismatch = 1;
211 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
212 //JoinBestTeam(self, FALSE, TRUE);
213 } else if(teams_matter && !cvar("sv_spectate")) {
214 self.classname = "observer";
215 stuffcmd(self,"menu_showteamselect\n");
217 } else if(cmd == "reportcvar") { // old system
218 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
220 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
221 tokens = tokenize_console(s);
224 } else if(cmd == "sentcvar") { // new system
225 if(tokens == 2) // undefined cvar: use the default value on the server then
227 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
228 tokens = tokenize_console(s);
231 } else if(cmd == "spectate") {
234 if not(self.flags & FL_CLIENT)
240 if(self.lms_spectate_warning)
242 // mark player as spectator
243 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
247 self.lms_spectate_warning = 1;
248 sprint(self, "WARNING: you won't be able to enter the game again after spectating in LMS. Use the same command again to spectate anyway.\n");
252 if(self.classname == "player" && cvar("sv_spectate") == 1) {
254 DropFlag(self.flagcarried, world, world);
256 DropBall(self.ballcarried, self.origin, self.velocity);
257 kh_Key_DropAll(self, TRUE);
258 WaypointSprite_PlayerDead();
259 self.classname = "observer";
263 sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
266 } else if(cmd == "join") {
267 if not(self.flags & FL_CLIENT)
270 if (self.classname != "player" && !lockteams)
272 if(isJoinAllowed()) {
273 self.classname = "player";
276 PlayerScore_Clear(self);
277 bprint ("^4", self.netname, "^4 is playing now\n");
279 if(cvar("g_campaign"))
280 campaign_bots_may_start = 1;
283 //player may not join because of g_maxplayers is set
284 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
287 } else if( cmd == "selectteam" ) {
288 if not(self.flags & FL_CLIENT)
290 if( !teams_matter ) {
291 sprint( self, "selecteam can only be used in teamgames\n");
292 } else if(cvar("g_campaign")) {
293 //JoinBestTeam(self, 0);
294 } else if(lockteams) {
295 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
296 } else if( argv(1) == "red" ) {
297 DoTeamChange(COLOR_TEAM1);
298 } else if( argv(1) == "blue" ) {
299 DoTeamChange(COLOR_TEAM2);
300 } else if( argv(1) == "yellow" ) {
301 DoTeamChange(COLOR_TEAM3);
302 } else if( argv(1) == "pink" ) {
303 DoTeamChange(COLOR_TEAM4);
304 } else if( argv(1) == "auto" ) {
307 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
309 } else if(cmd == "ready") {
310 if not(self.flags & FL_CLIENT)
313 if((inWarmupStage && 0 >= g_warmup_limit) // with unlimited warmup players have to be able to restart
314 || cvar("sv_ready_restart") || g_race_qualifying == 2)
316 if(!readyrestart_happened || cvar("sv_ready_restart_repeatable"))
318 if (self.ready) // toggle
321 bprint(self.netname, "^2 is ^1NOT^2 ready\n");
326 bprint(self.netname, "^2 is ready\n");
329 // cannot reset the game while a timeout is active!
333 sprint(self, "^1Game has already been restarted\n");
336 } else if(cmd == "maplist") {
337 sprint(self, maplist_reply);
338 } else if(cmd == "lsmaps") {
339 sprint(self, lsmaps_reply);
340 } else if(cmd == "records") {
341 sprint(self, records_reply);
342 } else if(cmd == "voice") {
344 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
346 VoiceMessage(argv(1), "");
347 } else if(cmd == "say") {
349 Say(self, FALSE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
350 //clientcommand(self, formatmessage(s));
351 } else if(cmd == "say_team") {
353 Say(self, TRUE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
354 //clientcommand(self, formatmessage(s));
355 } else if(cmd == "tell") {
356 e = GetCommandPlayerSlotTargetFromTokenizedCommand(tokens, 1);
357 if(e && tokens > ParseCommandPlayerSlotTarget_firsttoken)
359 Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
363 if(tokens > ParseCommandPlayerSlotTarget_firsttoken)
364 trigger_magicear_processmessage_forallears(self, -1, world, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
365 sprint(self, "ERROR: usage: tell # playerid text...\n");
367 //clientcommand(self, formatmessage(s));
368 } else if(cmd == "info") {
369 cmd = cvar_string(strcat("sv_info_", argv(1)));
371 sprint(self, "ERROR: unsupported info command\n");
373 wordwrap_sprint(cmd, 1111);
374 } else if(cmd == "suggestmap") {
375 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
376 } else if(cmd == "timeout") {
377 if not(self.flags & FL_CLIENT)
379 if(cvar("sv_timeout")) {
380 if(self.classname == "player") {
382 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
387 sprint(self, "^7Error: only players can call a timeout!\n");
389 } else if(cmd == "timein") {
390 if not(self.flags & FL_CLIENT)
392 if(cvar("sv_timeout")) {
395 } else if(cmd == "teamstatus") {
396 Score_NicePrint(self);
397 } else if(cmd == "cvar_changes") {
398 sprint(self, cvar_changes);
399 } else if(cmd == "pointparticles") {
400 if((sv_cheats || self.maycheat) && tokens == 5)
404 // origin (0..1, on crosshair line)
407 effectnum = particleeffectnum(argv(1));
409 start = (1-f) * self.origin + f * self.cursor_trace_endpos;
412 pointparticles(effectnum, start, end, f);
415 sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
416 } else if(cmd == "trailparticles") {
417 if((sv_cheats || self.maycheat) && tokens == 2)
421 effectnum = particleeffectnum(argv(1));
422 W_SetupShot(self, FALSE, FALSE, "",0);
423 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
424 trailparticles(self, effectnum, w_shotorg, trace_endpos);
427 sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
428 } else if(cmd == "make") {
429 if((sv_cheats || self.maycheat) && tokens == 3)
434 W_SetupShot(self, FALSE, FALSE, "", 0);
435 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, self);
436 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
438 sprint(self, "cannot make stuff there (bad surface)\n");
444 self.model = strzone(argv(1));
445 self.mdl = "rocket_explode";
447 setorigin(self, trace_endpos);
448 self.effects = EF_NOMODELFLAGS;
451 self.angles = fixedvectoangles2(trace_plane_normal, v_forward);
452 self.angles = AnglesTransform_Multiply(self.angles, '-90 0 0'); // so unrotated models work
454 spawnfunc_func_breakable();
458 tracebox(self.origin, self.mins, self.maxs, self.origin, MOVE_NORMAL, self);
461 sprint(oldself, "cannot make stuff there (no space)\n");
469 sprint(self, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
470 } else if(cmd == "penalty") {
471 if((sv_cheats || self.maycheat) && tokens == 3)
472 race_ImposePenaltyTime(self, stof(argv(1)), argv(2));
474 sprint(self, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
475 } else if(cmd == "dragbox_spawn") {
476 if(sv_cheats || self.maycheat)
479 e.classname = "dragbox_box";
480 e.think = DragBox_Think;
482 e.solid = -1; // black
483 setmodel(e, "null"); // network it
485 e.cnt = stof(argv(1));
487 e.cnt = max(0, drag_lastcnt);
490 e.aiment.classname = "dragbox_corner_1";
492 setmodel(e.aiment, "models/marker.md3");
494 setsize(e.aiment, '0 0 0', '0 0 0');
496 setorigin(e.aiment, stov(argv(2)));
498 setorigin(e.aiment, self.cursor_trace_endpos);
501 e.enemy.classname = "dragbox_corner_2";
503 setmodel(e.enemy, "models/marker.md3");
505 setsize(e.enemy, '0 0 0', '0 0 0');
506 end = normalize(self.cursor_trace_start - e.aiment.origin);
507 end_x = (end_x > 0) * 2 - 1;
508 end_y = (end_y > 0) * 2 - 1;
509 end_z = (end_z > 0) * 2 - 1;
511 setorigin(e.enemy, stov(argv(3)));
513 setorigin(e.enemy, e.aiment.origin + 32 * end);
515 e.killindicator = spawn();
516 e.killindicator.classname = "drag_digit";
517 e.killindicator.owner = e;
518 setattachment(e.killindicator, e, "");
519 setorigin(e.killindicator, '0 0 -8');
520 e.killindicator.killindicator = spawn();
521 e.killindicator.killindicator.classname = "drag_digit";
522 e.killindicator.killindicator.owner = e;
523 setattachment(e.killindicator.killindicator, e, "");
524 setorigin(e.killindicator.killindicator, '0 0 8');
527 sprint(self, "Usage: sv_cheats 1; r_showbboxes 1.5; restart; cmd dragbox_spawn\n");
528 } else if(cmd == "dragpoint_spawn") {
529 if(sv_cheats || self.maycheat)
532 e.classname = "dragpoint";
533 e.think = DragBox_Think;
535 e.solid = 0; // nothing special
536 setmodel(e, "models/marker.md3");
537 setsize(e, PL_MIN, PL_MAX);
540 e.cnt = stof(argv(1));
542 e.cnt = drag_lastcnt;
544 setorigin(e, stov(argv(2)));
547 setorigin(e, self.cursor_trace_endpos + normalize(self.cursor_trace_start - self.cursor_trace_endpos));
548 move_out_of_solid(e);
551 e.killindicator = spawn();
552 e.killindicator.classname = "drag_digit";
553 e.killindicator.owner = e;
554 setattachment(e.killindicator, e, "");
555 setorigin(e.killindicator, '0 0 40');
556 e.killindicator.killindicator = spawn();
557 e.killindicator.killindicator.classname = "drag_digit";
558 e.killindicator.killindicator.owner = e;
559 setattachment(e.killindicator.killindicator, e, "");
560 setorigin(e.killindicator.killindicator, '0 0 56');
563 sprint(self, "Usage: sv_cheats 1; r_showbboxes 1.5; restart; cmd dragbox_spawn\n");
564 } else if(cmd == "drag_remove") {
565 if(sv_cheats || self.maycheat)
567 RandomSelection_Init();
568 for(e = world; (e = find(e, classname, "dragbox_box")); )
569 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
570 for(e = world; (e = find(e, classname, "dragpoint")); )
571 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
572 if(RandomSelection_chosen_ent)
574 remove(RandomSelection_chosen_ent.killindicator.killindicator);
575 remove(RandomSelection_chosen_ent.killindicator);
576 if(RandomSelection_chosen_ent.aiment)
577 remove(RandomSelection_chosen_ent.aiment);
578 if(RandomSelection_chosen_ent.enemy)
579 remove(RandomSelection_chosen_ent.enemy);
580 remove(RandomSelection_chosen_ent);
584 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_remove\n");
585 } else if(cmd == "drag_setcnt") {
586 if((sv_cheats || self.maycheat) && tokens >= 2)
588 RandomSelection_Init();
589 for(e = world; (e = find(e, classname, "dragbox_box")); )
590 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
591 for(e = world; (e = find(e, classname, "dragpoint")); )
592 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
593 if(RandomSelection_chosen_ent)
595 if(substring(argv(1), 0, 1) == "*")
596 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
598 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
602 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
603 } else if(cmd == "drag_save") {
604 if((sv_cheats || self.maycheat) && tokens >= 2)
606 f = fopen(argv(1), FILE_WRITE);
607 fputs(f, "cmd drag_clear\n");
608 for(e = world; (e = find(e, classname, "dragbox_box")); )
610 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
612 for(e = world; (e = find(e, classname, "dragpoint")); )
614 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
619 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
620 } else if(cmd == "drag_saveraceent") {
621 if((sv_cheats || self.maycheat) && tokens >= 2)
623 f = fopen(argv(1), FILE_WRITE);
624 for(e = world; (e = find(e, classname, "dragbox_box")); )
627 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
628 fputs(f, strcat("\"origin\" \"", ftos(e.absmin_x), " ", ftos(e.absmin_y), " ", ftos(e.absmin_z), "\"\n"));
629 fputs(f, strcat("\"maxs\" \"", ftos(e.absmax_x - e.absmin_x), " ", ftos(e.absmax_y - e.absmin_y), " ", ftos(e.absmax_z - e.absmin_z), "\"\n"));
630 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
631 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
634 for(e = world; (e = find(e, classname, "dragpoint")); )
638 for(oldself = world; (oldself = find(oldself, classname, "dragbox_box")); )
640 if(e.cnt <= 0 && oldself.cnt == 0 || e.cnt == oldself.cnt)
642 start = start + oldself.origin;
646 start *= 1 / effectnum;
648 fputs(f, "\"classname\" \"info_player_race\"\n");
649 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
650 fputs(f, strcat("\"origin\" \"", ftos(e.origin_x), " ", ftos(e.origin_y), " ", ftos(e.origin_z), "\"\n"));
653 fputs(f, "\"target\" \"checkpoint0\"\n");
654 fputs(f, "\"race_place\" \"0\"\n");
658 fputs(f, "\"target\" \"checkpoint0\"\n");
659 fputs(f, "\"race_place\" \"-1\"\n");
663 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
666 // these need race_place
669 for(oldself = world; (oldself = find(oldself, classname, "dragpoint")); )
672 if(vlen(oldself.origin - start) < vlen(e.origin - start))
674 else if(vlen(oldself.origin - start) == vlen(e.origin - start) && num_for_edict(oldself) < num_for_edict(e))
677 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
685 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
686 } else if(cmd == "drag_clear") {
687 if(sv_cheats || self.maycheat)
689 for(e = world; (e = find(e, classname, "dragbox_box")); )
691 for(e = world; (e = find(e, classname, "dragbox_corner_1")); )
693 for(e = world; (e = find(e, classname, "dragbox_corner_2")); )
695 for(e = world; (e = find(e, classname, "dragpoint")); )
697 for(e = world; (e = find(e, classname, "drag_digit")); )
701 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_clear\n");
703 //if(ctf_clientcommand())
705 // grep for Cmd_AddCommand_WithClientCommand to find them all
713 if(cmd != "notarget")
717 //if(cmd != "say") // handled above
718 //if(cmd != "say_team") // handled above
726 if(cmd != "playermodel")
727 if(cmd != "playerskin")
728 if(cmd != "prespawn")
732 if(cmd != "sv_startdownload")
733 if(cmd != "download")
735 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
739 if(self.jointime > 0 && time > self.jointime + 10 && time > self.nickspamtime) // allow any changes in the first 10 seconds since joining
740 if(cmd == "name" || cmd == "playermodel") // TODO also playerskin and color?
742 if(self.nickspamtime == 0 || time > self.nickspamtime + cvar("g_nick_flood_timeout"))
743 // good, no serious flood
744 self.nickspamcount = 1;
746 self.nickspamcount += 1;
747 self.nickspamtime = time + cvar("g_nick_flood_penalty");
749 if (timeoutStatus == 2) //when game is paused, no flood protection
750 self.nickspamcount = self.nickspamtime = 0;
753 clientcommand(self,s);
757 void ReadyRestartForce()
761 bprint("^1Server is restarting...\n");
766 if (checkrules_overtimesadded > 0 && g_race_qualifying != 2) {
767 //we have to decrease timelimit to its original value again!!
769 newTL = cvar("timelimit");
770 newTL -= checkrules_overtimesadded * cvar("timelimit_overtime");
771 cvar_set("timelimit", ftos(newTL));
774 checkrules_suddendeathend = checkrules_overtimesadded = checkrules_suddendeathwarning = 0;
777 readyrestart_happened = 1;
778 game_starttime = time + RESTART_COUNTDOWN;
779 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
781 inWarmupStage = 0; //once the game is restarted the game is in match stage
783 //reset the .ready status of all players (also spectators)
784 FOR_EACH_CLIENTSLOT(e)
787 Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
789 if(cvar("teamplay_lockonrestart") && teams_matter) {
791 bprint("^1The teams are now locked.\n");
794 //initiate the restart-countdown-announcer entity
795 if(cvar("sv_ready_restart_after_countdown"))
797 restartTimer = spawn();
798 restartTimer.think = restartTimer_Think;
799 restartTimer.nextthink = game_starttime;
802 //after a restart every players number of allowed timeouts gets reset, too
803 if(cvar("sv_timeout"))
805 FOR_EACH_REALPLAYER(e)
806 e.allowedTimeouts = cvar("sv_timeout_number");
809 //reset map immediately if this cvar is not set
810 if (!cvar("sv_ready_restart_after_countdown"))
813 if(cvar("sv_eventlog"))
814 GameLogEcho(":restart");
819 // no arena, assault support yet...
821 if(g_arena | g_ca | g_assault | gameover | intermission_running | race_completing)
822 localcmd("restart\n");
824 localcmd("\nsv_hook_gamerestart;");
828 // reset ALL scores, but only do that at the beginning
829 //of the countdown if sv_ready_restart_after_countdown is off!
830 //Otherwise scores could be manipulated during the countdown!
831 if (!cvar("sv_ready_restart_after_countdown"))
836 * Counts how many players are ready. If not enough players are ready, the function
837 * does nothing. If all players are ready, the timelimit will be extended and the
838 * restart_countdown variable is set to allow other functions like PlayerPostThink
839 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
840 * is not set the map will be resetted.
842 * Function is called after the server receives a 'ready' sign from a player.
851 FOR_EACH_REALPLAYER(e)
860 Nagger_ReadyCounted();
862 if(r) // at least one is ready
863 if(r == p) // and, everyone is ready
868 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
871 void restartTimer_Think() {
872 restart_mapalreadyrestarted = 1;
880 * Checks whether the player who calls the timeout is allowed to do so.
881 * If so, it initializes the timeout countdown. It also checks whether another
882 * timeout was already running at this time and reacts correspondingly.
884 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
885 * timeoutInitiator, timeoutStatus, timeoutHandler
887 * This function is called when a player issues the calltimeout command.
889 void evaluateTimeout() {
890 if (inWarmupStage && !g_warmup_allow_timeout)
891 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
892 if (time < game_starttime )
893 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
894 if (timeoutStatus != 2) {
895 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
896 if (cvar("timelimit")) {
897 //a timelimit was used
899 myTl = cvar("timelimit");
901 local float lastPossibleTimeout;
902 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
904 if (lastPossibleTimeout < time - game_starttime)
905 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
908 //player may not call a timeout if he has no calls left
909 if (self.allowedTimeouts < 1)
910 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
911 //now all required checks are passed
912 self.allowedTimeouts -= 1;
913 bprint(self.netname, " ^7called a timeout (", ftos(self.allowedTimeouts), " timeouts left)!\n"); //write a bprint who started the timeout (and how many he has left)
914 remainingTimeoutTime = cvar("sv_timeout_length");
915 remainingLeadTime = cvar("sv_timeout_leadtime");
916 timeoutInitiator = self;
917 if (timeoutStatus == 0) { //if another timeout was already active, don't change its status (which was 1 or 2) to 1, only change it to 1 if no timeout was active yet
919 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
920 timeoutHandler = spawn();
921 timeoutHandler.think = timeoutHandler_Think;
923 timeoutHandler.nextthink = time; //always let the entity think asap
925 //inform all connected clients about the timeout call
926 play2all("announcer/robotic/timeoutcalled.wav");
930 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
931 * and the lead time for the timeout is still active, this countdown just will be aborted (the
932 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
933 * value of the cvar sv_timeout_resumetime.
935 * This function is called when a player issues the resumegame command.
937 void evaluateTimein() {
939 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
940 if (self != timeoutInitiator)
941 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
942 if (timeoutStatus == 1) {
943 remainingTimeoutTime = timeoutStatus = 0;
944 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
945 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
947 else if (timeoutStatus == 2) {
948 //only shorten the remainingTimeoutTime if it makes sense
949 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
950 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
951 remainingTimeoutTime = cvar("sv_timeout_resumetime");
952 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
955 sprint(self, "^7Error: Your resumegame call was discarded!\n");