1 #define FLAG_MIN (PL_MIN + '0 0 -13')
2 #define FLAG_MAX (PL_MAX + '0 0 -13')
5 entity ctf_worldflaglist; // CTF flags in the map
6 .entity ctf_worldflagnext;
10 .float next_take_time; // the next time a player can pick up a flag (time + blah)
11 /// I used this, in part, to fix the looping score bug. - avirox
12 //float FLAGSCORE_PICKUP = 1;
13 //float FLAGSCORE_RETURN = 5; // returned by owner team
14 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
15 //float FLAGSCORE_CAPTURE = 5;
17 #define FLAG_CARRY_POS '-15 0 7'
19 .float ctf_captureshielded; // set to 1 if the player is too bad to be allowed to capture
21 float captureshield_min_negscore; // punish at -20 points
22 float captureshield_max_ratio; // punish at most 30% of each team
23 float captureshield_force; // push force of the shield
25 float ctf_captureshield_shielded(entity p)
29 float players_worseeq, players_total;
31 if(captureshield_max_ratio <= 0)
34 s = PlayerScore_Add(p, SP_SCORE, 0);
35 if(s >= -captureshield_min_negscore)
38 players_total = players_worseeq = 0;
43 se = PlayerScore_Add(e, SP_SCORE, 0);
49 // player is in the worse half, if >= half the players are better than him, or consequently, if < half of the players are worse
52 if(players_worseeq >= players_total * captureshield_max_ratio)
58 void ctf_captureshield_update(entity p, float dir)
61 if(dir == p.ctf_captureshielded) // 0: shield only, 1: unshield only
63 should = ctf_captureshield_shielded(p);
68 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.");
69 // TODO csqc notifier for this
73 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.");
74 // TODO csqc notifier for this
76 p.ctf_captureshielded = should;
81 float ctf_captureshield_customize()
83 if not(other.ctf_captureshielded)
85 if(self.team == other.team)
90 void ctf_captureshield_touch()
92 if not(other.ctf_captureshielded)
94 if(self.team == other.team)
98 mymid = (self.absmin + self.absmax) * 0.5;
99 othermid = (other.absmin + other.absmax) * 0.5;
100 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * captureshield_force);
101 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.");
104 void ctf_captureshield_spawn()
110 e.touch = ctf_captureshield_touch;
111 e.customizeentityforclient = ctf_captureshield_customize;
112 e.classname = "ctf_captureshield";
113 e.effects = EF_ADDITIVE;
114 e.movetype = MOVETYPE_NOCLIP;
115 e.solid = SOLID_TRIGGER;
116 e.avelocity = '7 0 11';
117 setorigin(e, self.origin);
118 setmodel(e, "models/ctf/shield.md3");
120 setsize(e, e.scale * e.mins, e.scale * e.maxs);
123 float ctf_score_value(string parameter)
125 if(g_ctf_win_mode != 2)
126 return cvar(strcat("g_ctf_personal", parameter));
128 return cvar(strcat("g_ctf_flag", parameter));
131 void FakeTimeLimit(entity e, float t)
134 WriteByte(MSG_ONE, 3); // svc_updatestat
135 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
137 WriteCoord(MSG_ONE, cvar("timelimit"));
139 WriteCoord(MSG_ONE, (t + 1) / 60);
142 float flagcaptimerecord;
143 .float flagpickuptime;
144 //.float iscommander;
152 if(self.classname != "item_flag_team")
154 backtrace("PlaceFlag a non-flag");
159 self.t_width = 0.1; // frame animation rate
161 self.t_length = 58; // maximum frame
163 setattachment(self, world, "");
164 self.mdl = self.model;
165 self.flags = FL_ITEM;
166 self.solid = SOLID_TRIGGER;
167 self.movetype = MOVETYPE_NONE;
168 self.velocity = '0 0 0';
169 self.origin_z = self.origin_z + 6;
170 self.think = FlagThink;
171 self.touch = FlagTouch;
172 self.nextthink = time + 0.1;
173 self.cnt = FLAG_BASE;
174 self.mangle = self.angles;
175 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
176 //self.effects = self.effects | EF_DIMLIGHT;
179 self.dropped_origin = self.origin;
184 self.movetype = MOVETYPE_TOSS;
186 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
189 void LogCTF(string mode, float flagteam, entity actor)
192 if(!cvar("sv_eventlog"))
194 s = strcat(":ctf:", mode);
195 s = strcat(s, ":", ftos(flagteam));
197 s = strcat(s, ":", ftos(actor.playerid));
201 void RegenFlag(entity e)
203 if(e.classname != "item_flag_team")
205 backtrace("RegenFlag a non-flag");
209 setattachment(e, world, "");
210 e.damageforcescale = 0;
211 e.movetype = MOVETYPE_NONE;
213 e.movetype = MOVETYPE_TOSS;
214 e.velocity = '0 0 0';
215 e.solid = SOLID_TRIGGER;
216 // TODO: play a sound here
217 setorigin(e, e.dropped_origin);
221 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
224 void ReturnFlag(entity e)
226 if(e.classname != "item_flag_team")
228 backtrace("ReturnFlag a non-flag");
233 if (e.owner.flagcarried == e)
235 WaypointSprite_DetachCarrier(e.owner);
236 e.owner.flagcarried = world;
239 FakeTimeLimit(e.owner, -1);
245 void DropFlag(entity e, entity penalty_receiver, entity attacker)
249 if(e.classname != "item_flag_team")
251 backtrace("DropFlag a non-flag");
263 dprint("FLAG: drop - no owner?!?!\n");
267 if (p.flagcarried != e)
269 dprint("FLAG: drop - owner is not carrying this flag??\n");
272 bprint(p.netname, "^7 lost the ", e.netname, "\n");
275 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
277 UpdateFrags(p, -ctf_score_value("penalty_drop"));
278 PlayerScore_Add(p, SP_CTF_DROPS, +1);
279 ctf_captureshield_update(p, 0); // shield only
280 e.playerid = attacker.playerid;
281 e.ctf_droptime = time;
283 if(p.waypointsprite_attachedforcarrier)
285 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
286 WaypointSprite_DetachCarrier(p);
290 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
291 backtrace("Flag carrier had no flag sprite?!?");
293 LogCTF("dropped", p.team, p);
294 sound (self, CHAN_TRIGGER, self.noise4, VOL_BASE, ATTN_NONE);
296 setattachment(e, world, "");
297 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
299 if (p.flagcarried == e)
300 p.flagcarried = world;
303 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
304 e.solid = SOLID_TRIGGER;
305 e.movetype = MOVETYPE_TOSS;
306 // setsize(e, '-16 -16 0', '16 16 74');
307 setorigin(e, p.origin - '0 0 24' + '0 0 37');
308 e.cnt = FLAG_DROPPED;
309 e.velocity = '0 0 300';
310 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
312 trace_startsolid = FALSE;
313 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
315 dprint("FLAG FALLTHROUGH will happen SOON\n");
320 if(self.delay > time)
322 self.delay = time + self.t_width;
323 if(self.nextthink > self.delay)
324 self.nextthink = self.delay;
326 self.frame = self.frame + 1;
327 if(self.frame > self.t_length)
335 self.nextthink = time + 0.1;
337 // sorry, we have to reset the flag size if it got squished by something
338 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
340 // if we can grow back, grow back
341 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
342 if(!trace_startsolid)
343 setsize(self, FLAG_MIN, FLAG_MAX);
346 if(self == ctf_worldflaglist) // only for the first flag
349 ctf_captureshield_update(e, 1); // release shield only
354 if(self.speedrunning)
355 if(self.cnt == FLAG_CARRY)
358 if(flagcaptimerecord)
359 if(time >= self.flagpickuptime + flagcaptimerecord)
361 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
363 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
364 self.owner.impulse = 141; // returning!
375 if (self.cnt == FLAG_BASE)
378 if (self.cnt == FLAG_DROPPED)
380 // flag fallthrough? FIXME remove this if bug is really fixed now
381 if(self.origin_z < -131072)
383 dprint("FLAG FALLTHROUGH just happened\n");
384 self.pain_finished = 0;
386 setattachment(self, world, "");
387 if (time > self.pain_finished)
389 bprint("The ", self.netname, " has returned to base\n");
390 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
391 LogCTF("returned", self.team, world);
398 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
400 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
401 DropFlag(self, world, world);
405 if(cvar("g_ctf_allow_drop"))
407 DropFlag(self, e, world);
410 void flag_cap_ring_spawn(vector org)
412 shockwave_spawn("models/ctf/shockwavetransring.md3", org, -0.8, 0, 1);
421 local string s, s0, h0, h1;
422 if (other.classname != "player")
424 if (other.health < 1) // ignore dead players
427 if (self.cnt == FLAG_CARRY)
430 if (self.cnt == FLAG_BASE)
431 if (other.team == self.team)
432 if (other.flagcarried) // he's got a flag
433 if (other.flagcarried.team != self.team) // capture
435 if (other.flagcarried == world)
439 if(cvar("g_ctf_captimerecord_allow_assisted") || player_count - currentbots <= 1) // at most one human
441 t = time - other.flagcarried.flagpickuptime;
442 s = ftos_decimals(t, 2);
443 s0 = ftos_decimals(flagcaptimerecord, 2);
444 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
449 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
450 if (flagcaptimerecord == 0)
452 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
453 flagcaptimerecord = t;
454 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
455 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
456 write_recordmarker(other, time - t, t);
458 else if (t < flagcaptimerecord)
460 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
461 flagcaptimerecord = t;
462 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
463 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
464 write_recordmarker(other, time - t, t);
468 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
472 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
474 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
475 LogCTF("capture", other.flagcarried.team, other);
476 // give credit to the individual player
477 UpdateFrags(other, ctf_score_value("score_capture"));
479 if (cvar("g_ctf_flag_capture_effects")) {
480 if (other.team == COLOR_TEAM1) { // red team scores effect
481 pointparticles(particleeffectnum("red_ground_quake"), self.origin, '0 0 0', 1);
482 flag_cap_ring_spawn(self.origin);
484 if (other.team == COLOR_TEAM2) { // blue team scores effect
485 pointparticles(particleeffectnum("blue_ground_quake"), self.origin, '0 0 0', 1);
486 flag_cap_ring_spawn(self.origin);
490 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
491 WaypointSprite_DetachCarrier(other);
492 if(self.speedrunning)
493 FakeTimeLimit(other, -1);
494 RegenFlag (other.flagcarried);
495 other.flagcarried = world;
496 other.next_take_time = time + 1;
498 if (self.cnt == FLAG_BASE)
499 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
500 if (other.team != self.team)
501 if (!other.flagcarried)
502 if (!other.ctf_captureshielded)
504 if (other.next_take_time > time)
507 if (cvar("g_ctf_flag_pickup_effects")) // pickup effect
508 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
511 self.flagpickuptime = time; // used for timing runs
512 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
513 if(other.speedrunning)
514 if(flagcaptimerecord)
515 FakeTimeLimit(other, time + flagcaptimerecord);
516 self.solid = SOLID_NOT;
517 setorigin(self, self.origin); // relink
519 other.flagcarried = self;
520 self.cnt = FLAG_CARRY;
521 self.angles = '0 0 0';
522 bprint(other.netname, "^7 got the ", self.netname, "\n");
523 UpdateFrags(other, ctf_score_value("score_pickup_base"));
524 self.dropperid = other.playerid;
525 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
526 LogCTF("steal", self.team, other);
527 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
529 FOR_EACH_PLAYER(player)
530 if(player.team == self.team)
531 centerprint(player, "The enemy got your flag! Retrieve it!");
533 self.movetype = MOVETYPE_NONE;
534 setorigin(self, FLAG_CARRY_POS);
535 setattachment(self, other, "");
536 WaypointSprite_AttachCarrier("flagcarrier", other);
537 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
538 WaypointSprite_Ping(self.sprite);
543 if (self.cnt == FLAG_DROPPED)
545 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
546 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
549 bprint(other.netname, "^7 returned the ", self.netname, "\n");
551 // punish the player who last had it
552 FOR_EACH_PLAYER(player)
553 if(player.playerid == self.dropperid)
555 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
556 ctf_captureshield_update(player, 0); // shield only
559 // punish the team who was last carrying it
560 if(self.team == COLOR_TEAM1)
561 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
563 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
565 // reward the player who returned it
566 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
568 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
569 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
571 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
575 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
576 UpdateFrags(other, ctf_score_value("score_return"));
578 UpdateFrags(other, ctf_score_value("score_return_rogue"));
580 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
581 LogCTF("return", self.team, other);
582 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
585 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
587 if (cvar("g_ctf_flag_pickup_effects")) // field pickup effect
588 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
591 self.solid = SOLID_NOT;
592 setorigin(self, self.origin); // relink
594 other.flagcarried = self;
595 self.cnt = FLAG_CARRY;
596 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
599 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
600 //print("factor is ", ftos(f), "\n");
601 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
602 + ctf_score_value("score_pickup_dropped_early") * f;
604 self.dropperid = other.playerid;
605 //print("score is ", ftos(f), "\n");
607 UpdateFrags(other, f);
608 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
609 LogCTF("pickup", self.team, other);
610 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
612 FOR_EACH_PLAYER(player)
613 if(player.team == self.team)
614 centerprint(player, "The enemy got your flag! Retrieve it!");
616 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
617 setorigin(self, FLAG_CARRY_POS);
618 setattachment(self, other, "");
619 self.damageforcescale = 0;
620 WaypointSprite_AttachCarrier("flagcarrier", other);
621 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
626 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
627 CTF Starting point for a player
632 viewing angle when spawning
634 void spawnfunc_info_player_team1()
641 self.team = COLOR_TEAM1; // red
642 spawnfunc_info_player_deathmatch();
644 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
646 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
647 CTF Starting point for a player in
652 viewing angle when spawning
654 void spawnfunc_info_player_team2()
661 self.team = COLOR_TEAM2; // blue
662 spawnfunc_info_player_deathmatch();
664 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
666 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
667 CTF Starting point for a player in
672 viewing angle when spawning
674 void spawnfunc_info_player_team3()
681 self.team = COLOR_TEAM3; // yellow
682 spawnfunc_info_player_deathmatch();
686 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
687 CTF Starting point for a player in
692 viewing angle when spawning
694 void spawnfunc_info_player_team4()
701 self.team = COLOR_TEAM4; // purple
702 spawnfunc_info_player_deathmatch();
705 void item_flag_reset()
707 DropFlag(self, world, world);
711 void item_flag_postspawn()
712 { // Check CTF Item Flag Post Spawn
714 // Flag Glow Trail Support
715 if(cvar("g_ctf_flag_glowtrails"))
716 { // Provide Flag Glow Trail
717 if(self.team == COLOR_TEAM1)
719 self.glow_color = 251;
721 if(self.team == COLOR_TEAM2)
723 self.glow_color = 210;
730 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
731 CTF flag for team one (Red).
732 Multiple are allowed.
736 Angle the flag will point
739 model to use, note this needs red and blue as skins 0 and 1
740 (default models/ctf/flag.md3)
742 sound played when flag is picked up
743 (default ctf/take.wav)
745 sound played when flag is returned by a teammate
746 (default ctf/return.wav)
748 sound played when flag is captured
749 (default ctf/redcapture.wav)
751 sound played when flag is lost in the field and respawns itself
752 (default ctf/respawn.wav)
755 void spawnfunc_item_flag_team1()
763 //if(!cvar("teamplay"))
764 // cvar_set("teamplay", "3");
766 // link flag into ctf_worldflaglist
767 self.ctf_worldflagnext = ctf_worldflaglist;
768 ctf_worldflaglist = self;
770 self.classname = "item_flag_team";
773 self.team = COLOR_TEAM2; // color 13 team (blue)
774 self.items = IT_KEY1; // silver key (bluish enough)
778 self.team = COLOR_TEAM1; // color 4 team (red)
779 self.items = IT_KEY2; // gold key (redish enough)
781 self.netname = "^1RED^7 flag";
782 self.target = "###item###";
783 self.skin = cvar("g_ctf_flag_red_skin");
784 if(self.spawnflags & 1)
787 self.model = cvar_string("g_ctf_flag_red_model");
789 self.noise = "ctf/red_taken.wav";
791 self.noise1 = "ctf/red_returned.wav";
793 self.noise2 = "ctf/red_capture.wav"; // blue team scores by capturing the red flag
795 self.noise3 = "ctf/flag_respawn.wav";
797 self.noise4 = "ctf/red_dropped.wav";
798 precache_model (self.model);
799 setmodel (self, self.model); // precision set below
800 precache_sound (self.noise);
801 precache_sound (self.noise1);
802 precache_sound (self.noise2);
803 precache_sound (self.noise3);
804 precache_sound (self.noise4);
805 //setsize(self, '-16 -16 -37', '16 16 37');
806 setsize(self, FLAG_MIN, FLAG_MAX);
807 setorigin(self, self.origin + '0 0 37');
808 self.nextthink = time + 0.2; // start after doors etc
809 self.think = place_flag;
813 //if(!self.glow_size)
814 // self.glow_size = 50;
816 self.effects = self.effects | EF_LOWPRECISION;
817 if(cvar("g_ctf_fullbrightflags"))
818 self.effects |= EF_FULLBRIGHT;
819 if(cvar("g_ctf_dynamiclights"))
820 self.effects |= EF_RED;
823 item_flag_postspawn();
825 waypoint_spawnforitem(self);
827 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
828 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM1 - 1, FALSE));
830 precache_model("models/ctf/shield.md3");
831 precache_model("models/ctf/shockwavetransring.md3");
833 self.reset = item_flag_reset;
836 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
837 CTF flag for team two (Blue).
838 Multiple are allowed.
842 Angle the flag will point
845 model to use, note this needs red and blue as skins 0 and 1
846 (default models/ctf/flag.md3)
848 sound played when flag is picked up
849 (default ctf/take.wav)
851 sound played when flag is returned by a teammate
852 (default ctf/return.wav)
854 sound played when flag is captured
855 (default ctf/bluecapture.wav)
857 sound played when flag is lost in the field and respawns itself
858 (default ctf/respawn.wav)
861 void spawnfunc_item_flag_team2()
868 //if(!cvar("teamplay"))
869 // cvar_set("teamplay", "3");
871 // link flag into ctf_worldflaglist
872 self.ctf_worldflagnext = ctf_worldflaglist;
873 ctf_worldflaglist = self;
875 self.classname = "item_flag_team";
878 self.team = COLOR_TEAM1; // color 4 team (red)
879 self.items = IT_KEY2; // gold key (redish enough)
883 self.team = COLOR_TEAM2; // color 13 team (blue)
884 self.items = IT_KEY1; // silver key (bluish enough)
886 self.netname = "^4BLUE^7 flag";
887 self.target = "###item###";
888 self.skin = cvar("g_ctf_flag_blue_skin");
889 if(self.spawnflags & 1)
892 self.model = cvar_string("g_ctf_flag_blue_model");
894 self.noise = "ctf/blue_taken.wav";
896 self.noise1 = "ctf/blue_returned.wav";
898 self.noise2 = "ctf/blue_capture.wav"; // blue team scores by capturing the red flag
900 self.noise3 = "ctf/flag_respawn.wav";
902 self.noise4 = "ctf/blue_dropped.wav";
903 precache_model (self.model);
904 setmodel (self, self.model); // precision set below
905 precache_sound (self.noise);
906 precache_sound (self.noise1);
907 precache_sound (self.noise2);
908 precache_sound (self.noise3);
909 precache_sound (self.noise4);
910 //setsize(self, '-16 -16 -37', '16 16 37');
911 setsize(self, FLAG_MIN, FLAG_MAX);
912 setorigin(self, self.origin + '0 0 37');
913 self.nextthink = time + 0.2; // start after doors etc
914 self.think = place_flag;
918 //if(!self.glow_size)
919 // self.glow_size = 50;
921 self.effects = self.effects | EF_LOWPRECISION;
922 if(cvar("g_ctf_fullbrightflags"))
923 self.effects |= EF_FULLBRIGHT;
924 if(cvar("g_ctf_dynamiclights"))
925 self.effects |= EF_BLUE;
928 item_flag_postspawn();
930 waypoint_spawnforitem(self);
932 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
933 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM2 - 1, FALSE));
935 precache_model("models/ctf/shield.md3");
937 self.reset = item_flag_reset;
941 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
942 Team declaration for CTF gameplay, this allows you to decide what team
943 names and control point models are used in your map.
945 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
946 domination, you don't need to make a blank one too.
950 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
952 Scoreboard color of the team (for example 4 is red and 13 is blue)
956 void spawnfunc_ctf_team()
963 self.classname = "ctf_team";
964 self.team = self.cnt + 1;
967 // code from here on is just to support maps that don't have control point and team entities
968 void ctf_spawnteam (string teamname, float teamcolor)
970 local entity oldself;
973 self.classname = "ctf_team";
974 self.netname = teamname;
975 self.cnt = teamcolor;
977 spawnfunc_ctf_team();
982 // spawn some default teams if the map is not set up for ctf
983 void ctf_spawnteams()
987 numteams = 2;//cvar("g_ctf_default_teams");
989 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
990 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
993 void ctf_delayedinit()
995 // if no teams are found, spawn defaults
996 if (find(world, classname, "ctf_team") == world)
1004 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
1005 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
1007 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
1008 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
1009 captureshield_force = cvar("g_ctf_shield_force");
1012 void ctf_setstatus2(entity flag, float shift)
1014 if (flag.cnt == FLAG_CARRY)
1015 if (flag.owner == self)
1016 self.items |= shift * 3;
1018 self.items |= shift * 1;
1019 else if (flag.cnt == FLAG_DROPPED)
1020 self.items |= shift * 2;
1027 void ctf_setstatus()
1029 self.items &~= IT_RED_FLAG_TAKEN;
1030 self.items &~= IT_RED_FLAG_LOST;
1031 self.items &~= IT_BLUE_FLAG_TAKEN;
1032 self.items &~= IT_BLUE_FLAG_LOST;
1033 self.items &~= IT_CTF_SHIELDED;
1037 float redflags, blueflags;
1039 if(self.ctf_captureshielded)
1040 self.items |= IT_CTF_SHIELDED;
1045 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1047 if(flag.items & IT_KEY2) // blue
1049 else if(flag.items & IT_KEY1) // red
1053 // blinking magic: if there is more than one flag, show one of these in a clever way
1055 redflags = mod(floor(time * redflags * 0.75), redflags);
1057 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1059 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1061 if(flag.items & IT_KEY2) // blue
1063 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1064 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1066 else if(flag.items & IT_KEY1) // red
1068 if(--blueflags == -1) // happens exactly once
1069 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1075 entity(float cteam) ctf_team_has_commander =
1078 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1081 FOR_EACH_REALPLAYER(pl) {
1082 if(pl.team == cteam && pl.iscommander) {
1089 void(entity e, float st) ctf_setstate =
1095 void(float cteam) ctf_new_commander =
1100 FOR_EACH_REALPLAYER(pl) {
1101 if(pl.team == cteam) {
1102 if(pl.iscommander) { // don't reassign if alreay there
1105 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1109 if(plmax == world) {
1110 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1114 plmax.iscommander = TRUE;
1115 ctf_setstate(plmax, 3);
1116 sprint(plmax, "^3You're the commander now!\n");
1117 centerprint(plmax, "^3You're the commander now!\n");
1120 void() ctf_clientconnect =
1122 self.iscommander = FALSE;
1124 if(!self.team || self.classname != "player") {
1125 ctf_setstate(self, -1);
1127 ctf_setstate(self, 0);
1129 self.team_saved = self.team;
1131 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1132 ctf_new_commander(self.team);
1136 void() ctf_playerchanged =
1138 if(!self.team || self.classname != "player") {
1139 ctf_setstate(self, -1);
1140 } else if(self.ctf_state < 0 && self.classname == "player") {
1141 ctf_setstate(self, 0);
1144 if(self.iscommander &&
1145 (self.classname != "player" || self.team != self.team_saved)
1148 self.iscommander = FALSE;
1149 if(self.classname == "player")
1150 ctf_setstate(self, 0);
1152 ctf_setstate(self, -1);
1153 ctf_new_commander(self.team_saved);
1156 self.team_saved = self.team;
1158 ctf_new_commander(self.team);
1161 void() ctf_clientdisconnect =
1163 if(self.iscommander)
1165 ctf_new_commander(self.team);
1169 entity GetPlayer(string);
1170 float() ctf_clientcommand =
1173 if(argv(0) == "order") {
1175 sprint(self, "This command is not supported in this gamemode.\n");
1178 if(!self.iscommander) {
1179 sprint(self, "^1You are not the commander!\n");
1183 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1186 e = GetPlayer(argv(1));
1188 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1191 if(e.team != self.team) {
1192 sprint(self, "^3You can only give orders to your own team!\n");
1195 if(argv(2) == "attack") {
1196 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1197 sprint(e, "^1Attack!\n");
1198 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1200 } else if(argv(2) == "defend") {
1201 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1202 sprint(e, "^Defend!\n");
1203 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1206 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");