2 entity ctf_worldflaglist; // CTF flags in the map
3 .entity ctf_worldflagnext;
7 .float next_take_time; // the next time a player can pick up a flag (time + blah)
8 /// I used this, in part, to fix the looping score bug. - avirox
9 //float FLAGSCORE_PICKUP = 1;
10 //float FLAGSCORE_RETURN = 5; // returned by owner team
11 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
12 //float FLAGSCORE_CAPTURE = 5;
14 #define FLAG_CARRY_POS '-15 0 7'
16 .float ctf_captureshielded; // set to 1 if the player is too bad to be allowed to capture
18 float captureshield_min_negscore; // punish at -20 points
19 float captureshield_max_ratio; // punish at most 30% of each team
20 float captureshield_force; // push force of the shield
22 float ctf_captureshield_shielded(entity p)
26 float players_worseeq, players_total;
28 if(captureshield_max_ratio <= 0)
31 s = PlayerScore_Add(p, SP_SCORE, 0);
32 if(s >= -captureshield_min_negscore)
35 players_total = players_worseeq = 0;
40 se = PlayerScore_Add(e, SP_SCORE, 0);
46 // player is in the worse half, if >= half the players are better than him, or consequently, if < half of the players are worse
49 if(players_worseeq >= players_total * captureshield_max_ratio)
55 void ctf_captureshield_update(entity p, float dir)
58 if(dir == p.ctf_captureshielded) // 0: shield only, 1: unshield only
60 should = ctf_captureshield_shielded(p);
65 centerprint_atprio(p, CENTERPRIO_SHIELDING, "^3You are now ^4shielded^3 from the flag\n^3for ^1too many unsuccessful attempts^3 to capture.\n\n^3Make some defensive scores before trying again.");
66 // TODO csqc notifier for this
70 centerprint_atprio(p, CENTERPRIO_SHIELDING, "^3You are now free.\n\n^3Feel free to ^1try to capture^3 the flag again\n^3if you think you will succeed.");
71 // TODO csqc notifier for this
73 p.ctf_captureshielded = should;
78 float ctf_captureshield_customize()
80 if not(other.ctf_captureshielded)
82 if(self.team == other.team)
87 void ctf_captureshield_touch()
89 if not(other.ctf_captureshielded)
91 if(self.team == other.team)
95 mymid = (self.absmin + self.absmax) * 0.5;
96 othermid = (other.absmin + other.absmax) * 0.5;
97 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * captureshield_force);
98 centerprint_atprio(other, CENTERPRIO_SHIELDING, "^3You are ^4shielded^3 from the flag\n^3for ^1too many unsuccessful attempts^3 to capture.\n\n^3Get some defensive scores before trying again.");
101 void ctf_captureshield_spawn()
107 e.touch = ctf_captureshield_touch;
108 e.customizeentityforclient = ctf_captureshield_customize;
109 e.classname = "ctf_captureshield";
110 e.effects = EF_ADDITIVE;
111 e.movetype = MOVETYPE_NOCLIP;
112 e.solid = SOLID_TRIGGER;
113 e.avelocity = '7 0 11';
114 setorigin(e, self.origin);
115 setmodel(e, "models/onslaught/generator_shield.md3");
117 setsize(e, e.scale * e.mins, e.scale * e.maxs);
118 print(etos(e), "\n");
121 float ctf_score_value(string parameter)
123 if(g_ctf_win_mode != 2)
124 return cvar(strcat("g_ctf_personal", parameter));
126 return cvar(strcat("g_ctf_flag", parameter));
129 void FakeTimeLimit(entity e, float t)
132 WriteByte(MSG_ONE, 3); // svc_updatestat
133 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
135 WriteCoord(MSG_ONE, cvar("timelimit"));
137 WriteCoord(MSG_ONE, (t + 1) / 60);
140 float flagcaptimerecord;
141 .float flagpickuptime;
142 //.float iscommander;
151 self.t_width = 0.1; // frame animation rate
153 self.t_length = 119; // maximum frame
155 setattachment(self, world, "");
156 self.mdl = self.model;
157 self.flags = FL_ITEM;
158 self.solid = SOLID_TRIGGER;
159 self.movetype = MOVETYPE_NONE;
160 self.velocity = '0 0 0';
161 self.origin_z = self.origin_z + 6;
162 self.think = FlagThink;
163 self.touch = FlagTouch;
164 self.nextthink = time + 0.1;
165 self.cnt = FLAG_BASE;
166 self.mangle = self.angles;
167 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
168 //self.effects = self.effects | EF_DIMLIGHT;
171 self.dropped_origin = self.origin;
176 self.movetype = MOVETYPE_TOSS;
178 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
181 void LogCTF(string mode, float flagteam, entity actor)
184 if(!cvar("sv_eventlog"))
186 s = strcat(":ctf:", mode);
187 s = strcat(s, ":", ftos(flagteam));
189 s = strcat(s, ":", ftos(actor.playerid));
193 void RegenFlag(entity e)
195 setattachment(e, world, "");
196 e.damageforcescale = 0;
197 e.movetype = MOVETYPE_NONE;
199 e.movetype = MOVETYPE_TOSS;
200 e.solid = SOLID_TRIGGER;
201 // TODO: play a sound here
202 setorigin(e, e.dropped_origin);
206 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
209 void ReturnFlag(entity e)
212 if (e.owner.flagcarried == e)
214 WaypointSprite_DetachCarrier(e.owner);
215 e.owner.flagcarried = world;
218 FakeTimeLimit(e.owner, -1);
224 void DropFlag(entity e, entity penalty_receiver, entity attacker)
236 dprint("FLAG: drop - no owner?!?!\n");
240 if (p.flagcarried != e)
242 dprint("FLAG: drop - owner is not carrying this flag??\n");
245 bprint(p.netname, "^7 lost the ", e.netname, "\n");
248 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
250 UpdateFrags(p, -ctf_score_value("penalty_drop"));
251 PlayerScore_Add(p, SP_CTF_DROPS, +1);
252 ctf_captureshield_update(p, 0); // shield only
253 e.playerid = attacker.playerid;
254 e.ctf_droptime = time;
256 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
257 WaypointSprite_DetachCarrier(p);
258 LogCTF("dropped", p.team, p);
260 setattachment(e, world, "");
261 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
263 if (p.flagcarried == e)
264 p.flagcarried = world;
267 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
268 e.solid = SOLID_TRIGGER;
269 e.movetype = MOVETYPE_TOSS;
270 // setsize(e, '-16 -16 0', '16 16 74');
271 setorigin(e, p.origin - '0 0 24' + '0 0 37');
272 e.cnt = FLAG_DROPPED;
273 e.velocity = '0 0 300';
274 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
276 trace_startsolid = FALSE;
277 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
279 dprint("FLAG FALLTHROUGH will happen SOON\n");
284 if(self.delay > time)
286 self.delay = time + self.t_width;
287 if(self.nextthink > self.delay)
288 self.nextthink = self.delay;
290 self.frame = self.frame + 1;
291 if(self.frame > self.t_length)
299 self.nextthink = time + 0.1;
301 if(self == ctf_worldflaglist) // only for the first flag
304 ctf_captureshield_update(e, 1); // release shield only
309 if(self.speedrunning)
310 if(self.cnt == FLAG_CARRY)
313 if(flagcaptimerecord)
314 if(time >= self.flagpickuptime + flagcaptimerecord)
316 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
318 self.owner.impulse = 77; // returning!
328 if (self.cnt == FLAG_BASE)
331 if (self.cnt == FLAG_DROPPED)
333 // flag fallthrough? FIXME remove this if bug is really fixed now
334 if(self.origin_z < -131072)
336 dprint("FLAG FALLTHROUGH just happened\n");
337 self.pain_finished = 0;
339 setattachment(self, world, "");
340 if (time > self.pain_finished)
342 bprint("The ", self.netname, " has returned to base\n");
343 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
344 LogCTF("returned", self.team, world);
351 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
353 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
354 DropFlag(self, world, world);
358 if(cvar("g_ctf_allow_drop"))
360 DropFlag(self, e, world);
369 local string s, s0, h0, h1;
370 if (other.classname != "player")
372 if (other.health < 1) // ignore dead players
375 if (self.cnt == FLAG_CARRY)
378 if (self.cnt == FLAG_BASE)
379 if (other.team == self.team)
380 if (other.flagcarried) // he's got a flag
381 if (other.flagcarried.team != self.team) // capture
383 if (other.flagcarried == world)
387 t = time - other.flagcarried.flagpickuptime;
388 s = ftos_decimals(t, 2);
389 s0 = ftos_decimals(flagcaptimerecord, 2);
390 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
395 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
396 if (flagcaptimerecord == 0)
398 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
399 flagcaptimerecord = t;
400 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
401 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
402 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
404 else if (t < flagcaptimerecord)
406 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
407 flagcaptimerecord = t;
408 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
409 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
410 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
414 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
417 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
418 LogCTF("capture", other.flagcarried.team, other);
419 // give credit to the individual player
420 UpdateFrags(other, ctf_score_value("score_capture"));
422 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
423 WaypointSprite_DetachCarrier(other);
424 if(self.speedrunning)
425 FakeTimeLimit(other, -1);
426 RegenFlag (other.flagcarried);
427 other.flagcarried = world;
428 other.next_take_time = time + 1;
430 if (self.cnt == FLAG_BASE)
431 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
432 if (other.team != self.team)
433 if (!other.flagcarried)
434 if (!other.ctf_captureshielded)
436 if (other.next_take_time > time)
439 self.flagpickuptime = time; // used for timing runs
440 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
441 if(other.speedrunning)
442 if(flagcaptimerecord)
443 FakeTimeLimit(other, time + flagcaptimerecord);
444 self.solid = SOLID_NOT;
445 setorigin(self, self.origin); // relink
447 other.flagcarried = self;
448 self.cnt = FLAG_CARRY;
449 self.angles = '0 0 0';
450 bprint(other.netname, "^7 got the ", self.netname, "\n");
451 UpdateFrags(other, ctf_score_value("score_pickup_base"));
452 self.dropperid = other.playerid;
453 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
454 LogCTF("steal", self.team, other);
455 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
457 FOR_EACH_PLAYER(player)
458 if(player.team == self.team)
459 centerprint(player, "The enemy got your flag! Retrieve it!");
461 self.movetype = MOVETYPE_NONE;
462 setorigin(self, FLAG_CARRY_POS);
463 setattachment(self, other, "");
464 WaypointSprite_AttachCarrier("flagcarrier", other);
465 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
466 WaypointSprite_Ping(self.sprite);
471 if (self.cnt == FLAG_DROPPED)
473 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
474 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
477 bprint(other.netname, "^7 returned the ", self.netname, "\n");
479 // punish the player who last had it
480 FOR_EACH_PLAYER(player)
481 if(player.playerid == self.dropperid)
483 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
484 ctf_captureshield_update(player, 0); // shield only
487 // punish the team who was last carrying it
488 if(self.team == COLOR_TEAM1)
489 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
491 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
493 // reward the player who returned it
494 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
496 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
497 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
499 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
503 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
504 UpdateFrags(other, ctf_score_value("score_return"));
506 UpdateFrags(other, ctf_score_value("score_return_rogue"));
508 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
509 LogCTF("return", self.team, other);
510 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
513 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
516 self.solid = SOLID_NOT;
517 setorigin(self, self.origin); // relink
519 other.flagcarried = self;
520 self.cnt = FLAG_CARRY;
521 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
524 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
525 //print("factor is ", ftos(f), "\n");
526 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
527 + ctf_score_value("score_pickup_dropped_early") * f;
529 self.dropperid = other.playerid;
530 //print("score is ", ftos(f), "\n");
532 UpdateFrags(other, f);
533 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
534 LogCTF("pickup", self.team, other);
535 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
537 FOR_EACH_PLAYER(player)
538 if(player.team == self.team)
539 centerprint(player, "The enemy got your flag! Retrieve it!");
541 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
542 setorigin(self, FLAG_CARRY_POS);
543 setattachment(self, other, "");
544 self.damageforcescale = 0;
545 WaypointSprite_AttachCarrier("flagcarrier", other);
546 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
551 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
552 CTF Starting point for a player
557 viewing angle when spawning
559 void spawnfunc_info_player_team1()
561 self.team = COLOR_TEAM1; // red
562 spawnfunc_info_player_deathmatch();
564 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
566 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
567 CTF Starting point for a player in
572 viewing angle when spawning
574 void spawnfunc_info_player_team2()
576 self.team = COLOR_TEAM2; // blue
577 spawnfunc_info_player_deathmatch();
579 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
581 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
582 CTF Starting point for a player in
583 team three (Magenta).
587 viewing angle when spawning
589 void spawnfunc_info_player_team3()
591 self.team = COLOR_TEAM3; // purple
592 spawnfunc_info_player_deathmatch();
596 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
597 CTF Starting point for a player in
602 viewing angle when spawning
604 void spawnfunc_info_player_team4()
606 self.team = COLOR_TEAM4; // yellow
607 spawnfunc_info_player_deathmatch();
613 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
614 CTF flag for team one (Red).
615 Multiple are allowed.
619 Angle the flag will point
622 model to use, note this needs red and blue as skins 0 and 1
623 (default models/ctf/flag.md3)
625 sound played when flag is picked up
626 (default ctf/take.wav)
628 sound played when flag is returned by a teammate
629 (default ctf/return.wav)
631 sound played when flag is captured
632 (default ctf/redcapture.wav)
634 sound played when flag is lost in the field and respawns itself
635 (default ctf/respawn.wav)
638 void spawnfunc_item_flag_team1()
646 //if(!cvar("teamplay"))
647 // cvar_set("teamplay", "3");
649 // link flag into ctf_worldflaglist
650 self.ctf_worldflagnext = ctf_worldflaglist;
651 ctf_worldflaglist = self;
653 self.classname = "item_flag_team";
656 self.team = COLOR_TEAM2; // color 13 team (blue)
657 self.items = IT_KEY1; // silver key (bluish enough)
661 self.team = COLOR_TEAM1; // color 4 team (red)
662 self.items = IT_KEY2; // gold key (redish enough)
664 self.netname = "^1RED^7 flag";
665 self.target = "###item###";
667 if(self.spawnflags & 1)
670 self.model = "models/ctf/flag_red.md3";
672 self.noise = "ctf/take.wav";
674 self.noise1 = "ctf/return.wav";
676 self.noise2 = "ctf/redcapture.wav"; // blue team scores by capturing the red flag
678 self.noise3 = "ctf/respawn.wav";
679 precache_model (self.model);
680 setmodel (self, self.model); // precision set below
681 precache_sound (self.noise);
682 precache_sound (self.noise1);
683 precache_sound (self.noise2);
684 precache_sound (self.noise3);
685 //setsize(self, '-16 -16 -37', '16 16 37');
686 setsize(self, PL_MIN + '0 0 -13', PL_MAX + '0 0 -13');
687 setorigin(self, self.origin + '0 0 37');
688 self.nextthink = time + 0.2; // start after doors etc
689 self.think = place_flag;
693 //if(!self.glow_size)
694 // self.glow_size = 50;
696 self.effects = self.effects | EF_LOWPRECISION;
697 if(cvar("g_ctf_fullbrightflags"))
698 self.effects |= EF_FULLBRIGHT;
700 waypoint_spawnforitem(self);
702 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
703 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '1 0 0');
705 precache_model("models/onslaught/generator_shield.md3");
708 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
709 CTF flag for team two (Blue).
710 Multiple are allowed.
714 Angle the flag will point
717 model to use, note this needs red and blue as skins 0 and 1
718 (default models/ctf/flag.md3)
720 sound played when flag is picked up
721 (default ctf/take.wav)
723 sound played when flag is returned by a teammate
724 (default ctf/return.wav)
726 sound played when flag is captured
727 (default ctf/bluecapture.wav)
729 sound played when flag is lost in the field and respawns itself
730 (default ctf/respawn.wav)
733 void spawnfunc_item_flag_team2()
740 //if(!cvar("teamplay"))
741 // cvar_set("teamplay", "3");
743 // link flag into ctf_worldflaglist
744 self.ctf_worldflagnext = ctf_worldflaglist;
745 ctf_worldflaglist = self;
747 self.classname = "item_flag_team";
750 self.team = COLOR_TEAM1; // color 4 team (red)
751 self.items = IT_KEY2; // gold key (redish enough)
755 self.team = COLOR_TEAM2; // color 13 team (blue)
756 self.items = IT_KEY1; // silver key (bluish enough)
758 self.netname = "^4BLUE^7 flag";
759 self.target = "###item###";
761 if(self.spawnflags & 1)
764 self.model = "models/ctf/flag_blue.md3";
766 self.noise = "ctf/take.wav";
768 self.noise1 = "ctf/return.wav";
770 self.noise2 = "ctf/bluecapture.wav"; // red team scores by capturing the blue flag
772 self.noise3 = "ctf/respawn.wav";
773 precache_model (self.model);
774 setmodel (self, self.model); // precision set below
775 precache_sound (self.noise);
776 precache_sound (self.noise1);
777 precache_sound (self.noise2);
778 precache_sound (self.noise3);
779 //setsize(self, '-16 -16 -37', '16 16 37');
780 setsize(self, PL_MIN + '0 0 -13', PL_MAX + '0 0 -13');
781 setorigin(self, self.origin + '0 0 37');
782 self.nextthink = time + 0.2; // start after doors etc
783 self.think = place_flag;
787 //if(!self.glow_size)
788 // self.glow_size = 50;
790 self.effects = self.effects | EF_LOWPRECISION;
791 if(cvar("g_ctf_fullbrightflags"))
792 self.effects |= EF_FULLBRIGHT;
794 waypoint_spawnforitem(self);
796 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
797 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '0 0 1');
799 precache_model("models/onslaught/generator_shield.md3");
803 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
804 Team declaration for CTF gameplay, this allows you to decide what team
805 names and control point models are used in your map.
807 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
808 domination, you don't need to make a blank one too.
812 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
814 Scoreboard color of the team (for example 4 is red and 13 is blue)
818 void spawnfunc_ctf_team()
825 self.classname = "ctf_team";
826 self.team = self.cnt + 1;
829 // code from here on is just to support maps that don't have control point and team entities
830 void ctf_spawnteam (string teamname, float teamcolor)
832 local entity oldself;
835 self.classname = "ctf_team";
836 self.netname = teamname;
837 self.cnt = teamcolor;
839 spawnfunc_ctf_team();
844 // spawn some default teams if the map is not set up for ctf
845 void ctf_spawnteams()
849 numteams = 2;//cvar("g_ctf_default_teams");
851 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
852 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
855 void ctf_delayedinit()
857 // if no teams are found, spawn defaults
858 if (find(world, classname, "ctf_team") == world)
866 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
867 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
869 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
870 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
871 captureshield_force = cvar("g_ctf_shield_force");
874 void ctf_setstatus2(entity flag, float shift)
876 if (flag.cnt == FLAG_CARRY)
877 if (flag.owner == self)
878 self.items |= shift * 3;
880 self.items |= shift * 1;
881 else if (flag.cnt == FLAG_DROPPED)
882 self.items |= shift * 2;
891 self.items (-) IT_RED_FLAG_TAKEN;
892 self.items (-) IT_RED_FLAG_LOST;
893 self.items (-) IT_BLUE_FLAG_TAKEN;
894 self.items (-) IT_BLUE_FLAG_LOST;
895 self.items (-) IT_CTF_SHIELDED;
899 float redflags, blueflags;
901 if(self.ctf_captureshielded)
902 self.items |= IT_CTF_SHIELDED;
907 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
909 if(flag.items & IT_KEY2) // blue
911 else if(flag.items & IT_KEY1) // red
915 // blinking magic: if there is more than one flag, show one of these in a clever way
917 redflags = mod(floor(time * redflags * 0.75), redflags);
919 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
921 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
923 if(flag.items & IT_KEY2) // blue
925 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
926 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
928 else if(flag.items & IT_KEY1) // red
930 if(--blueflags == -1) // happens exactly once
931 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
937 entity(float cteam) ctf_team_has_commander =
940 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
943 FOR_EACH_REALPLAYER(pl) {
944 if(pl.team == cteam && pl.iscommander) {
951 void(entity e, float st) ctf_setstate =
957 void(float cteam) ctf_new_commander =
962 FOR_EACH_REALPLAYER(pl) {
963 if(pl.team == cteam) {
964 if(pl.iscommander) { // don't reassign if alreay there
967 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
972 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
976 plmax.iscommander = TRUE;
977 ctf_setstate(plmax, 3);
978 sprint(plmax, "^3You're the commander now!\n");
979 centerprint(plmax, "^3You're the commander now!\n");
982 void() ctf_clientconnect =
984 self.iscommander = FALSE;
986 if(!self.team || self.classname != "player") {
987 ctf_setstate(self, -1);
989 ctf_setstate(self, 0);
991 self.team_saved = self.team;
993 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
994 ctf_new_commander(self.team);
998 void() ctf_playerchanged =
1000 if(!self.team || self.classname != "player") {
1001 ctf_setstate(self, -1);
1002 } else if(self.ctf_state < 0 && self.classname == "player") {
1003 ctf_setstate(self, 0);
1006 if(self.iscommander &&
1007 (self.classname != "player" || self.team != self.team_saved)
1010 self.iscommander = FALSE;
1011 if(self.classname == "player")
1012 ctf_setstate(self, 0);
1014 ctf_setstate(self, -1);
1015 ctf_new_commander(self.team_saved);
1018 self.team_saved = self.team;
1020 ctf_new_commander(self.team);
1023 void() ctf_clientdisconnect =
1025 if(self.iscommander)
1027 ctf_new_commander(self.team);
1031 entity GetPlayer(string);
1032 float() ctf_clientcommand =
1035 if(argv(0) == "order") {
1037 sprint(self, "This command is not supported in this gamemode.\n");
1040 if(!self.iscommander) {
1041 sprint(self, "^1You are not the commander!\n");
1045 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1048 e = GetPlayer(argv(1));
1050 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1053 if(e.team != self.team) {
1054 sprint(self, "^3You can only give orders to your own team!\n");
1057 if(argv(2) == "attack") {
1058 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1059 sprint(e, "^1Attack!\n");
1060 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1062 } else if(argv(2) == "defend") {
1063 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1064 sprint(e, "^Defend!\n");
1065 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1068 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");