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_flag_spawnstuff()
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);
123 waypoint_spawnforitem_force(self, self.origin);
124 self.nearestwaypointtimeout = 0; // activate waypointing again
125 self.basewaypoint = self.nearestwaypoint;
127 if(self.team == COLOR_TEAM1)
129 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 61', self, sprite);
130 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM1 - 1, FALSE));
134 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 61', self, sprite);
135 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM2 - 1, FALSE));
139 float ctf_score_value(string parameter)
141 if(g_ctf_win_mode != 2)
142 return cvar(strcat("g_ctf_personal", parameter));
144 return cvar(strcat("g_ctf_flag", parameter));
147 void FakeTimeLimit(entity e, float t)
150 WriteByte(MSG_ONE, 3); // svc_updatestat
151 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
153 WriteCoord(MSG_ONE, cvar("timelimit"));
155 WriteCoord(MSG_ONE, (t + 1) / 60);
158 float flagcaptimerecord;
159 .float flagpickuptime;
160 //.float iscommander;
168 if(self.classname != "item_flag_team")
170 backtrace("PlaceFlag a non-flag");
175 self.t_width = 0.1; // frame animation rate
177 self.t_length = 58; // maximum frame
179 setattachment(self, world, "");
180 self.mdl = self.model;
181 self.flags = FL_ITEM;
182 self.solid = SOLID_TRIGGER;
183 self.movetype = MOVETYPE_NONE;
184 self.velocity = '0 0 0';
185 self.origin_z = self.origin_z + 6;
186 self.think = FlagThink;
187 self.touch = FlagTouch;
188 self.nextthink = time + 0.1;
189 self.cnt = FLAG_BASE;
190 self.mangle = self.angles;
191 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
192 //self.effects = self.effects | EF_DIMLIGHT;
195 self.dropped_origin = self.origin;
200 self.movetype = MOVETYPE_TOSS;
203 InitializeEntity(self, ctf_flag_spawnstuff, INITPRIO_SETLOCATION);
206 void LogCTF(string mode, float flagteam, entity actor)
209 if(!cvar("sv_eventlog"))
211 s = strcat(":ctf:", mode);
212 s = strcat(s, ":", ftos(flagteam));
214 s = strcat(s, ":", ftos(actor.playerid));
218 void RegenFlag(entity e)
220 if(e.classname != "item_flag_team")
222 backtrace("RegenFlag a non-flag");
226 if(e.waypointsprite_attachedforcarrier)
227 WaypointSprite_DetachCarrier(e);
229 setattachment(e, world, "");
230 e.damageforcescale = 0;
231 e.takedamage = DAMAGE_NO;
232 e.movetype = MOVETYPE_NONE;
234 e.movetype = MOVETYPE_TOSS;
235 e.velocity = '0 0 0';
236 e.solid = SOLID_TRIGGER;
237 // TODO: play a sound here
238 setorigin(e, e.dropped_origin);
242 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
245 void ReturnFlag(entity e)
247 if(e.classname != "item_flag_team")
249 backtrace("ReturnFlag a non-flag");
254 if (e.owner.flagcarried == e)
256 WaypointSprite_DetachCarrier(e.owner);
257 e.owner.flagcarried = world;
260 FakeTimeLimit(e.owner, -1);
266 void DropFlag(entity e, entity penalty_receiver, entity attacker)
270 if(e.classname != "item_flag_team")
272 backtrace("DropFlag a non-flag");
284 dprint("FLAG: drop - no owner?!?!\n");
288 if (p.flagcarried != e)
290 dprint("FLAG: drop - owner is not carrying this flag??\n");
293 //bprint(p.netname, "^7 lost the ", e.netname, "\n");
294 Send_KillNotification (p.netname, e.netname, "", INFO_LOSTFLAG, MSG_INFO);
297 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
299 UpdateFrags(p, -ctf_score_value("penalty_drop"));
300 PlayerScore_Add(p, SP_CTF_DROPS, +1);
301 ctf_captureshield_update(p, 0); // shield only
302 e.playerid = attacker.playerid;
303 e.ctf_droptime = time;
304 WaypointSprite_Spawn("flagdropped", 0, 0, e, '0 0 1' * 61, world, COLOR_TEAM1 + COLOR_TEAM2 - e.team, e, waypointsprite_attachedforcarrier, FALSE);
306 if(p.waypointsprite_attachedforcarrier)
308 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
309 WaypointSprite_DetachCarrier(p);
313 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
314 backtrace("Flag carrier had no flag sprite?!?");
316 LogCTF("dropped", p.team, p);
317 sound (self, CHAN_TRIGGER, self.noise4, VOL_BASE, ATTN_NONE);
319 setattachment(e, world, "");
320 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
321 e.takedamage = DAMAGE_YES;
323 if (p.flagcarried == e)
324 p.flagcarried = world;
327 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
328 e.solid = SOLID_TRIGGER;
329 e.movetype = MOVETYPE_TOSS;
330 // setsize(e, '-16 -16 0', '16 16 74');
331 setorigin(e, p.origin - '0 0 24' + '0 0 37');
332 e.cnt = FLAG_DROPPED;
333 e.velocity = '0 0 300';
334 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
336 trace_startsolid = FALSE;
337 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
339 dprint("FLAG FALLTHROUGH will happen SOON\n");
344 if(self.delay > time)
346 self.delay = time + self.t_width;
347 if(self.nextthink > self.delay)
348 self.nextthink = self.delay;
350 self.frame = self.frame + 1;
351 if(self.frame > self.t_length)
359 self.nextthink = time + 0.1;
361 // sorry, we have to reset the flag size if it got squished by something
362 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
364 // if we can grow back, grow back
365 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
366 if(!trace_startsolid)
367 setsize(self, FLAG_MIN, FLAG_MAX);
370 if(self == ctf_worldflaglist) // only for the first flag
373 ctf_captureshield_update(e, 1); // release shield only
378 if(self.speedrunning)
379 if(self.cnt == FLAG_CARRY)
382 if(flagcaptimerecord)
383 if(time >= self.flagpickuptime + flagcaptimerecord)
385 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
387 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
388 self.owner.impulse = 141; // returning!
399 if (self.cnt == FLAG_BASE)
402 if (self.cnt == FLAG_DROPPED)
404 // flag fallthrough? FIXME remove this if bug is really fixed now
405 if(self.origin_z < -131072)
407 dprint("FLAG FALLTHROUGH just happened\n");
408 self.pain_finished = 0;
410 setattachment(self, world, "");
411 if (time > self.pain_finished)
413 bprint("The ", self.netname, " has returned to base\n");
414 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
415 LogCTF("returned", self.team, world);
422 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
424 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
425 DropFlag(self, world, world);
429 if(cvar("g_ctf_allow_drop"))
431 DropFlag(self, e, world);
434 void flag_cap_ring_spawn(vector org)
436 shockwave_spawn("models/ctf/shockwavetransring.md3", org - '0 0 15', -0.8, 0, 1);
445 local string s, s0, h0, h1;
446 if (other.classname != "player")
448 if (other.health < 1) // ignore dead players
451 if (self.cnt == FLAG_CARRY)
454 if (self.cnt == FLAG_BASE)
455 if (other.team == self.team)
456 if (other.flagcarried) // he's got a flag
457 if (other.flagcarried.team != self.team) // capture
459 if (other.flagcarried == world)
463 if(cvar("g_ctf_captimerecord_always") || player_count - currentbots <= 1) // at most one human
465 t = time - other.flagcarried.flagpickuptime;
466 s = ftos_decimals(t, 2);
467 s0 = ftos_decimals(flagcaptimerecord, 2);
468 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
473 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
474 if (flagcaptimerecord == 0)
476 s = strcat(" in ", s, " seconds");
477 flagcaptimerecord = t;
478 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
479 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
480 write_recordmarker(other, time - t, t);
482 else if (t < flagcaptimerecord)
484 s = strcat(" in ", s, " seconds, breaking ", h0, " previous record of ", s0, " seconds");
485 flagcaptimerecord = t;
486 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
487 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
488 write_recordmarker(other, time - t, t);
492 s = strcat(" in ", s, " seconds, failing to break ", h0, " record of ", s0, " seconds");
498 Send_KillNotification (other.netname, other.flagcarried.netname, s, INFO_CAPTUREFLAG, MSG_INFO);
500 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
501 LogCTF("capture", other.flagcarried.team, other);
502 // give credit to the individual player
503 UpdateFrags(other, ctf_score_value("score_capture"));
505 if (cvar("g_ctf_flag_capture_effects")) {
506 if (other.team == COLOR_TEAM1) { // red team scores effect
507 pointparticles(particleeffectnum("red_ground_quake"), self.origin, '0 0 0', 1);
508 flag_cap_ring_spawn(self.origin);
510 if (other.team == COLOR_TEAM2) { // blue team scores effect
511 pointparticles(particleeffectnum("blue_ground_quake"), self.origin, '0 0 0', 1);
512 flag_cap_ring_spawn(self.origin);
516 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
517 WaypointSprite_DetachCarrier(other);
518 if(self.speedrunning)
519 FakeTimeLimit(other, -1);
520 RegenFlag (other.flagcarried);
521 other.flagcarried = world;
522 other.next_take_time = time + 1;
524 if (self.cnt == FLAG_BASE)
525 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
526 if (other.team != self.team)
527 if (!other.flagcarried)
528 if (!other.ctf_captureshielded)
530 if (other.next_take_time > time)
533 if (cvar("g_ctf_flag_pickup_effects")) // pickup effect
534 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
537 self.flagpickuptime = time; // used for timing runs
538 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
539 if(other.speedrunning)
540 if(flagcaptimerecord)
541 FakeTimeLimit(other, time + flagcaptimerecord);
542 self.solid = SOLID_NOT;
543 setorigin(self, self.origin); // relink
545 other.flagcarried = self;
546 self.cnt = FLAG_CARRY;
547 self.angles = '0 0 0';
548 //bprint(other.netname, "^7 got the ", self.netname, "\n");
549 Send_KillNotification (other.netname, self.netname, "", INFO_GOTFLAG, MSG_INFO);
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 Send_KillNotification (other.netname, self.netname, "", INFO_RETURNFLAG, MSG_INFO);
577 //bprint(other.netname, "^7 returned the ", self.netname, "\n");
579 // punish the player who last had it
580 FOR_EACH_PLAYER(player)
581 if(player.playerid == self.dropperid)
583 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
584 ctf_captureshield_update(player, 0); // shield only
587 // punish the team who was last carrying it
588 if(self.team == COLOR_TEAM1)
589 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
591 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
593 // reward the player who returned it
594 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
596 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
597 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
599 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
603 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
604 UpdateFrags(other, ctf_score_value("score_return"));
606 UpdateFrags(other, ctf_score_value("score_return_rogue"));
608 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
609 LogCTF("return", self.team, other);
610 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
613 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
615 if(self.waypointsprite_attachedforcarrier)
616 WaypointSprite_DetachCarrier(self);
618 if (cvar("g_ctf_flag_pickup_effects")) // field pickup effect
619 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
622 self.solid = SOLID_NOT;
623 setorigin(self, self.origin); // relink
625 other.flagcarried = self;
626 self.cnt = FLAG_CARRY;
627 Send_KillNotification (other.netname, self.netname, "", INFO_PICKUPFLAG, MSG_INFO);
628 //bprint(other.netname, "^7 picked up the ", self.netname, "\n");
631 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
632 //print("factor is ", ftos(f), "\n");
633 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
634 + ctf_score_value("score_pickup_dropped_early") * f;
636 self.dropperid = other.playerid;
637 //print("score is ", ftos(f), "\n");
639 UpdateFrags(other, f);
640 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
641 LogCTF("pickup", self.team, other);
642 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
644 FOR_EACH_PLAYER(player)
645 if(player.team == self.team)
646 centerprint(player, "The enemy got your flag! Retrieve it!");
648 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
649 setorigin(self, FLAG_CARRY_POS);
650 setattachment(self, other, "");
651 self.damageforcescale = 0;
652 self.takedamage = DAMAGE_NO;
653 WaypointSprite_AttachCarrier("flagcarrier", other);
654 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
659 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
660 CTF Starting point for a player
665 viewing angle when spawning
667 void spawnfunc_info_player_team1()
674 self.team = COLOR_TEAM1; // red
675 spawnfunc_info_player_deathmatch();
677 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
679 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
680 CTF Starting point for a player in
685 viewing angle when spawning
687 void spawnfunc_info_player_team2()
694 self.team = COLOR_TEAM2; // blue
695 spawnfunc_info_player_deathmatch();
697 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
699 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
700 CTF Starting point for a player in
705 viewing angle when spawning
707 void spawnfunc_info_player_team3()
714 self.team = COLOR_TEAM3; // yellow
715 spawnfunc_info_player_deathmatch();
719 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
720 CTF Starting point for a player in
725 viewing angle when spawning
727 void spawnfunc_info_player_team4()
734 self.team = COLOR_TEAM4; // purple
735 spawnfunc_info_player_deathmatch();
738 void item_flag_reset()
740 DropFlag(self, world, world);
741 if(self.waypointsprite_attachedforcarrier)
742 WaypointSprite_DetachCarrier(self);
746 void item_flag_postspawn()
747 { // Check CTF Item Flag Post Spawn
749 // Flag Glow Trail Support
750 if(cvar("g_ctf_flag_glowtrails"))
751 { // Provide Flag Glow Trail
752 if(self.team == COLOR_TEAM1)
754 self.glow_color = 251;
756 if(self.team == COLOR_TEAM2)
758 self.glow_color = 210;
765 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
766 CTF flag for team one (Red).
767 Multiple are allowed.
771 Angle the flag will point
774 model to use, note this needs red and blue as skins 0 and 1
775 (default models/ctf/flag.md3)
777 sound played when flag is picked up
778 (default ctf/take.wav)
780 sound played when flag is returned by a teammate
781 (default ctf/return.wav)
783 sound played when flag is captured
784 (default ctf/redcapture.wav)
786 sound played when flag is lost in the field and respawns itself
787 (default ctf/respawn.wav)
790 void spawnfunc_item_flag_team1()
798 //if(!cvar("teamplay"))
799 // cvar_set("teamplay", "3");
801 // link flag into ctf_worldflaglist
802 self.ctf_worldflagnext = ctf_worldflaglist;
803 ctf_worldflaglist = self;
805 self.classname = "item_flag_team";
808 self.team = COLOR_TEAM2; // color 13 team (blue)
809 self.items = IT_KEY1; // silver key (bluish enough)
813 self.team = COLOR_TEAM1; // color 4 team (red)
814 self.items = IT_KEY2; // gold key (redish enough)
816 self.netname = "^1RED^7 flag";
817 self.target = "###item###";
818 self.skin = cvar("g_ctf_flag_red_skin");
819 if(self.spawnflags & 1)
822 self.model = cvar_string("g_ctf_flag_red_model");
824 self.noise = "ctf/red_taken.wav";
826 self.noise1 = "ctf/red_returned.wav";
828 self.noise2 = "ctf/red_capture.wav"; // blue team scores by capturing the red flag
830 self.noise3 = "ctf/flag_respawn.wav";
832 self.noise4 = "ctf/red_dropped.wav";
833 precache_model (self.model);
834 setmodel (self, self.model); // precision set below
835 precache_sound (self.noise);
836 precache_sound (self.noise1);
837 precache_sound (self.noise2);
838 precache_sound (self.noise3);
839 precache_sound (self.noise4);
840 //setsize(self, '-16 -16 -37', '16 16 37');
841 setsize(self, FLAG_MIN, FLAG_MAX);
842 setorigin(self, self.origin + '0 0 37');
843 self.nextthink = time + 0.2; // start after doors etc
844 self.think = place_flag;
848 //if(!self.glow_size)
849 // self.glow_size = 50;
851 self.effects = self.effects | EF_LOWPRECISION;
852 if(cvar("g_ctf_fullbrightflags"))
853 self.effects |= EF_FULLBRIGHT;
854 if(cvar("g_ctf_dynamiclights"))
855 self.effects |= EF_RED;
858 item_flag_postspawn();
860 precache_model("models/ctf/shield.md3");
861 precache_model("models/ctf/shockwavetransring.md3");
863 self.reset = item_flag_reset;
866 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
867 CTF flag for team two (Blue).
868 Multiple are allowed.
872 Angle the flag will point
875 model to use, note this needs red and blue as skins 0 and 1
876 (default models/ctf/flag.md3)
878 sound played when flag is picked up
879 (default ctf/take.wav)
881 sound played when flag is returned by a teammate
882 (default ctf/return.wav)
884 sound played when flag is captured
885 (default ctf/bluecapture.wav)
887 sound played when flag is lost in the field and respawns itself
888 (default ctf/respawn.wav)
891 void spawnfunc_item_flag_team2()
898 //if(!cvar("teamplay"))
899 // cvar_set("teamplay", "3");
901 // link flag into ctf_worldflaglist
902 self.ctf_worldflagnext = ctf_worldflaglist;
903 ctf_worldflaglist = self;
905 self.classname = "item_flag_team";
908 self.team = COLOR_TEAM1; // color 4 team (red)
909 self.items = IT_KEY2; // gold key (redish enough)
913 self.team = COLOR_TEAM2; // color 13 team (blue)
914 self.items = IT_KEY1; // silver key (bluish enough)
916 self.netname = "^4BLUE^7 flag";
917 self.target = "###item###";
918 self.skin = cvar("g_ctf_flag_blue_skin");
919 if(self.spawnflags & 1)
922 self.model = cvar_string("g_ctf_flag_blue_model");
924 self.noise = "ctf/blue_taken.wav";
926 self.noise1 = "ctf/blue_returned.wav";
928 self.noise2 = "ctf/blue_capture.wav"; // blue team scores by capturing the red flag
930 self.noise3 = "ctf/flag_respawn.wav";
932 self.noise4 = "ctf/blue_dropped.wav";
933 precache_model (self.model);
934 setmodel (self, self.model); // precision set below
935 precache_sound (self.noise);
936 precache_sound (self.noise1);
937 precache_sound (self.noise2);
938 precache_sound (self.noise3);
939 precache_sound (self.noise4);
940 //setsize(self, '-16 -16 -37', '16 16 37');
941 setsize(self, FLAG_MIN, FLAG_MAX);
942 setorigin(self, self.origin + '0 0 37');
943 self.nextthink = time + 0.2; // start after doors etc
944 self.think = place_flag;
948 //if(!self.glow_size)
949 // self.glow_size = 50;
951 self.effects = self.effects | EF_LOWPRECISION;
952 if(cvar("g_ctf_fullbrightflags"))
953 self.effects |= EF_FULLBRIGHT;
954 if(cvar("g_ctf_dynamiclights"))
955 self.effects |= EF_BLUE;
958 item_flag_postspawn();
960 precache_model("models/ctf/shield.md3");
961 precache_model("models/ctf/shockwavetransring.md3");
963 self.reset = item_flag_reset;
967 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
968 Team declaration for CTF gameplay, this allows you to decide what team
969 names and control point models are used in your map.
971 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
972 domination, you don't need to make a blank one too.
976 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
978 Scoreboard color of the team (for example 4 is red and 13 is blue)
982 void spawnfunc_ctf_team()
989 self.classname = "ctf_team";
990 self.team = self.cnt + 1;
993 // code from here on is just to support maps that don't have control point and team entities
994 void ctf_spawnteam (string teamname, float teamcolor)
996 local entity oldself;
999 self.classname = "ctf_team";
1000 self.netname = teamname;
1001 self.cnt = teamcolor;
1003 spawnfunc_ctf_team();
1008 // spawn some default teams if the map is not set up for ctf
1009 void ctf_spawnteams()
1013 numteams = 2;//cvar("g_ctf_default_teams");
1015 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
1016 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
1019 void ctf_delayedinit()
1021 // if no teams are found, spawn defaults
1022 if (find(world, classname, "ctf_team") == world)
1030 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
1031 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
1033 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
1034 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
1035 captureshield_force = cvar("g_ctf_shield_force");
1038 void ctf_setstatus2(entity flag, float shift)
1040 if (flag.cnt == FLAG_CARRY)
1041 if (flag.owner == self)
1042 self.items |= shift * 3;
1044 self.items |= shift * 1;
1045 else if (flag.cnt == FLAG_DROPPED)
1046 self.items |= shift * 2;
1053 void ctf_setstatus()
1055 self.items &~= IT_RED_FLAG_TAKEN;
1056 self.items &~= IT_RED_FLAG_LOST;
1057 self.items &~= IT_BLUE_FLAG_TAKEN;
1058 self.items &~= IT_BLUE_FLAG_LOST;
1059 self.items &~= IT_CTF_SHIELDED;
1063 float redflags, blueflags;
1065 if(self.ctf_captureshielded)
1066 self.items |= IT_CTF_SHIELDED;
1071 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1073 if(flag.items & IT_KEY2) // blue
1075 else if(flag.items & IT_KEY1) // red
1079 // blinking magic: if there is more than one flag, show one of these in a clever way
1081 redflags = mod(floor(time * redflags * 0.75), redflags);
1083 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1085 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1087 if(flag.items & IT_KEY2) // blue
1089 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1090 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1092 else if(flag.items & IT_KEY1) // red
1094 if(--blueflags == -1) // happens exactly once
1095 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1101 entity(float cteam) ctf_team_has_commander =
1104 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1107 FOR_EACH_REALPLAYER(pl) {
1108 if(pl.team == cteam && pl.iscommander) {
1115 void(entity e, float st) ctf_setstate =
1121 void(float cteam) ctf_new_commander =
1126 FOR_EACH_REALPLAYER(pl) {
1127 if(pl.team == cteam) {
1128 if(pl.iscommander) { // don't reassign if alreay there
1131 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1135 if(plmax == world) {
1136 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1140 plmax.iscommander = TRUE;
1141 ctf_setstate(plmax, 3);
1142 sprint(plmax, "^3You're the commander now!\n");
1143 centerprint(plmax, "^3You're the commander now!\n");
1146 void() ctf_clientconnect =
1148 self.iscommander = FALSE;
1150 if(!self.team || self.classname != "player") {
1151 ctf_setstate(self, -1);
1153 ctf_setstate(self, 0);
1155 self.team_saved = self.team;
1157 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1158 ctf_new_commander(self.team);
1162 void() ctf_playerchanged =
1164 if(!self.team || self.classname != "player") {
1165 ctf_setstate(self, -1);
1166 } else if(self.ctf_state < 0 && self.classname == "player") {
1167 ctf_setstate(self, 0);
1170 if(self.iscommander &&
1171 (self.classname != "player" || self.team != self.team_saved)
1174 self.iscommander = FALSE;
1175 if(self.classname == "player")
1176 ctf_setstate(self, 0);
1178 ctf_setstate(self, -1);
1179 ctf_new_commander(self.team_saved);
1182 self.team_saved = self.team;
1184 ctf_new_commander(self.team);
1187 void() ctf_clientdisconnect =
1189 if(self.iscommander)
1191 ctf_new_commander(self.team);
1195 entity GetPlayer(string);
1196 float() ctf_clientcommand =
1199 if(argv(0) == "order") {
1201 sprint(self, "This command is not supported in this gamemode.\n");
1204 if(!self.iscommander) {
1205 sprint(self, "^1You are not the commander!\n");
1209 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1212 e = GetPlayer(argv(1));
1214 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1217 if(e.team != self.team) {
1218 sprint(self, "^3You can only give orders to your own team!\n");
1221 if(argv(2) == "attack") {
1222 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1223 sprint(e, "^1Attack!\n");
1224 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1226 } else if(argv(2) == "defend") {
1227 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1228 sprint(e, "^Defend!\n");
1229 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1232 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");