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_think()
412 self.nextthink = time + 0.05;
415 self.think = SUB_Remove;
419 self.scale = self.count / 30;
421 self.frame = self.count;
424 self.alpha = self.alpha-0.04;
427 void flag_cap_ring_spawn(vector org)
431 setmodel(e, "models/ctf/shockwavetransring.md3");
438 e.think = flag_cap_ring_think;
448 local string s, s0, h0, h1;
449 if (other.classname != "player")
451 if (other.health < 1) // ignore dead players
454 if (self.cnt == FLAG_CARRY)
457 if (self.cnt == FLAG_BASE)
458 if (other.team == self.team)
459 if (other.flagcarried) // he's got a flag
460 if (other.flagcarried.team != self.team) // capture
462 if (other.flagcarried == world)
466 if(cvar("g_ctf_captimerecord_allow_assisted") || player_count - currentbots <= 1) // at most one human
468 t = time - other.flagcarried.flagpickuptime;
469 s = ftos_decimals(t, 2);
470 s0 = ftos_decimals(flagcaptimerecord, 2);
471 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
476 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
477 if (flagcaptimerecord == 0)
479 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
480 flagcaptimerecord = t;
481 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
482 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
483 write_recordmarker(other, time - t, t);
485 else if (t < flagcaptimerecord)
487 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
488 flagcaptimerecord = t;
489 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
490 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
491 write_recordmarker(other, time - t, t);
495 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
499 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
501 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
502 LogCTF("capture", other.flagcarried.team, other);
503 // give credit to the individual player
504 UpdateFrags(other, ctf_score_value("score_capture"));
506 if (cvar("g_ctf_flag_capture_effects")) {
507 if (other.team == COLOR_TEAM1) { // red team scores effect
508 pointparticles(particleeffectnum("red_ground_quake"), self.origin, '0 0 0', 1);
509 flag_cap_ring_spawn(self.origin);
511 if (other.team == COLOR_TEAM2) { // blue team scores effect
512 pointparticles(particleeffectnum("blue_ground_quake"), self.origin, '0 0 0', 1);
513 flag_cap_ring_spawn(self.origin);
517 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
518 WaypointSprite_DetachCarrier(other);
519 if(self.speedrunning)
520 FakeTimeLimit(other, -1);
521 RegenFlag (other.flagcarried);
522 other.flagcarried = world;
523 other.next_take_time = time + 1;
525 if (self.cnt == FLAG_BASE)
526 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
527 if (other.team != self.team)
528 if (!other.flagcarried)
529 if (!other.ctf_captureshielded)
531 if (other.next_take_time > time)
534 if (cvar("g_ctf_flag_pickup_effects")) // pickup effect
535 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
538 self.flagpickuptime = time; // used for timing runs
539 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
540 if(other.speedrunning)
541 if(flagcaptimerecord)
542 FakeTimeLimit(other, time + flagcaptimerecord);
543 self.solid = SOLID_NOT;
544 setorigin(self, self.origin); // relink
546 other.flagcarried = self;
547 self.cnt = FLAG_CARRY;
548 self.angles = '0 0 0';
549 bprint(other.netname, "^7 got the ", self.netname, "\n");
550 UpdateFrags(other, ctf_score_value("score_pickup_base"));
551 self.dropperid = other.playerid;
552 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
553 LogCTF("steal", self.team, other);
554 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
556 FOR_EACH_PLAYER(player)
557 if(player.team == self.team)
558 centerprint(player, "The enemy got your flag! Retrieve it!");
560 self.movetype = MOVETYPE_NONE;
561 setorigin(self, FLAG_CARRY_POS);
562 setattachment(self, other, "");
563 WaypointSprite_AttachCarrier("flagcarrier", other);
564 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
565 WaypointSprite_Ping(self.sprite);
570 if (self.cnt == FLAG_DROPPED)
572 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
573 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
576 bprint(other.netname, "^7 returned the ", self.netname, "\n");
578 // punish the player who last had it
579 FOR_EACH_PLAYER(player)
580 if(player.playerid == self.dropperid)
582 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
583 ctf_captureshield_update(player, 0); // shield only
586 // punish the team who was last carrying it
587 if(self.team == COLOR_TEAM1)
588 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
590 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
592 // reward the player who returned it
593 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
595 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
596 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
598 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
602 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
603 UpdateFrags(other, ctf_score_value("score_return"));
605 UpdateFrags(other, ctf_score_value("score_return_rogue"));
607 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
608 LogCTF("return", self.team, other);
609 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
612 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
614 if (cvar("g_ctf_flag_pickup_effects")) // field pickup effect
615 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
618 self.solid = SOLID_NOT;
619 setorigin(self, self.origin); // relink
621 other.flagcarried = self;
622 self.cnt = FLAG_CARRY;
623 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
626 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
627 //print("factor is ", ftos(f), "\n");
628 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
629 + ctf_score_value("score_pickup_dropped_early") * f;
631 self.dropperid = other.playerid;
632 //print("score is ", ftos(f), "\n");
634 UpdateFrags(other, f);
635 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
636 LogCTF("pickup", self.team, other);
637 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
639 FOR_EACH_PLAYER(player)
640 if(player.team == self.team)
641 centerprint(player, "The enemy got your flag! Retrieve it!");
643 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
644 setorigin(self, FLAG_CARRY_POS);
645 setattachment(self, other, "");
646 self.damageforcescale = 0;
647 WaypointSprite_AttachCarrier("flagcarrier", other);
648 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
653 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
654 CTF Starting point for a player
659 viewing angle when spawning
661 void spawnfunc_info_player_team1()
668 self.team = COLOR_TEAM1; // red
669 spawnfunc_info_player_deathmatch();
671 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
673 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
674 CTF Starting point for a player in
679 viewing angle when spawning
681 void spawnfunc_info_player_team2()
688 self.team = COLOR_TEAM2; // blue
689 spawnfunc_info_player_deathmatch();
691 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
693 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
694 CTF Starting point for a player in
699 viewing angle when spawning
701 void spawnfunc_info_player_team3()
708 self.team = COLOR_TEAM3; // yellow
709 spawnfunc_info_player_deathmatch();
713 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
714 CTF Starting point for a player in
719 viewing angle when spawning
721 void spawnfunc_info_player_team4()
728 self.team = COLOR_TEAM4; // purple
729 spawnfunc_info_player_deathmatch();
732 void item_flag_reset()
734 DropFlag(self, world, world);
738 void item_flag_postspawn()
739 { // Check CTF Item Flag Post Spawn
741 // Flag Glow Trail Support
742 if(cvar("g_ctf_flag_glowtrails"))
743 { // Provide Flag Glow Trail
744 if(self.team == COLOR_TEAM1)
746 self.glow_color = 251;
748 if(self.team == COLOR_TEAM2)
750 self.glow_color = 210;
757 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
758 CTF flag for team one (Red).
759 Multiple are allowed.
763 Angle the flag will point
766 model to use, note this needs red and blue as skins 0 and 1
767 (default models/ctf/flag.md3)
769 sound played when flag is picked up
770 (default ctf/take.wav)
772 sound played when flag is returned by a teammate
773 (default ctf/return.wav)
775 sound played when flag is captured
776 (default ctf/redcapture.wav)
778 sound played when flag is lost in the field and respawns itself
779 (default ctf/respawn.wav)
782 void spawnfunc_item_flag_team1()
790 //if(!cvar("teamplay"))
791 // cvar_set("teamplay", "3");
793 // link flag into ctf_worldflaglist
794 self.ctf_worldflagnext = ctf_worldflaglist;
795 ctf_worldflaglist = self;
797 self.classname = "item_flag_team";
800 self.team = COLOR_TEAM2; // color 13 team (blue)
801 self.items = IT_KEY1; // silver key (bluish enough)
805 self.team = COLOR_TEAM1; // color 4 team (red)
806 self.items = IT_KEY2; // gold key (redish enough)
808 self.netname = "^1RED^7 flag";
809 self.target = "###item###";
810 self.skin = cvar("g_ctf_flag_red_skin");
811 if(self.spawnflags & 1)
814 self.model = cvar_string("g_ctf_flag_red_model");
816 self.noise = "ctf/red_taken.wav";
818 self.noise1 = "ctf/red_returned.wav";
820 self.noise2 = "ctf/red_capture.wav"; // blue team scores by capturing the red flag
822 self.noise3 = "ctf/flag_respawn.wav";
824 self.noise4 = "ctf/red_dropped.wav";
825 precache_model (self.model);
826 setmodel (self, self.model); // precision set below
827 precache_sound (self.noise);
828 precache_sound (self.noise1);
829 precache_sound (self.noise2);
830 precache_sound (self.noise3);
831 precache_sound (self.noise4);
832 //setsize(self, '-16 -16 -37', '16 16 37');
833 setsize(self, FLAG_MIN, FLAG_MAX);
834 setorigin(self, self.origin + '0 0 37');
835 self.nextthink = time + 0.2; // start after doors etc
836 self.think = place_flag;
840 //if(!self.glow_size)
841 // self.glow_size = 50;
843 self.effects = self.effects | EF_LOWPRECISION;
844 if(cvar("g_ctf_fullbrightflags"))
845 self.effects |= EF_FULLBRIGHT;
846 if(cvar("g_ctf_dynamiclights"))
847 self.effects |= EF_RED;
850 item_flag_postspawn();
852 waypoint_spawnforitem(self);
854 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
855 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM1 - 1, FALSE));
857 precache_model("models/ctf/shield.md3");
858 precache_model("models/ctf/shockwavetransring.md3");
860 self.reset = item_flag_reset;
863 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
864 CTF flag for team two (Blue).
865 Multiple are allowed.
869 Angle the flag will point
872 model to use, note this needs red and blue as skins 0 and 1
873 (default models/ctf/flag.md3)
875 sound played when flag is picked up
876 (default ctf/take.wav)
878 sound played when flag is returned by a teammate
879 (default ctf/return.wav)
881 sound played when flag is captured
882 (default ctf/bluecapture.wav)
884 sound played when flag is lost in the field and respawns itself
885 (default ctf/respawn.wav)
888 void spawnfunc_item_flag_team2()
895 //if(!cvar("teamplay"))
896 // cvar_set("teamplay", "3");
898 // link flag into ctf_worldflaglist
899 self.ctf_worldflagnext = ctf_worldflaglist;
900 ctf_worldflaglist = self;
902 self.classname = "item_flag_team";
905 self.team = COLOR_TEAM1; // color 4 team (red)
906 self.items = IT_KEY2; // gold key (redish enough)
910 self.team = COLOR_TEAM2; // color 13 team (blue)
911 self.items = IT_KEY1; // silver key (bluish enough)
913 self.netname = "^4BLUE^7 flag";
914 self.target = "###item###";
915 self.skin = cvar("g_ctf_flag_blue_skin");
916 if(self.spawnflags & 1)
919 self.model = cvar_string("g_ctf_flag_blue_model");
921 self.noise = "ctf/blue_taken.wav";
923 self.noise1 = "ctf/blue_returned.wav";
925 self.noise2 = "ctf/blue_capture.wav"; // blue team scores by capturing the red flag
927 self.noise3 = "ctf/flag_respawn.wav";
929 self.noise4 = "ctf/blue_dropped.wav";
930 precache_model (self.model);
931 setmodel (self, self.model); // precision set below
932 precache_sound (self.noise);
933 precache_sound (self.noise1);
934 precache_sound (self.noise2);
935 precache_sound (self.noise3);
936 precache_sound (self.noise4);
937 //setsize(self, '-16 -16 -37', '16 16 37');
938 setsize(self, FLAG_MIN, FLAG_MAX);
939 setorigin(self, self.origin + '0 0 37');
940 self.nextthink = time + 0.2; // start after doors etc
941 self.think = place_flag;
945 //if(!self.glow_size)
946 // self.glow_size = 50;
948 self.effects = self.effects | EF_LOWPRECISION;
949 if(cvar("g_ctf_fullbrightflags"))
950 self.effects |= EF_FULLBRIGHT;
951 if(cvar("g_ctf_dynamiclights"))
952 self.effects |= EF_BLUE;
955 item_flag_postspawn();
957 waypoint_spawnforitem(self);
959 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
960 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM2 - 1, FALSE));
962 precache_model("models/ctf/shield.md3");
964 self.reset = item_flag_reset;
968 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
969 Team declaration for CTF gameplay, this allows you to decide what team
970 names and control point models are used in your map.
972 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
973 domination, you don't need to make a blank one too.
977 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
979 Scoreboard color of the team (for example 4 is red and 13 is blue)
983 void spawnfunc_ctf_team()
990 self.classname = "ctf_team";
991 self.team = self.cnt + 1;
994 // code from here on is just to support maps that don't have control point and team entities
995 void ctf_spawnteam (string teamname, float teamcolor)
997 local entity oldself;
1000 self.classname = "ctf_team";
1001 self.netname = teamname;
1002 self.cnt = teamcolor;
1004 spawnfunc_ctf_team();
1009 // spawn some default teams if the map is not set up for ctf
1010 void ctf_spawnteams()
1014 numteams = 2;//cvar("g_ctf_default_teams");
1016 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
1017 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
1020 void ctf_delayedinit()
1022 // if no teams are found, spawn defaults
1023 if (find(world, classname, "ctf_team") == world)
1031 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
1032 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
1034 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
1035 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
1036 captureshield_force = cvar("g_ctf_shield_force");
1039 void ctf_setstatus2(entity flag, float shift)
1041 if (flag.cnt == FLAG_CARRY)
1042 if (flag.owner == self)
1043 self.items |= shift * 3;
1045 self.items |= shift * 1;
1046 else if (flag.cnt == FLAG_DROPPED)
1047 self.items |= shift * 2;
1054 void ctf_setstatus()
1056 self.items &~= IT_RED_FLAG_TAKEN;
1057 self.items &~= IT_RED_FLAG_LOST;
1058 self.items &~= IT_BLUE_FLAG_TAKEN;
1059 self.items &~= IT_BLUE_FLAG_LOST;
1060 self.items &~= IT_CTF_SHIELDED;
1064 float redflags, blueflags;
1066 if(self.ctf_captureshielded)
1067 self.items |= IT_CTF_SHIELDED;
1072 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1074 if(flag.items & IT_KEY2) // blue
1076 else if(flag.items & IT_KEY1) // red
1080 // blinking magic: if there is more than one flag, show one of these in a clever way
1082 redflags = mod(floor(time * redflags * 0.75), redflags);
1084 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1086 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1088 if(flag.items & IT_KEY2) // blue
1090 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1091 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1093 else if(flag.items & IT_KEY1) // red
1095 if(--blueflags == -1) // happens exactly once
1096 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1102 entity(float cteam) ctf_team_has_commander =
1105 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1108 FOR_EACH_REALPLAYER(pl) {
1109 if(pl.team == cteam && pl.iscommander) {
1116 void(entity e, float st) ctf_setstate =
1122 void(float cteam) ctf_new_commander =
1127 FOR_EACH_REALPLAYER(pl) {
1128 if(pl.team == cteam) {
1129 if(pl.iscommander) { // don't reassign if alreay there
1132 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1136 if(plmax == world) {
1137 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1141 plmax.iscommander = TRUE;
1142 ctf_setstate(plmax, 3);
1143 sprint(plmax, "^3You're the commander now!\n");
1144 centerprint(plmax, "^3You're the commander now!\n");
1147 void() ctf_clientconnect =
1149 self.iscommander = FALSE;
1151 if(!self.team || self.classname != "player") {
1152 ctf_setstate(self, -1);
1154 ctf_setstate(self, 0);
1156 self.team_saved = self.team;
1158 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1159 ctf_new_commander(self.team);
1163 void() ctf_playerchanged =
1165 if(!self.team || self.classname != "player") {
1166 ctf_setstate(self, -1);
1167 } else if(self.ctf_state < 0 && self.classname == "player") {
1168 ctf_setstate(self, 0);
1171 if(self.iscommander &&
1172 (self.classname != "player" || self.team != self.team_saved)
1175 self.iscommander = FALSE;
1176 if(self.classname == "player")
1177 ctf_setstate(self, 0);
1179 ctf_setstate(self, -1);
1180 ctf_new_commander(self.team_saved);
1183 self.team_saved = self.team;
1185 ctf_new_commander(self.team);
1188 void() ctf_clientdisconnect =
1190 if(self.iscommander)
1192 ctf_new_commander(self.team);
1196 entity GetPlayer(string);
1197 float() ctf_clientcommand =
1200 if(argv(0) == "order") {
1202 sprint(self, "This command is not supported in this gamemode.\n");
1205 if(!self.iscommander) {
1206 sprint(self, "^1You are not the commander!\n");
1210 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1213 e = GetPlayer(argv(1));
1215 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1218 if(e.team != self.team) {
1219 sprint(self, "^3You can only give orders to your own team!\n");
1222 if(argv(2) == "attack") {
1223 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1224 sprint(e, "^1Attack!\n");
1225 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1227 } else if(argv(2) == "defend") {
1228 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1229 sprint(e, "^Defend!\n");
1230 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1233 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");