2 .float next_take_time; // the next time a player can pick up a flag (time + blah)
3 /// I used this, in part, to fix the looping score bug. - avirox
5 //float FLAGSCORE_PICKUP = 1;
6 //float FLAGSCORE_RETURN = 5; // returned by owner team
7 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
8 //float FLAGSCORE_CAPTURE = 5;
9 //float FLAGSCORE_CAPTURE_TEAM = 20;
13 float FLAG_DROPPED = 3;
21 self.t_width = 0.1; // frame animation rate
23 self.t_length = 119; // maximum frame
25 self.mdl = self.model;
27 self.solid = SOLID_TRIGGER;
28 self.movetype = MOVETYPE_TOSS;
29 self.velocity = '0 0 0';
30 self.origin_z = self.origin_z + 6;
31 self.think = FlagThink;
32 self.touch = FlagTouch;
33 self.nextthink = time + 0.1;
35 self.mangle = self.angles;
36 //self.effects = self.effects | EF_DIMLIGHT;
37 if (!droptofloor(0, 0))
39 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
43 self.oldorigin = self.origin;
46 void(entity e) RegenFlag =
48 e.movetype = MOVETYPE_TOSS;
49 e.solid = SOLID_TRIGGER;
50 // TODO: play a sound here
51 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
52 setorigin(e, e.oldorigin);
56 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
59 void(entity e) ReturnFlag =
62 if (e.owner.flagcarried == e)
63 e.owner.flagcarried = world;
68 void(entity e) DropFlag =
74 dprint("FLAG: drop - no owner?!?!\n");
78 if (p.flagcarried != e)
80 dprint("FLAG: drop - owner is not carrying this flag??\n");
85 bprint("^7 lost the RED flag\n");
87 bprint("^7 lost the BLUE flag\n");
88 if (p.flagcarried == e)
89 p.flagcarried = world;
92 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
93 e.solid = SOLID_TRIGGER;
94 e.movetype = MOVETYPE_TOSS;
95 // setsize(e, '-16 -16 0', '16 16 74');
96 setorigin(e, p.origin - '0 0 24');
98 e.velocity = '0 0 300';
99 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
104 if(self.delay > time)
106 self.delay = time + self.t_width;
107 if(self.nextthink > self.delay)
108 self.nextthink = self.delay;
110 self.frame = self.frame + 1;
111 if(self.frame > self.t_length)
121 self.nextthink = time + 0.1;
125 if (self.cnt == FLAG_BASE)
128 if (self.cnt == FLAG_DROPPED)
130 if (time > self.pain_finished)
133 bprint("The RED flag has returned to base\n");
135 bprint("The BLUE flag has returned to base\n");
142 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
148 // borrowed from threewave CTF, because it would be way too much work
150 makevectors (e.angles);
152 v_z = 0 - v_z; // reverse z
156 if (e.frame >= 29 && e.frame <= 40)
158 if (e.frame >= 29 && e.frame <= 34)
161 if (e.frame == 29) f = f + 2;
162 else if (e.frame == 30) f = f + 8;
163 else if (e.frame == 31) f = f + 12;
164 else if (e.frame == 32) f = f + 11;
165 else if (e.frame == 33) f = f + 10;
166 else if (e.frame == 34) f = f + 4;
168 else if (e.frame >= 35 && e.frame <= 40)
171 if (e.frame == 35) f = f + 2;
172 else if (e.frame == 36) f = f + 10;
173 else if (e.frame == 37) f = f + 10;
174 else if (e.frame == 38) f = f + 8;
175 else if (e.frame == 39) f = f + 4;
176 else if (e.frame == 40) f = f + 2;
179 else if (e.frame >= 103 && e.frame <= 118)
181 if (e.frame >= 103 && e.frame <= 104) f = f + 6; //nailattack
182 else if (e.frame >= 105 && e.frame <= 106) f = f + 6; //light
183 else if (e.frame >= 107 && e.frame <= 112) f = f + 7; //rocketattack
184 else if (e.frame >= 112 && e.frame <= 118) f = f + 7; //shotattack
187 self.angles = e.angles + '0 0 -45';
188 setorigin (self, e.origin + '0 0 0' - f*v + v_right * 22);
189 self.nextthink = time + 0.01;
192 float flagcaptimerecord;
193 .float flagpickuptime;
202 if (other.classname != "player")
204 if (other.health < 1) // ignore dead players
207 if (self.cnt == FLAG_CARRY)
210 if (self.cnt == FLAG_BASE)
211 if (other.team == self.team)
212 if (other.flagcarried) // he's got a flag
213 if (other.flagcarried.team != self.team) // capture
215 if (other.flagcarried == world)
219 t = time - other.flagpickuptime;
220 if (flagcaptimerecord == 0)
222 if (other.flagcarried.team == 5)
223 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), " seconds\n");
225 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), " seconds\n");
226 flagcaptimerecord = t;
228 else if (t < flagcaptimerecord)
230 if (other.flagcarried.team == 5)
231 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
233 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
234 flagcaptimerecord = t;
238 if (other.flagcarried.team == 5)
239 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
241 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
244 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
245 head = find(head, classname, "player");
248 if (head.team == self.team)
249 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
250 head = find(head, classname, "player");
252 RegenFlag (other.flagcarried);
253 other.flagcarried = world;
254 other.next_take_time = time + 1;
256 if (self.cnt == FLAG_BASE)
257 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
258 if (other.team != self.team)
259 if (!other.flagcarried)
261 if (other.next_take_time > time)
264 other.flagpickuptime = time; // used for timing runs
265 self.solid = SOLID_NOT;
266 setorigin(self, self.origin); // relink
268 other.flagcarried = self;
269 self.cnt = FLAG_CARRY;
270 if (other.flagcarried.team == 5)
271 bprint(other.netname, "^7 got the RED flag\n");
273 bprint(other.netname, "^7 got the BLUE flag\n");
274 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
275 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
277 player = find(world, classname, "player");
279 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
280 player = find(player, classname, "player");
286 if (self.cnt == FLAG_DROPPED)
288 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
289 if (other.team == self.team || (other.team != 5 && other.team != 14))
293 bprint(other.netname, "^7 returned the RED flag\n");
295 bprint(other.netname, "^7 returned the BLUE flag\n");
296 if (other.team == 5 || other.team == 14)
297 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
299 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
300 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
303 else if (!other.flagcarried)
306 other.flagpickuptime = time; // used for timing runs
307 self.solid = SOLID_NOT;
308 setorigin(self, self.origin); // relink
310 other.flagcarried = self;
311 self.cnt = FLAG_CARRY;
313 bprint(other.netname, "^7 picked up the RED flag\n");
315 bprint(other.netname, "^7 picked up the BLUE flag\n");
316 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
317 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
319 player = find(world, classname, "player");
321 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
322 player = find(player, classname, "player");
328 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
329 CTF Starting point for a player
334 viewing angle when spawning
336 void() info_player_team1 =
338 self.classname = "info_player_deathmatch";
339 self.team = 5; // red
341 //self.team = 4;self.classname = "info_player_start";info_player_start();};
343 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
344 CTF Starting point for a player in
349 viewing angle when spawning
351 void() info_player_team2 =
353 self.classname = "info_player_deathmatch";
354 self.team = 14; // blue
356 //self.team = 13;self.classname = "info_player_start";info_player_start();};
358 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
359 CTF Starting point for a player in
360 team three (Magenta).
364 viewing angle when spawning
366 void() info_player_team3 =
368 self.classname = "info_player_deathmatch";
369 self.team = 10; // purple
373 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
374 CTF Starting point for a player in
379 viewing angle when spawning
381 void() info_player_team4 =
383 self.classname = "info_player_deathmatch";
384 self.team = 13; // yellow
390 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
391 CTF flag for team one (Red).
392 Multiple are allowed.
396 Angle the flag will point
399 model to use, note this needs red and blue as skins 0 and 1
400 (default models/ctf/flag.md3)
402 sound played when flag is picked up
403 (default ctf/take.wav)
405 sound played when flag is returned by a teammate
406 (default ctf/return.wav)
408 sound played when flag is captured
409 (default ctf/capture.wav)
411 sound played when flag is lost in the field and respawns itself
412 (default ctf/respawn.wav)
415 void() item_flag_team1 =
419 //if(!cvar("teamplay"))
420 // cvar_set("teamplay", "3");
422 self.team = 5; // color 4 team (red)
423 self.items = IT_KEY2; // gold key (redish enough)
426 self.model = "models/ctf/flag_red.md3";
428 self.noise = "ctf/take.wav";
430 self.noise1 = "ctf/return.wav";
432 self.noise2 = "ctf/capture.wav";
434 self.noise3 = "ctf/respawn.wav";
435 precache_model (self.model);
436 setmodel (self, self.model);
437 precache_sound (self.noise);
438 precache_sound (self.noise1);
439 precache_sound (self.noise2);
440 precache_sound (self.noise3);
441 setsize(self, '-16 -16 -37', '16 16 37');
442 setorigin(self, self.origin + '0 0 37');
443 self.nextthink = time + 0.2; // start after doors etc
444 self.think = place_flag;
448 //if(!self.glow_size)
449 // self.glow_size = 50;
451 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
454 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
455 CTF flag for team two (Blue).
456 Multiple are allowed.
460 Angle the flag will point
465 void() item_flag_team2 =
469 //if(!cvar("teamplay"))
470 // cvar_set("teamplay", "3");
472 self.team = 14; // color 13 team (blue)
473 self.items = IT_KEY1; // silver key (bluish enough)
476 self.model = "models/ctf/flag_blue.md3";
478 self.noise = "ctf/take.wav";
480 self.noise1 = "ctf/return.wav";
482 self.noise2 = "ctf/capture.wav";
484 self.noise3 = "ctf/respawn.wav";
485 precache_model (self.model);
486 setmodel (self, self.model);
487 precache_sound (self.noise);
488 precache_sound (self.noise1);
489 precache_sound (self.noise2);
490 precache_sound (self.noise3);
491 setsize(self, '-16 -16 -37', '16 16 37');
492 setorigin(self, self.origin + '0 0 37');
493 self.nextthink = time + 0.2; // start after doors etc
494 self.think = place_flag;
498 //if(!self.glow_size)
499 // self.glow_size = 50;
501 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
505 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
506 Team declaration for CTF gameplay, this allows you to decide what team
507 names and control point models are used in your map.
509 Note: If you use ctf_team entities you must define at least 2! However, unlike
510 domination, you don't need to make a blank one too.
514 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
516 Scoreboard color of the team (for example 4 is red and 13 is blue)
522 self.classname = "ctf_team";
523 self.team = self.cnt + 1;
526 // code from here on is just to support maps that don't have control point and team entities
527 void ctf_spawnteam (string teamname, float teamcolor)
529 local entity oldself;
532 self.classname = "ctf_team";
533 self.netname = teamname;
534 self.cnt = teamcolor;
541 // spawn some default teams if the map is not set up for ctf
542 void() ctf_spawnteams =
546 numteams = 2;//cvar("g_ctf_default_teams");
548 ctf_spawnteam("Red", 4);
549 ctf_spawnteam("Blue", 13);
552 void() ctf_delayedinit =
554 self.think = SUB_Remove;
555 self.nextthink = time;
556 // if no teams are found, spawn defaults
557 if (find(world, classname, "ctf_team") == world)
565 e.think = ctf_delayedinit;
566 e.nextthink = time + 0.1;