3 .float next_take_time; // the next time a player can pick up a flag (time + blah)
4 /// I used this, in part, to fix the looping score bug. - avirox
6 //float FLAGSCORE_PICKUP = 1;
7 //float FLAGSCORE_RETURN = 5; // returned by owner team
8 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
9 //float FLAGSCORE_CAPTURE = 5;
10 //float FLAGSCORE_CAPTURE_TEAM = 20;
14 float FLAG_DROPPED = 3;
22 self.t_width = 0.1; // frame animation rate
24 self.t_length = 119; // maximum frame
26 self.mdl = self.model;
28 self.solid = SOLID_TRIGGER;
29 self.movetype = MOVETYPE_TOSS;
30 self.velocity = '0 0 0';
31 self.origin_z = self.origin_z + 6;
32 self.think = FlagThink;
33 self.touch = FlagTouch;
34 self.nextthink = time + 0.1;
36 self.mangle = self.angles;
37 //self.effects = self.effects | EF_DIMLIGHT;
38 if (!droptofloor(0, 0))
40 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
44 self.oldorigin = self.origin;
47 void(entity e) RegenFlag =
49 e.movetype = MOVETYPE_TOSS;
50 e.solid = SOLID_TRIGGER;
51 // TODO: play a sound here
52 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
53 setorigin(e, e.oldorigin);
57 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
60 void(entity e) ReturnFlag =
63 if (e.owner.flagcarried == e)
64 e.owner.flagcarried = world;
69 void(entity e) DropFlag =
75 dprint("FLAG: drop - no owner?!?!\n");
79 if (p.flagcarried != e)
81 dprint("FLAG: drop - owner is not carrying this flag??\n");
86 bprint("^7 lost the RED flag\n");
88 bprint("^7 lost the BLUE flag\n");
89 if (p.flagcarried == e)
90 p.flagcarried = world;
93 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
94 e.solid = SOLID_TRIGGER;
95 e.movetype = MOVETYPE_TOSS;
96 // setsize(e, '-16 -16 0', '16 16 74');
97 setorigin(e, p.origin - '0 0 24');
99 e.velocity = '0 0 300';
100 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
105 if(self.delay > time)
107 self.delay = time + self.t_width;
108 if(self.nextthink > self.delay)
109 self.nextthink = self.delay;
111 self.frame = self.frame + 1;
112 if(self.frame > self.t_length)
122 self.nextthink = time + 0.1;
126 if (self.cnt == FLAG_BASE)
129 if (self.cnt == FLAG_DROPPED)
131 if (time > self.pain_finished)
134 bprint("The RED flag has returned to base\n");
136 bprint("The BLUE flag has returned to base\n");
143 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
149 // borrowed from threewave CTF, because it would be way too much work
151 makevectors (e.angles);
153 v_z = 0 - v_z; // reverse z
157 if (e.frame >= 29 && e.frame <= 40)
159 if (e.frame >= 29 && e.frame <= 34)
162 if (e.frame == 29) f = f + 2;
163 else if (e.frame == 30) f = f + 8;
164 else if (e.frame == 31) f = f + 12;
165 else if (e.frame == 32) f = f + 11;
166 else if (e.frame == 33) f = f + 10;
167 else if (e.frame == 34) f = f + 4;
169 else if (e.frame >= 35 && e.frame <= 40)
172 if (e.frame == 35) f = f + 2;
173 else if (e.frame == 36) f = f + 10;
174 else if (e.frame == 37) f = f + 10;
175 else if (e.frame == 38) f = f + 8;
176 else if (e.frame == 39) f = f + 4;
177 else if (e.frame == 40) f = f + 2;
180 else if (e.frame >= 103 && e.frame <= 118)
182 if (e.frame >= 103 && e.frame <= 104) f = f + 6; //nailattack
183 else if (e.frame >= 105 && e.frame <= 106) f = f + 6; //light
184 else if (e.frame >= 107 && e.frame <= 112) f = f + 7; //rocketattack
185 else if (e.frame >= 112 && e.frame <= 118) f = f + 7; //shotattack
188 self.angles = e.angles + '0 0 -45';
189 setorigin (self, e.origin + '0 0 0' - f*v + v_right * 22);
190 self.nextthink = time + 0.01;
193 float flagcaptimerecord;
194 .float flagpickuptime;
203 if (other.classname != "player")
205 if (other.health < 1) // ignore dead players
208 if (self.cnt == FLAG_CARRY)
211 if (self.cnt == FLAG_BASE)
212 if (other.team == self.team)
213 if (other.flagcarried) // he's got a flag
214 if (other.flagcarried.team != self.team) // capture
216 if (other.flagcarried == world)
220 t = time - other.flagpickuptime;
221 if (flagcaptimerecord == 0)
223 if (other.flagcarried.team == 5)
224 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), " seconds\n");
226 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), " seconds\n");
227 flagcaptimerecord = t;
229 else if (t < flagcaptimerecord)
231 if (other.flagcarried.team == 5)
232 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
234 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
235 flagcaptimerecord = t;
239 if (other.flagcarried.team == 5)
240 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
242 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
245 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
246 head = find(head, classname, "player");
249 if (head.team == self.team)
250 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
251 head = find(head, classname, "player");
253 RegenFlag (other.flagcarried);
254 other.flagcarried = world;
255 other.next_take_time = time + 1;
257 if (self.cnt == FLAG_BASE)
258 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
259 if (other.team != self.team)
260 if (!other.flagcarried)
262 if (other.next_take_time > time)
265 other.flagpickuptime = time; // used for timing runs
266 self.solid = SOLID_NOT;
267 setorigin(self, self.origin); // relink
269 other.flagcarried = self;
270 self.cnt = FLAG_CARRY;
271 if (other.flagcarried.team == 5)
272 bprint(other.netname, "^7 got the RED flag\n");
274 bprint(other.netname, "^7 got the BLUE flag\n");
275 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
276 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
278 player = find(world, classname, "player");
280 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
281 player = find(player, classname, "player");
287 if (self.cnt == FLAG_DROPPED)
289 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
290 if (other.team == self.team || (other.team != 5 && other.team != 14))
294 bprint(other.netname, "^7 returned the RED flag\n");
296 bprint(other.netname, "^7 returned the BLUE flag\n");
297 if (other.team == 5 || other.team == 14)
298 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
300 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
301 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
304 else if (!other.flagcarried)
307 other.flagpickuptime = time; // used for timing runs
308 self.solid = SOLID_NOT;
309 setorigin(self, self.origin); // relink
311 other.flagcarried = self;
312 self.cnt = FLAG_CARRY;
314 bprint(other.netname, "^7 picked up the RED flag\n");
316 bprint(other.netname, "^7 picked up the BLUE flag\n");
317 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
318 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
320 player = find(world, classname, "player");
322 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
323 player = find(player, classname, "player");
329 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
330 CTF Starting point for a player
335 viewing angle when spawning
337 void() info_player_team1 =
340 self.classname = "info_player_deathmatch";
342 //self.team = 4;self.classname = "info_player_start";info_player_start();};
344 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
345 CTF Starting point for a player in
350 viewing angle when spawning
352 void() info_player_team2 =
355 self.classname = "info_player_deathmatch";
357 //self.team = 13;self.classname = "info_player_start";info_player_start();};
359 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
360 CTF Starting point for a player in
365 viewing angle when spawning
367 void() info_player_team3 =
370 self.classname = "info_player_deathmatch";
374 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
375 CTF Starting point for a player in
380 viewing angle when spawning
382 void() info_player_team4 =
385 self.classname = "info_player_deathmatch";
391 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
392 CTF flag for team one (Red).
393 Multiple are allowed.
397 Angle the flag will point
400 model to use, note this needs red and blue as skins 0 and 1
401 (default models/ctf/flag.md3)
403 sound played when flag is picked up
404 (default ctf/take.wav)
406 sound played when flag is returned by a teammate
407 (default ctf/return.wav)
409 sound played when flag is captured
410 (default ctf/capture.wav)
412 sound played when flag is lost in the field and respawns itself
413 (default ctf/respawn.wav)
416 void() item_flag_team1 =
420 //if(!cvar("teamplay"))
421 // cvar_set("teamplay", "3");
423 self.team = 5; // color 4 team (red)
424 self.items = IT_KEY2; // gold key (redish enough)
427 self.model = "models/ctf/flag_red.md3";
429 self.noise = "ctf/take.wav";
431 self.noise1 = "ctf/return.wav";
433 self.noise2 = "ctf/capture.wav";
435 self.noise3 = "ctf/respawn.wav";
436 precache_model (self.model);
437 setmodel (self, self.model);
438 precache_sound (self.noise);
439 precache_sound (self.noise1);
440 precache_sound (self.noise2);
441 precache_sound (self.noise3);
442 setsize(self, '-16 -16 -37', '16 16 37');
443 setorigin(self, self.origin + '0 0 37');
444 self.nextthink = time + 0.2; // start after doors etc
445 self.think = place_flag;
449 //if(!self.glow_size)
450 // self.glow_size = 50;
452 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
455 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
456 CTF flag for team two (Blue).
457 Multiple are allowed.
461 Angle the flag will point
466 void() item_flag_team2 =
470 //if(!cvar("teamplay"))
471 // cvar_set("teamplay", "3");
473 self.team = 14; // color 13 team (blue)
474 self.items = IT_KEY1; // silver key (bluish enough)
477 self.model = "models/ctf/flag_blue.md3";
479 self.noise = "ctf/take.wav";
481 self.noise1 = "ctf/return.wav";
483 self.noise2 = "ctf/capture.wav";
485 self.noise3 = "ctf/respawn.wav";
486 precache_model (self.model);
487 setmodel (self, self.model);
488 precache_sound (self.noise);
489 precache_sound (self.noise1);
490 precache_sound (self.noise2);
491 precache_sound (self.noise3);
492 setsize(self, '-16 -16 -37', '16 16 37');
493 setorigin(self, self.origin + '0 0 37');
494 self.nextthink = time + 0.2; // start after doors etc
495 self.think = place_flag;
499 //if(!self.glow_size)
500 // self.glow_size = 50;
502 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
506 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
507 Team declaration for CTF gameplay, this allows you to decide what team
508 names and control point models are used in your map.
510 Note: If you use ctf_team entities you must define at least 2! However, unlike
511 domination, you don't need to make a blank one too.
515 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
517 Scoreboard color of the team (for example 4 is red and 13 is blue)
523 self.classname = "ctf_team";
524 self.team = self.cnt + 1;
527 // code from here on is just to support maps that don't have control point and team entities
528 void ctf_spawnteam (string teamname, float teamcolor)
530 local entity oldself;
533 self.classname = "ctf_team";
534 self.netname = teamname;
535 self.cnt = teamcolor;
542 // spawn some default teams if the map is not set up for ctf
543 void() ctf_spawnteams =
547 numteams = 2;//cvar("g_ctf_default_teams");
549 ctf_spawnteam("Red", 4);
550 ctf_spawnteam("Blue", 13);
553 void() ctf_delayedinit =
555 self.think = SUB_Remove;
556 self.nextthink = time;
557 // if no teams are found, spawn defaults
558 if (find(world, classname, "ctf_team") == world)
566 e.think = ctf_delayedinit;
567 e.nextthink = time + 0.1;