2 entity flaglist; // CTF flags in the map
4 .float next_take_time; // the next time a player can pick up a flag (time + blah)
5 /// I used this, in part, to fix the looping score bug. - avirox
7 //float FLAGSCORE_PICKUP = 1;
8 //float FLAGSCORE_RETURN = 5; // returned by owner team
9 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
10 //float FLAGSCORE_CAPTURE = 5;
11 //float FLAGSCORE_CAPTURE_TEAM = 20;
13 #define FLAG_CARRY_POS '-15 0 7'
15 void FakeTimeLimit(entity e, float t)
18 WriteByte(MSG_ONE, 3); // svc_updatestat
19 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
21 WriteCoord(MSG_ONE, cvar("timelimit"));
23 WriteCoord(MSG_ONE, (t + 1) / 60);
26 float flagcaptimerecord;
27 .float flagpickuptime;
35 self.t_width = 0.1; // frame animation rate
37 self.t_length = 119; // maximum frame
39 setattachment(self, world, "");
40 self.mdl = self.model;
42 self.solid = SOLID_TRIGGER;
43 self.movetype = MOVETYPE_NONE;
44 self.velocity = '0 0 0';
45 self.origin_z = self.origin_z + 6;
46 self.think = FlagThink;
47 self.touch = FlagTouch;
48 self.nextthink = time + 0.1;
50 self.mangle = self.angles;
51 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
52 //self.effects = self.effects | EF_DIMLIGHT;
55 self.movetype = MOVETYPE_TOSS;
58 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
63 self.oldorigin = self.origin;
66 void LogCTF(string mode, float flagteam, entity actor)
69 if(!cvar("sv_eventlog"))
71 s = strcat(":ctf:", mode);
72 s = strcat(s, ":", ftos(flagteam));
74 s = strcat(s, ":", ftos(actor.playerid));
75 GameLogEcho(s, FALSE);
78 void(entity e) RegenFlag =
80 setattachment(e, world, "");
81 e.movetype = MOVETYPE_NONE;
83 e.movetype = MOVETYPE_TOSS;
84 e.solid = SOLID_TRIGGER;
85 // TODO: play a sound here
86 setorigin(e, e.oldorigin);
90 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
93 void(entity e) ReturnFlag =
96 if (e.owner.flagcarried == e)
98 WaypointSprite_DetachCarrier(e.owner);
99 e.owner.flagcarried = world;
102 FakeTimeLimit(e.owner, -1);
108 void(entity e) DropFlag =
120 dprint("FLAG: drop - no owner?!?!\n");
124 if (p.flagcarried != e)
126 dprint("FLAG: drop - owner is not carrying this flag??\n");
129 bprint(p.netname, "^7 lost the ", e.netname, "\n");
130 WaypointSprite_DetachCarrier(p);
131 LogCTF("dropped", p.team, p.flagcarried);
133 setattachment(e, world, "");
135 if (p.flagcarried == e)
136 p.flagcarried = world;
139 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
140 e.solid = SOLID_TRIGGER;
141 e.movetype = MOVETYPE_TOSS;
142 // setsize(e, '-16 -16 0', '16 16 74');
143 setorigin(e, p.origin - '0 0 24' + '0 0 37');
144 e.cnt = FLAG_DROPPED;
145 e.velocity = '0 0 300';
146 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
148 trace_startsolid = FALSE;
149 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
151 dprint("FLAG FALLTHROUGH will happen SOON\n");
156 if(self.delay > time)
158 self.delay = time + self.t_width;
159 if(self.nextthink > self.delay)
160 self.nextthink = self.delay;
162 self.frame = self.frame + 1;
163 if(self.frame > self.t_length)
171 self.nextthink = time + 0.1;
175 if(self.speedrunning)
176 if(self.cnt == FLAG_CARRY)
179 if(flagcaptimerecord)
180 if(time >= self.flagpickuptime + flagcaptimerecord)
182 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
184 self.owner.impulse = 77; // returning!
194 if (self.cnt == FLAG_BASE)
197 if (self.cnt == FLAG_DROPPED)
199 // flag fallthrough? FIXME remove this if bug is really fixed now
200 if(self.origin_z < -131072)
202 dprint("FLAG FALLTHROUGH just happened\n");
203 self.pain_finished = 0;
205 setattachment(self, world, "");
206 if (time > self.pain_finished)
208 bprint("The ", self.netname, " has returned to base\n");
209 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
210 LogCTF("returned", self.team, world);
217 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
219 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
232 local string s, s0, h0, h1;
233 if (other.classname != "player")
235 if (other.health < 1) // ignore dead players
238 if (self.cnt == FLAG_CARRY)
241 if (self.cnt == FLAG_BASE)
242 if (other.team == self.team)
243 if (other.flagcarried) // he's got a flag
244 if (other.flagcarried.team != self.team) // capture
246 if (other.flagcarried == world)
250 t = time - other.flagcarried.flagpickuptime;
251 s = ftos_decimals(t, 2);
252 s0 = ftos_decimals(flagcaptimerecord, 2);
253 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
254 h1 = strreplace("\\", "\xDC", other.netname); // h1: current netname, escaped for DB (\ is 5C, other \ is DC)
258 h0 = strcat(strreplace("\xDC", "\\", h0), "^7's"); // h0: display text for previous netname
259 if (flagcaptimerecord == 0)
261 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
262 flagcaptimerecord = t;
263 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
264 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
266 else if (t < flagcaptimerecord)
268 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
269 flagcaptimerecord = t;
270 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
271 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
275 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
278 LogCTF("capture", other.flagcarried.team, other);
279 // give credit to the individual player
280 UpdateFrags(other, cvar("g_ctf_flagscore_capture"));
282 // give credit to all players of the team (rewards large teams)
283 // NOTE: this defaults to 0
284 FOR_EACH_PLAYER(head)
285 if (head.team == self.team)
286 UpdateFrags(head, cvar("g_ctf_flagscore_capture_team"));
288 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
289 WaypointSprite_DetachCarrier(other);
290 if(self.speedrunning)
291 FakeTimeLimit(other, -1);
292 RegenFlag (other.flagcarried);
293 other.flagcarried = world;
294 other.next_take_time = time + 1;
296 if (self.cnt == FLAG_BASE)
297 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
298 if (other.team != self.team)
299 if (!other.flagcarried)
301 if (other.next_take_time > time)
304 self.flagpickuptime = time; // used for timing runs
305 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
306 if(other.speedrunning)
307 if(flagcaptimerecord)
308 FakeTimeLimit(other, time + flagcaptimerecord);
309 self.solid = SOLID_NOT;
310 setorigin(self, self.origin); // relink
312 other.flagcarried = self;
313 self.cnt = FLAG_CARRY;
314 self.angles = '0 0 0';
315 bprint(other.netname, "^7 got the ", self.netname, "\n");
316 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
317 LogCTF("steal", self.team, other);
318 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
320 FOR_EACH_PLAYER(player)
321 if(player.team == self.team)
322 centerprint(player, "The enemy got your flag! Retrieve it!");
324 self.movetype = MOVETYPE_NONE;
325 setorigin(self, FLAG_CARRY_POS);
326 setattachment(self, other, "");
327 WaypointSprite_AttachCarrier("flagcarrier", other);
332 if (self.cnt == FLAG_DROPPED)
334 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
335 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
338 bprint(other.netname, "^7 returned the ", self.netname, "\n");
339 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
340 UpdateFrags(other, cvar("g_ctf_flagscore_return"));
342 UpdateFrags(other, cvar("g_ctf_flagscore_return_rogue"));
343 LogCTF("return", self.team, other);
344 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
347 else if (!other.flagcarried)
350 self.solid = SOLID_NOT;
351 setorigin(self, self.origin); // relink
353 other.flagcarried = self;
354 self.cnt = FLAG_CARRY;
355 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
356 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
357 LogCTF("pickup", self.team, other);
358 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
360 FOR_EACH_PLAYER(player)
361 if(player.team == self.team)
362 centerprint(player, "The enemy got your flag! Retrieve it!");
364 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
365 setorigin(self, FLAG_CARRY_POS);
366 setattachment(self, other, "");
367 WaypointSprite_AttachCarrier("flagcarrier", other);
372 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
373 CTF Starting point for a player
378 viewing angle when spawning
380 void() info_player_team1 =
382 self.team = COLOR_TEAM1; // red
383 info_player_deathmatch();
385 //self.team = 4;self.classname = "info_player_start";info_player_start();};
387 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
388 CTF Starting point for a player in
393 viewing angle when spawning
395 void() info_player_team2 =
397 self.team = COLOR_TEAM2; // blue
398 info_player_deathmatch();
400 //self.team = 13;self.classname = "info_player_start";info_player_start();};
402 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
403 CTF Starting point for a player in
404 team three (Magenta).
408 viewing angle when spawning
410 void() info_player_team3 =
412 self.team = COLOR_TEAM3; // purple
413 info_player_deathmatch();
417 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
418 CTF Starting point for a player in
423 viewing angle when spawning
425 void() info_player_team4 =
427 self.team = COLOR_TEAM4; // yellow
428 info_player_deathmatch();
434 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
435 CTF flag for team one (Red).
436 Multiple are allowed.
440 Angle the flag will point
443 model to use, note this needs red and blue as skins 0 and 1
444 (default models/ctf/flag.md3)
446 sound played when flag is picked up
447 (default ctf/take.wav)
449 sound played when flag is returned by a teammate
450 (default ctf/return.wav)
452 sound played when flag is captured
453 (default ctf/capture.wav)
455 sound played when flag is lost in the field and respawns itself
456 (default ctf/respawn.wav)
459 void() item_flag_team1 =
464 //if(!cvar("teamplay"))
465 // cvar_set("teamplay", "3");
467 // link flag into flaglist
468 self.enemy = flaglist;
471 self.classname = "item_flag_team";
472 self.team = COLOR_TEAM1; // color 4 team (red)
473 self.items = IT_KEY2; // gold key (redish enough)
474 self.netname = "^1RED^7 flag";
475 self.target = "###item###";
477 if(self.spawnflags & 1)
480 self.model = "models/ctf/flag_red.md3";
482 self.noise = "ctf/take.wav";
484 self.noise1 = "ctf/return.wav";
486 self.noise2 = "ctf/capture.wav";
488 self.noise3 = "ctf/respawn.wav";
489 precache_model (self.model);
490 setmodel (self, self.model); // precision set below
491 precache_sound (self.noise);
492 precache_sound (self.noise1);
493 precache_sound (self.noise2);
494 precache_sound (self.noise3);
495 setsize(self, '-16 -16 -37', '16 16 37');
496 setorigin(self, self.origin + '0 0 37');
497 self.nextthink = time + 0.2; // start after doors etc
498 self.think = place_flag;
502 //if(!self.glow_size)
503 // self.glow_size = 50;
505 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
509 waypoint_spawnforitem(self);
511 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
514 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
515 CTF flag for team two (Blue).
516 Multiple are allowed.
520 Angle the flag will point
525 void() item_flag_team2 =
529 //if(!cvar("teamplay"))
530 // cvar_set("teamplay", "3");
532 // link flag into flaglist
533 self.enemy = flaglist;
536 self.classname = "item_flag_team";
537 self.team = COLOR_TEAM2; // color 13 team (blue)
538 self.items = IT_KEY1; // silver key (bluish enough)
539 self.netname = "^4BLUE^7 flag";
540 self.target = "###item###";
542 if(self.spawnflags & 1)
545 self.model = "models/ctf/flag_blue.md3";
547 self.noise = "ctf/take.wav";
549 self.noise1 = "ctf/return.wav";
551 self.noise2 = "ctf/capture.wav";
553 self.noise3 = "ctf/respawn.wav";
554 precache_model (self.model);
555 setmodel (self, self.model); // precision set below
556 precache_sound (self.noise);
557 precache_sound (self.noise1);
558 precache_sound (self.noise2);
559 precache_sound (self.noise3);
560 setsize(self, '-16 -16 -37', '16 16 37');
561 setorigin(self, self.origin + '0 0 37');
562 self.nextthink = time + 0.2; // start after doors etc
563 self.think = place_flag;
567 //if(!self.glow_size)
568 // self.glow_size = 50;
570 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
574 waypoint_spawnforitem(self);
576 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
580 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
581 Team declaration for CTF gameplay, this allows you to decide what team
582 names and control point models are used in your map.
584 Note: If you use ctf_team entities you must define at least 2! However, unlike
585 domination, you don't need to make a blank one too.
589 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
591 Scoreboard color of the team (for example 4 is red and 13 is blue)
597 self.classname = "ctf_team";
598 self.team = self.cnt + 1;
601 // code from here on is just to support maps that don't have control point and team entities
602 void ctf_spawnteam (string teamname, float teamcolor)
604 local entity oldself;
607 self.classname = "ctf_team";
608 self.netname = teamname;
609 self.cnt = teamcolor;
616 // spawn some default teams if the map is not set up for ctf
617 void() ctf_spawnteams =
621 numteams = 2;//cvar("g_ctf_default_teams");
623 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
624 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
627 void() ctf_delayedinit =
629 self.think = SUB_Remove;
630 self.nextthink = time;
631 // if no teams are found, spawn defaults
632 if (find(world, classname, "ctf_team") == world)
640 e.think = ctf_delayedinit;
641 e.nextthink = time + 0.1;
642 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
645 void(entity flag) ctf_setstatus2 =
649 if (flag.team == COLOR_TEAM1) shift = IT_RED_FLAG_TAKEN;
650 else if (flag.team == COLOR_TEAM2) shift = IT_BLUE_FLAG_TAKEN;
654 if (flag.cnt == FLAG_CARRY)
655 if (flag.owner == self) status = 3;
657 else if (flag.cnt == FLAG_DROPPED) status = 2;
660 self.items = self.items | (shift * status);
664 void() ctf_setstatus =
666 self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
667 self.items = self.items - (self.items & IT_RED_FLAG_LOST);
668 self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
669 self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
676 ctf_setstatus2(flag);