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 LogCTF(string mode, float flagteam, entity actor)
49 if(!cvar("sv_eventlog"))
51 s = strcat(":ctf:", mode);
52 s = strcat(s, ":", ftos(flagteam));
54 s = strcat(s, ":", ftos(actor.playerid));
55 GameLogEcho(s, FALSE);
58 void(entity e) RegenFlag =
60 e.movetype = MOVETYPE_TOSS;
61 e.solid = SOLID_TRIGGER;
62 // TODO: play a sound here
63 setorigin(e, e.oldorigin);
67 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
70 void(entity e) ReturnFlag =
73 if (e.owner.flagcarried == e)
74 e.owner.flagcarried = world;
79 void(entity e) DropFlag =
85 dprint("FLAG: drop - no owner?!?!\n");
89 if (p.flagcarried != e)
91 dprint("FLAG: drop - owner is not carrying this flag??\n");
96 bprint("^7 lost the RED flag\n");
98 bprint("^7 lost the BLUE flag\n");
99 if (p.flagcarried == e)
100 p.flagcarried = world;
103 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
104 e.solid = SOLID_TRIGGER;
105 e.movetype = MOVETYPE_TOSS;
106 // setsize(e, '-16 -16 0', '16 16 74');
107 setorigin(e, p.origin - '0 0 24');
108 e.cnt = FLAG_DROPPED;
109 e.velocity = '0 0 300';
110 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
115 if(self.delay > time)
117 self.delay = time + self.t_width;
118 if(self.nextthink > self.delay)
119 self.nextthink = self.delay;
121 self.frame = self.frame + 1;
122 if(self.frame > self.t_length)
132 self.nextthink = time + 0.1;
136 if (self.cnt == FLAG_BASE)
139 if (self.cnt == FLAG_DROPPED)
141 if (time > self.pain_finished)
144 bprint("The RED flag has returned to base\n");
146 bprint("The BLUE flag has returned to base\n");
147 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
148 LogCTF("returned", self.team, world);
155 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
158 LogCTF("dropped", self.team, e);
162 // borrowed from threewave CTF, because it would be way too much work
164 makevectors (e.angles);
166 v_z = 0 - v_z; // reverse z
170 if (e.frame >= 29 && e.frame <= 40)
172 if (e.frame >= 29 && e.frame <= 34)
175 if (e.frame == 29) f = f + 2;
176 else if (e.frame == 30) f = f + 8;
177 else if (e.frame == 31) f = f + 12;
178 else if (e.frame == 32) f = f + 11;
179 else if (e.frame == 33) f = f + 10;
180 else if (e.frame == 34) f = f + 4;
182 else if (e.frame >= 35 && e.frame <= 40)
185 if (e.frame == 35) f = f + 2;
186 else if (e.frame == 36) f = f + 10;
187 else if (e.frame == 37) f = f + 10;
188 else if (e.frame == 38) f = f + 8;
189 else if (e.frame == 39) f = f + 4;
190 else if (e.frame == 40) f = f + 2;
193 else if (e.frame >= 103 && e.frame <= 118)
195 if (e.frame >= 103 && e.frame <= 104) f = f + 6; //nailattack
196 else if (e.frame >= 105 && e.frame <= 106) f = f + 6; //light
197 else if (e.frame >= 107 && e.frame <= 112) f = f + 7; //rocketattack
198 else if (e.frame >= 112 && e.frame <= 118) f = f + 7; //shotattack
201 self.angles = e.angles + '0 0 -45';
202 setorigin (self, e.origin + '0 0 0' - f*v + v_right * 22);
203 self.nextthink = time + 0.01;
206 float flagcaptimerecord;
207 .float flagpickuptime;
216 if (other.classname != "player")
218 if (other.health < 1) // ignore dead players
221 if (self.cnt == FLAG_CARRY)
224 if (self.cnt == FLAG_BASE)
225 if (other.team == self.team)
226 if (other.flagcarried) // he's got a flag
227 if (other.flagcarried.team != self.team) // capture
229 if (other.flagcarried == world)
233 t = time - other.flagpickuptime;
234 if (flagcaptimerecord == 0)
236 if (other.flagcarried.team == 5)
237 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), " seconds\n");
239 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), " seconds\n");
240 flagcaptimerecord = t;
242 else if (t < flagcaptimerecord)
244 if (other.flagcarried.team == 5)
245 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
247 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
248 flagcaptimerecord = t;
252 if (other.flagcarried.team == 5)
253 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
255 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
258 LogCTF("capture", other.flagcarried.team, other);
259 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
260 head = find(head, classname, "player");
263 if (head.team == self.team)
264 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
265 head = find(head, classname, "player");
267 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
268 RegenFlag (other.flagcarried);
269 other.flagcarried = world;
270 other.next_take_time = time + 1;
272 if (self.cnt == FLAG_BASE)
273 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
274 if (other.team != self.team)
275 if (!other.flagcarried)
277 if (other.next_take_time > time)
280 other.flagpickuptime = time; // used for timing runs
281 self.solid = SOLID_NOT;
282 setorigin(self, self.origin); // relink
284 other.flagcarried = self;
285 self.cnt = FLAG_CARRY;
286 if (other.flagcarried.team == 5)
287 bprint(other.netname, "^7 got the RED flag\n");
289 bprint(other.netname, "^7 got the BLUE flag\n");
290 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
291 LogCTF("steal", self.team, other);
292 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
294 player = find(world, classname, "player");
296 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
297 player = find(player, classname, "player");
303 if (self.cnt == FLAG_DROPPED)
305 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
306 if (other.team == self.team || (other.team != 5 && other.team != 14))
310 bprint(other.netname, "^7 returned the RED flag\n");
312 bprint(other.netname, "^7 returned the BLUE flag\n");
313 if (other.team == 5 || other.team == 14)
314 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
316 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
317 LogCTF("return", self.team, other);
318 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
321 else if (!other.flagcarried)
324 other.flagpickuptime = time; // used for timing runs
325 self.solid = SOLID_NOT;
326 setorigin(self, self.origin); // relink
328 other.flagcarried = self;
329 self.cnt = FLAG_CARRY;
331 bprint(other.netname, "^7 picked up the RED flag\n");
333 bprint(other.netname, "^7 picked up the BLUE flag\n");
334 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
335 LogCTF("pickup", self.team, other);
336 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
338 player = find(world, classname, "player");
340 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
341 player = find(player, classname, "player");
347 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
348 CTF Starting point for a player
353 viewing angle when spawning
355 void() info_player_team1 =
357 self.classname = "info_player_deathmatch";
358 self.team = 5; // red
359 relocate_spawnpoint();
361 //self.team = 4;self.classname = "info_player_start";info_player_start();};
363 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
364 CTF Starting point for a player in
369 viewing angle when spawning
371 void() info_player_team2 =
373 self.classname = "info_player_deathmatch";
374 self.team = 14; // blue
375 relocate_spawnpoint();
377 //self.team = 13;self.classname = "info_player_start";info_player_start();};
379 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
380 CTF Starting point for a player in
381 team three (Magenta).
385 viewing angle when spawning
387 void() info_player_team3 =
389 self.classname = "info_player_deathmatch";
390 self.team = 10; // purple
391 relocate_spawnpoint();
395 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
396 CTF Starting point for a player in
401 viewing angle when spawning
403 void() info_player_team4 =
405 self.classname = "info_player_deathmatch";
406 self.team = 13; // yellow
407 relocate_spawnpoint();
413 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
414 CTF flag for team one (Red).
415 Multiple are allowed.
419 Angle the flag will point
422 model to use, note this needs red and blue as skins 0 and 1
423 (default models/ctf/flag.md3)
425 sound played when flag is picked up
426 (default ctf/take.wav)
428 sound played when flag is returned by a teammate
429 (default ctf/return.wav)
431 sound played when flag is captured
432 (default ctf/capture.wav)
434 sound played when flag is lost in the field and respawns itself
435 (default ctf/respawn.wav)
438 void() item_flag_team1 =
442 //if(!cvar("teamplay"))
443 // cvar_set("teamplay", "3");
445 self.team = 5; // color 4 team (red)
446 self.items = IT_KEY2; // gold key (redish enough)
449 self.model = "models/ctf/flag_red.md3";
451 self.noise = "ctf/take.wav";
453 self.noise1 = "ctf/return.wav";
455 self.noise2 = "ctf/capture.wav";
457 self.noise3 = "ctf/respawn.wav";
458 precache_model (self.model);
459 setmodel (self, self.model);
460 precache_sound (self.noise);
461 precache_sound (self.noise1);
462 precache_sound (self.noise2);
463 precache_sound (self.noise3);
464 setsize(self, '-16 -16 -37', '16 16 37');
465 setorigin(self, self.origin + '0 0 37');
466 self.nextthink = time + 0.2; // start after doors etc
467 self.think = place_flag;
471 //if(!self.glow_size)
472 // self.glow_size = 50;
474 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
477 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
478 CTF flag for team two (Blue).
479 Multiple are allowed.
483 Angle the flag will point
488 void() item_flag_team2 =
492 //if(!cvar("teamplay"))
493 // cvar_set("teamplay", "3");
495 self.team = 14; // color 13 team (blue)
496 self.items = IT_KEY1; // silver key (bluish enough)
499 self.model = "models/ctf/flag_blue.md3";
501 self.noise = "ctf/take.wav";
503 self.noise1 = "ctf/return.wav";
505 self.noise2 = "ctf/capture.wav";
507 self.noise3 = "ctf/respawn.wav";
508 precache_model (self.model);
509 setmodel (self, self.model);
510 precache_sound (self.noise);
511 precache_sound (self.noise1);
512 precache_sound (self.noise2);
513 precache_sound (self.noise3);
514 setsize(self, '-16 -16 -37', '16 16 37');
515 setorigin(self, self.origin + '0 0 37');
516 self.nextthink = time + 0.2; // start after doors etc
517 self.think = place_flag;
521 //if(!self.glow_size)
522 // self.glow_size = 50;
524 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
528 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
529 Team declaration for CTF gameplay, this allows you to decide what team
530 names and control point models are used in your map.
532 Note: If you use ctf_team entities you must define at least 2! However, unlike
533 domination, you don't need to make a blank one too.
537 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
539 Scoreboard color of the team (for example 4 is red and 13 is blue)
545 self.classname = "ctf_team";
546 self.team = self.cnt + 1;
549 // code from here on is just to support maps that don't have control point and team entities
550 void ctf_spawnteam (string teamname, float teamcolor)
552 local entity oldself;
555 self.classname = "ctf_team";
556 self.netname = teamname;
557 self.cnt = teamcolor;
564 // spawn some default teams if the map is not set up for ctf
565 void() ctf_spawnteams =
569 numteams = 2;//cvar("g_ctf_default_teams");
571 ctf_spawnteam("Red", 4);
572 ctf_spawnteam("Blue", 13);
575 void() ctf_delayedinit =
577 self.think = SUB_Remove;
578 self.nextthink = time;
579 // if no teams are found, spawn defaults
580 if (find(world, classname, "ctf_team") == world)
588 e.think = ctf_delayedinit;
589 e.nextthink = time + 0.1;