1 #define FLAG_MIN (PL_MIN + '0 0 -13')
2 #define FLAG_MAX (PL_MAX + '0 0 -13')
6 entity ctf_worldflaglist; // CTF flags in the map
7 .entity ctf_worldflagnext;
11 .float next_take_time; // the next time a player can pick up a flag (time + blah)
12 /// I used this, in part, to fix the looping score bug. - avirox
13 //float FLAGSCORE_PICKUP = 1;
14 //float FLAGSCORE_RETURN = 5; // returned by owner team
15 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
16 //float FLAGSCORE_CAPTURE = 5;
18 #define FLAG_CARRY_POS '-15 0 7'
20 .float ctf_captureshielded; // set to 1 if the player is too bad to be allowed to capture
22 float captureshield_min_negscore; // punish at -20 points
23 float captureshield_max_ratio; // punish at most 30% of each team
24 float captureshield_force; // push force of the shield
26 float ctf_captureshield_shielded(entity p)
30 float players_worseeq, players_total;
32 if(captureshield_max_ratio <= 0)
35 s = PlayerScore_Add(p, SP_SCORE, 0);
36 if(s >= -captureshield_min_negscore)
39 players_total = players_worseeq = 0;
44 se = PlayerScore_Add(e, SP_SCORE, 0);
50 // player is in the worse half, if >= half the players are better than him, or consequently, if < half of the players are worse
53 if(players_worseeq >= players_total * captureshield_max_ratio)
59 void ctf_captureshield_update(entity p, float dir)
62 if(dir == p.ctf_captureshielded) // 0: shield only, 1: unshield only
64 should = ctf_captureshield_shielded(p);
69 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.");
70 // TODO csqc notifier for this
74 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.");
75 // TODO csqc notifier for this
77 p.ctf_captureshielded = should;
82 float ctf_captureshield_customize()
84 if not(other.ctf_captureshielded)
86 if(self.team == other.team)
91 void ctf_captureshield_touch()
93 if not(other.ctf_captureshielded)
95 if(self.team == other.team)
99 mymid = (self.absmin + self.absmax) * 0.5;
100 othermid = (other.absmin + other.absmax) * 0.5;
101 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * captureshield_force);
102 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.");
105 void ctf_captureshield_spawn()
111 e.touch = ctf_captureshield_touch;
112 e.customizeentityforclient = ctf_captureshield_customize;
113 e.classname = "ctf_captureshield";
114 e.effects = EF_ADDITIVE;
115 e.movetype = MOVETYPE_NOCLIP;
116 e.solid = SOLID_TRIGGER;
117 e.avelocity = '7 0 11';
118 setorigin(e, self.origin);
119 setmodel(e, "models/ctf/shield.md3");
121 setsize(e, e.scale * e.mins, e.scale * e.maxs);
124 float ctf_score_value(string parameter)
126 if(g_ctf_win_mode != 2)
127 return cvar(strcat("g_ctf_personal", parameter));
129 return cvar(strcat("g_ctf_flag", parameter));
132 void FakeTimeLimit(entity e, float t)
135 WriteByte(MSG_ONE, 3); // svc_updatestat
136 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
138 WriteCoord(MSG_ONE, cvar("timelimit"));
140 WriteCoord(MSG_ONE, (t + 1) / 60);
143 float flagcaptimerecord;
144 .float flagpickuptime;
145 //.float iscommander;
153 if(self.classname != "item_flag_team")
155 backtrace("PlaceFlag a non-flag");
160 self.t_width = 0.1; // frame animation rate
162 self.t_length = 58; // maximum frame
164 setattachment(self, world, "");
165 self.mdl = self.model;
166 self.flags = FL_ITEM;
167 self.solid = SOLID_TRIGGER;
168 self.movetype = MOVETYPE_NONE;
169 self.velocity = '0 0 0';
170 self.origin_z = self.origin_z + 6;
171 self.think = FlagThink;
172 self.touch = FlagTouch;
173 self.nextthink = time + 0.1;
174 self.cnt = FLAG_BASE;
175 self.mangle = self.angles;
176 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
177 //self.effects = self.effects | EF_DIMLIGHT;
180 self.dropped_origin = self.origin;
185 self.movetype = MOVETYPE_TOSS;
187 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
190 void LogCTF(string mode, float flagteam, entity actor)
193 if(!cvar("sv_eventlog"))
195 s = strcat(":ctf:", mode);
196 s = strcat(s, ":", ftos(flagteam));
198 s = strcat(s, ":", ftos(actor.playerid));
202 void RegenFlag(entity e)
204 if(e.classname != "item_flag_team")
206 backtrace("RegenFlag a non-flag");
210 setattachment(e, world, "");
211 e.damageforcescale = 0;
212 e.movetype = MOVETYPE_NONE;
214 e.movetype = MOVETYPE_TOSS;
215 e.velocity = '0 0 0';
216 e.solid = SOLID_TRIGGER;
217 // TODO: play a sound here
218 setorigin(e, e.dropped_origin);
222 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
225 void ReturnFlag(entity e)
227 if(e.classname != "item_flag_team")
229 backtrace("ReturnFlag a non-flag");
234 if (e.owner.flagcarried == e)
236 WaypointSprite_DetachCarrier(e.owner);
237 e.owner.flagcarried = world;
240 FakeTimeLimit(e.owner, -1);
246 void DropFlag(entity e, entity penalty_receiver, entity attacker)
250 if(e.classname != "item_flag_team")
252 backtrace("DropFlag a non-flag");
264 dprint("FLAG: drop - no owner?!?!\n");
268 if (p.flagcarried != e)
270 dprint("FLAG: drop - owner is not carrying this flag??\n");
273 bprint(p.netname, "^7 lost the ", e.netname, "\n");
276 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
278 UpdateFrags(p, -ctf_score_value("penalty_drop"));
279 PlayerScore_Add(p, SP_CTF_DROPS, +1);
280 ctf_captureshield_update(p, 0); // shield only
281 e.playerid = attacker.playerid;
282 e.ctf_droptime = time;
284 if(p.waypointsprite_attachedforcarrier)
286 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
287 WaypointSprite_DetachCarrier(p);
291 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
292 backtrace("Flag carrier had no flag sprite?!?");
294 LogCTF("dropped", p.team, p);
295 sound (self, CHAN_TRIGGER, self.noise4, VOL_BASE, ATTN_NONE);
297 setattachment(e, world, "");
298 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
300 if (p.flagcarried == e)
301 p.flagcarried = world;
304 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
305 e.solid = SOLID_TRIGGER;
306 e.movetype = MOVETYPE_TOSS;
307 // setsize(e, '-16 -16 0', '16 16 74');
308 setorigin(e, p.origin - '0 0 24' + '0 0 37');
309 e.cnt = FLAG_DROPPED;
310 e.velocity = '0 0 300';
311 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
313 trace_startsolid = FALSE;
314 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
316 dprint("FLAG FALLTHROUGH will happen SOON\n");
321 if(self.delay > time)
323 self.delay = time + self.t_width;
324 if(self.nextthink > self.delay)
325 self.nextthink = self.delay;
327 self.frame = self.frame + 1;
328 if(self.frame > self.t_length)
336 self.nextthink = time + 0.1;
338 // sorry, we have to reset the flag size if it got squished by something
339 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
341 // if we can grow back, grow back
342 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
343 if(!trace_startsolid)
344 setsize(self, FLAG_MIN, FLAG_MAX);
347 if(self == ctf_worldflaglist) // only for the first flag
350 ctf_captureshield_update(e, 1); // release shield only
355 if(self.speedrunning)
356 if(self.cnt == FLAG_CARRY)
359 if(flagcaptimerecord)
360 if(time >= self.flagpickuptime + flagcaptimerecord)
362 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
364 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
365 self.owner.impulse = 141; // returning!
376 if (self.cnt == FLAG_BASE)
379 if (self.cnt == FLAG_DROPPED)
381 // flag fallthrough? FIXME remove this if bug is really fixed now
382 if(self.origin_z < -131072)
384 dprint("FLAG FALLTHROUGH just happened\n");
385 self.pain_finished = 0;
387 setattachment(self, world, "");
388 if (time > self.pain_finished)
390 bprint("The ", self.netname, " has returned to base\n");
391 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
392 LogCTF("returned", self.team, world);
399 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
401 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
402 DropFlag(self, world, world);
406 if(cvar("g_ctf_allow_drop"))
408 DropFlag(self, e, world);
411 void flag_cap_ring_spawn(vector org)
413 shockwave_spawn("models/ctf/shockwavetransring.md3", org - '0 0 15', -0.8, 0, 1);
422 local string s, s0, h0, h1;
423 if (other.classname != "player")
425 if (other.health < 1) // ignore dead players
428 if (self.cnt == FLAG_CARRY)
431 if (self.cnt == FLAG_BASE)
432 if (other.team == self.team)
433 if (other.flagcarried) // he's got a flag
434 if (other.flagcarried.team != self.team) // capture
436 if (other.flagcarried == world)
440 if(cvar("g_ctf_captimerecord_allow_assisted") || player_count - currentbots <= 1) // at most one human
442 t = time - other.flagcarried.flagpickuptime;
443 s = ftos_decimals(t, 2);
444 s0 = ftos_decimals(flagcaptimerecord, 2);
445 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
450 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
451 if (flagcaptimerecord == 0)
453 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
454 flagcaptimerecord = t;
455 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
456 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
457 write_recordmarker(other, time - t, t);
459 else if (t < flagcaptimerecord)
461 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
462 flagcaptimerecord = t;
463 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
464 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
465 write_recordmarker(other, time - t, t);
469 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
473 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
475 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
476 LogCTF("capture", other.flagcarried.team, other);
477 // give credit to the individual player
478 UpdateFrags(other, ctf_score_value("score_capture"));
480 if (cvar("g_ctf_flag_capture_effects")) {
481 if (other.team == COLOR_TEAM1) { // red team scores effect
482 pointparticles(particleeffectnum("red_ground_quake"), self.origin, '0 0 0', 1);
483 flag_cap_ring_spawn(self.origin);
485 if (other.team == COLOR_TEAM2) { // blue team scores effect
486 pointparticles(particleeffectnum("blue_ground_quake"), self.origin, '0 0 0', 1);
487 flag_cap_ring_spawn(self.origin);
491 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
492 WaypointSprite_DetachCarrier(other);
493 if(self.speedrunning)
494 FakeTimeLimit(other, -1);
495 RegenFlag (other.flagcarried);
496 other.flagcarried = world;
497 other.next_take_time = time + 1;
499 if (self.cnt == FLAG_BASE)
500 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
501 if (other.team != self.team)
502 if (!other.flagcarried)
503 if (!other.ctf_captureshielded)
505 if (other.next_take_time > time)
508 if (cvar("g_ctf_flag_pickup_effects")) // pickup effect
509 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
512 self.flagpickuptime = time; // used for timing runs
513 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
514 if(other.speedrunning)
515 if(flagcaptimerecord)
516 FakeTimeLimit(other, time + flagcaptimerecord);
517 self.solid = SOLID_NOT;
518 setorigin(self, self.origin); // relink
520 other.flagcarried = self;
521 self.cnt = FLAG_CARRY;
522 self.angles = '0 0 0';
523 bprint(other.netname, "^7 got the ", self.netname, "\n");
524 UpdateFrags(other, ctf_score_value("score_pickup_base"));
525 self.dropperid = other.playerid;
526 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
527 LogCTF("steal", self.team, other);
528 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
530 FOR_EACH_PLAYER(player)
531 if(player.team == self.team)
532 centerprint(player, "The enemy got your flag! Retrieve it!");
534 self.movetype = MOVETYPE_NONE;
535 setorigin(self, FLAG_CARRY_POS);
536 setattachment(self, other, "");
537 WaypointSprite_AttachCarrier("flagcarrier", other);
538 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
539 WaypointSprite_Ping(self.sprite);
544 if (self.cnt == FLAG_DROPPED)
546 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
547 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
550 bprint(other.netname, "^7 returned the ", self.netname, "\n");
552 // punish the player who last had it
553 FOR_EACH_PLAYER(player)
554 if(player.playerid == self.dropperid)
556 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
557 ctf_captureshield_update(player, 0); // shield only
560 // punish the team who was last carrying it
561 if(self.team == COLOR_TEAM1)
562 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
564 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
566 // reward the player who returned it
567 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
569 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
570 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
572 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
576 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
577 UpdateFrags(other, ctf_score_value("score_return"));
579 UpdateFrags(other, ctf_score_value("score_return_rogue"));
581 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
582 LogCTF("return", self.team, other);
583 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
586 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
588 if (cvar("g_ctf_flag_pickup_effects")) // field pickup effect
589 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
592 self.solid = SOLID_NOT;
593 setorigin(self, self.origin); // relink
595 other.flagcarried = self;
596 self.cnt = FLAG_CARRY;
597 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
600 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
601 //print("factor is ", ftos(f), "\n");
602 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
603 + ctf_score_value("score_pickup_dropped_early") * f;
605 self.dropperid = other.playerid;
606 //print("score is ", ftos(f), "\n");
608 UpdateFrags(other, f);
609 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
610 LogCTF("pickup", self.team, other);
611 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
613 FOR_EACH_PLAYER(player)
614 if(player.team == self.team)
615 centerprint(player, "The enemy got your flag! Retrieve it!");
617 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
618 setorigin(self, FLAG_CARRY_POS);
619 setattachment(self, other, "");
620 self.damageforcescale = 0;
621 WaypointSprite_AttachCarrier("flagcarrier", other);
622 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
627 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
628 CTF Starting point for a player
633 viewing angle when spawning
635 void spawnfunc_info_player_team1()
642 self.team = COLOR_TEAM1; // red
643 spawnfunc_info_player_deathmatch();
645 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
647 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
648 CTF Starting point for a player in
653 viewing angle when spawning
655 void spawnfunc_info_player_team2()
662 self.team = COLOR_TEAM2; // blue
663 spawnfunc_info_player_deathmatch();
665 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
667 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
668 CTF Starting point for a player in
673 viewing angle when spawning
675 void spawnfunc_info_player_team3()
682 self.team = COLOR_TEAM3; // yellow
683 spawnfunc_info_player_deathmatch();
687 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
688 CTF Starting point for a player in
693 viewing angle when spawning
695 void spawnfunc_info_player_team4()
702 self.team = COLOR_TEAM4; // purple
703 spawnfunc_info_player_deathmatch();
706 void item_flag_reset()
708 DropFlag(self, world, world);
712 void item_flag_postspawn()
713 { // Check CTF Item Flag Post Spawn
715 // Flag Glow Trail Support
716 if(cvar("g_ctf_flag_glowtrails"))
717 { // Provide Flag Glow Trail
718 if(self.team == COLOR_TEAM1)
720 self.glow_color = 251;
722 if(self.team == COLOR_TEAM2)
724 self.glow_color = 210;
731 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
732 CTF flag for team one (Red).
733 Multiple are allowed.
737 Angle the flag will point
740 model to use, note this needs red and blue as skins 0 and 1
741 (default models/ctf/flag.md3)
743 sound played when flag is picked up
744 (default ctf/take.wav)
746 sound played when flag is returned by a teammate
747 (default ctf/return.wav)
749 sound played when flag is captured
750 (default ctf/redcapture.wav)
752 sound played when flag is lost in the field and respawns itself
753 (default ctf/respawn.wav)
756 void spawnfunc_item_flag_team1()
764 //if(!cvar("teamplay"))
765 // cvar_set("teamplay", "3");
767 // link flag into ctf_worldflaglist
768 self.ctf_worldflagnext = ctf_worldflaglist;
769 ctf_worldflaglist = self;
771 self.classname = "item_flag_team";
774 self.team = COLOR_TEAM2; // color 13 team (blue)
775 self.items = IT_KEY1; // silver key (bluish enough)
779 self.team = COLOR_TEAM1; // color 4 team (red)
780 self.items = IT_KEY2; // gold key (redish enough)
782 self.netname = "^1RED^7 flag";
783 self.target = "###item###";
784 self.skin = cvar("g_ctf_flag_red_skin");
785 if(self.spawnflags & 1)
788 self.model = cvar_string("g_ctf_flag_red_model");
790 self.noise = "ctf/red_taken.wav";
792 self.noise1 = "ctf/red_returned.wav";
794 self.noise2 = "ctf/red_capture.wav"; // blue team scores by capturing the red flag
796 self.noise3 = "ctf/flag_respawn.wav";
798 self.noise4 = "ctf/red_dropped.wav";
799 precache_model (self.model);
800 setmodel (self, self.model); // precision set below
801 precache_sound (self.noise);
802 precache_sound (self.noise1);
803 precache_sound (self.noise2);
804 precache_sound (self.noise3);
805 precache_sound (self.noise4);
806 //setsize(self, '-16 -16 -37', '16 16 37');
807 setsize(self, FLAG_MIN, FLAG_MAX);
808 setorigin(self, self.origin + '0 0 37');
809 self.nextthink = time + 0.2; // start after doors etc
810 self.think = place_flag;
814 //if(!self.glow_size)
815 // self.glow_size = 50;
817 self.effects = self.effects | EF_LOWPRECISION;
818 if(cvar("g_ctf_fullbrightflags"))
819 self.effects |= EF_FULLBRIGHT;
820 if(cvar("g_ctf_dynamiclights"))
821 self.effects |= EF_RED;
824 item_flag_postspawn();
826 waypoint_spawnforitem_force(self, self.origin);
827 self.nearestwaypointtimeout = 0; // activate waypointing again
828 self.basewaypoint = self.nearestwaypoint;
830 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
831 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM1 - 1, FALSE));
833 precache_model("models/ctf/shield.md3");
834 precache_model("models/ctf/shockwavetransring.md3");
836 self.reset = item_flag_reset;
839 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
840 CTF flag for team two (Blue).
841 Multiple are allowed.
845 Angle the flag will point
848 model to use, note this needs red and blue as skins 0 and 1
849 (default models/ctf/flag.md3)
851 sound played when flag is picked up
852 (default ctf/take.wav)
854 sound played when flag is returned by a teammate
855 (default ctf/return.wav)
857 sound played when flag is captured
858 (default ctf/bluecapture.wav)
860 sound played when flag is lost in the field and respawns itself
861 (default ctf/respawn.wav)
864 void spawnfunc_item_flag_team2()
871 //if(!cvar("teamplay"))
872 // cvar_set("teamplay", "3");
874 // link flag into ctf_worldflaglist
875 self.ctf_worldflagnext = ctf_worldflaglist;
876 ctf_worldflaglist = self;
878 self.classname = "item_flag_team";
881 self.team = COLOR_TEAM1; // color 4 team (red)
882 self.items = IT_KEY2; // gold key (redish enough)
886 self.team = COLOR_TEAM2; // color 13 team (blue)
887 self.items = IT_KEY1; // silver key (bluish enough)
889 self.netname = "^4BLUE^7 flag";
890 self.target = "###item###";
891 self.skin = cvar("g_ctf_flag_blue_skin");
892 if(self.spawnflags & 1)
895 self.model = cvar_string("g_ctf_flag_blue_model");
897 self.noise = "ctf/blue_taken.wav";
899 self.noise1 = "ctf/blue_returned.wav";
901 self.noise2 = "ctf/blue_capture.wav"; // blue team scores by capturing the red flag
903 self.noise3 = "ctf/flag_respawn.wav";
905 self.noise4 = "ctf/blue_dropped.wav";
906 precache_model (self.model);
907 setmodel (self, self.model); // precision set below
908 precache_sound (self.noise);
909 precache_sound (self.noise1);
910 precache_sound (self.noise2);
911 precache_sound (self.noise3);
912 precache_sound (self.noise4);
913 //setsize(self, '-16 -16 -37', '16 16 37');
914 setsize(self, FLAG_MIN, FLAG_MAX);
915 setorigin(self, self.origin + '0 0 37');
916 self.nextthink = time + 0.2; // start after doors etc
917 self.think = place_flag;
921 //if(!self.glow_size)
922 // self.glow_size = 50;
924 self.effects = self.effects | EF_LOWPRECISION;
925 if(cvar("g_ctf_fullbrightflags"))
926 self.effects |= EF_FULLBRIGHT;
927 if(cvar("g_ctf_dynamiclights"))
928 self.effects |= EF_BLUE;
931 item_flag_postspawn();
933 waypoint_spawnforitem_force(self, self.origin);
934 self.nearestwaypointtimeout = 0; // activate waypointing again
935 self.basewaypoint = self.nearestwaypoint;
937 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
938 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM2 - 1, FALSE));
940 precache_model("models/ctf/shield.md3");
942 self.reset = item_flag_reset;
946 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
947 Team declaration for CTF gameplay, this allows you to decide what team
948 names and control point models are used in your map.
950 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
951 domination, you don't need to make a blank one too.
955 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
957 Scoreboard color of the team (for example 4 is red and 13 is blue)
961 void spawnfunc_ctf_team()
968 self.classname = "ctf_team";
969 self.team = self.cnt + 1;
972 // code from here on is just to support maps that don't have control point and team entities
973 void ctf_spawnteam (string teamname, float teamcolor)
975 local entity oldself;
978 self.classname = "ctf_team";
979 self.netname = teamname;
980 self.cnt = teamcolor;
982 spawnfunc_ctf_team();
987 // spawn some default teams if the map is not set up for ctf
988 void ctf_spawnteams()
992 numteams = 2;//cvar("g_ctf_default_teams");
994 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
995 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
998 void ctf_delayedinit()
1000 // if no teams are found, spawn defaults
1001 if (find(world, classname, "ctf_team") == world)
1009 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
1010 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
1012 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
1013 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
1014 captureshield_force = cvar("g_ctf_shield_force");
1017 void ctf_setstatus2(entity flag, float shift)
1019 if (flag.cnt == FLAG_CARRY)
1020 if (flag.owner == self)
1021 self.items |= shift * 3;
1023 self.items |= shift * 1;
1024 else if (flag.cnt == FLAG_DROPPED)
1025 self.items |= shift * 2;
1032 void ctf_setstatus()
1034 self.items &~= IT_RED_FLAG_TAKEN;
1035 self.items &~= IT_RED_FLAG_LOST;
1036 self.items &~= IT_BLUE_FLAG_TAKEN;
1037 self.items &~= IT_BLUE_FLAG_LOST;
1038 self.items &~= IT_CTF_SHIELDED;
1042 float redflags, blueflags;
1044 if(self.ctf_captureshielded)
1045 self.items |= IT_CTF_SHIELDED;
1050 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1052 if(flag.items & IT_KEY2) // blue
1054 else if(flag.items & IT_KEY1) // red
1058 // blinking magic: if there is more than one flag, show one of these in a clever way
1060 redflags = mod(floor(time * redflags * 0.75), redflags);
1062 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1064 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1066 if(flag.items & IT_KEY2) // blue
1068 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1069 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1071 else if(flag.items & IT_KEY1) // red
1073 if(--blueflags == -1) // happens exactly once
1074 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1080 entity(float cteam) ctf_team_has_commander =
1083 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1086 FOR_EACH_REALPLAYER(pl) {
1087 if(pl.team == cteam && pl.iscommander) {
1094 void(entity e, float st) ctf_setstate =
1100 void(float cteam) ctf_new_commander =
1105 FOR_EACH_REALPLAYER(pl) {
1106 if(pl.team == cteam) {
1107 if(pl.iscommander) { // don't reassign if alreay there
1110 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1114 if(plmax == world) {
1115 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1119 plmax.iscommander = TRUE;
1120 ctf_setstate(plmax, 3);
1121 sprint(plmax, "^3You're the commander now!\n");
1122 centerprint(plmax, "^3You're the commander now!\n");
1125 void() ctf_clientconnect =
1127 self.iscommander = FALSE;
1129 if(!self.team || self.classname != "player") {
1130 ctf_setstate(self, -1);
1132 ctf_setstate(self, 0);
1134 self.team_saved = self.team;
1136 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1137 ctf_new_commander(self.team);
1141 void() ctf_playerchanged =
1143 if(!self.team || self.classname != "player") {
1144 ctf_setstate(self, -1);
1145 } else if(self.ctf_state < 0 && self.classname == "player") {
1146 ctf_setstate(self, 0);
1149 if(self.iscommander &&
1150 (self.classname != "player" || self.team != self.team_saved)
1153 self.iscommander = FALSE;
1154 if(self.classname == "player")
1155 ctf_setstate(self, 0);
1157 ctf_setstate(self, -1);
1158 ctf_new_commander(self.team_saved);
1161 self.team_saved = self.team;
1163 ctf_new_commander(self.team);
1166 void() ctf_clientdisconnect =
1168 if(self.iscommander)
1170 ctf_new_commander(self.team);
1174 entity GetPlayer(string);
1175 float() ctf_clientcommand =
1178 if(argv(0) == "order") {
1180 sprint(self, "This command is not supported in this gamemode.\n");
1183 if(!self.iscommander) {
1184 sprint(self, "^1You are not the commander!\n");
1188 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1191 e = GetPlayer(argv(1));
1193 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1196 if(e.team != self.team) {
1197 sprint(self, "^3You can only give orders to your own team!\n");
1200 if(argv(2) == "attack") {
1201 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1202 sprint(e, "^1Attack!\n");
1203 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1205 } else if(argv(2) == "defend") {
1206 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1207 sprint(e, "^Defend!\n");
1208 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1211 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");