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
62 void(entity e) ReturnFlag =
65 if (e.owner.flagcarried == e)
66 e.owner.flagcarried = world;
71 void(entity e) DropFlag =
77 dprint("FLAG: drop - no owner?!?!\n");
81 if (p.flagcarried != e)
83 dprint("FLAG: drop - owner is not carrying this flag??\n");
88 bprint("^7 lost the RED flag\n");
90 bprint("^7 lost the BLUE flag\n");
91 if (p.flagcarried == e)
92 p.flagcarried = world;
95 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
96 e.solid = SOLID_TRIGGER;
97 e.movetype = MOVETYPE_TOSS;
98 // setsize(e, '-16 -16 0', '16 16 74');
99 setorigin(e, p.origin - '0 0 24');
100 e.cnt = FLAG_DROPPED;
101 e.velocity = '0 0 300';
102 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
107 if(self.delay > time)
109 self.delay = time + self.t_width;
110 if(self.nextthink > self.delay)
111 self.nextthink = self.delay;
113 self.frame = self.frame + 1;
114 if(self.frame > self.t_length)
124 self.nextthink = time + 0.1;
128 if (self.cnt == FLAG_BASE)
131 if (self.cnt == FLAG_DROPPED || !self.health)
133 if (time > self.pain_finished || !self.health)
136 bprint("The RED flag has returned to base\n");
138 bprint("The BLUE flag has returned to base\n");
145 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
151 // borrowed from threewave CTF, because it would be way too much work
153 makevectors (e.angles);
155 v_z = 0 - v_z; // reverse z
159 if (e.frame >= 29 && e.frame <= 40)
161 if (e.frame >= 29 && e.frame <= 34)
164 if (e.frame == 29) f = f + 2;
165 else if (e.frame == 30) f = f + 8;
166 else if (e.frame == 31) f = f + 12;
167 else if (e.frame == 32) f = f + 11;
168 else if (e.frame == 33) f = f + 10;
169 else if (e.frame == 34) f = f + 4;
171 else if (e.frame >= 35 && e.frame <= 40)
174 if (e.frame == 35) f = f + 2;
175 else if (e.frame == 36) f = f + 10;
176 else if (e.frame == 37) f = f + 10;
177 else if (e.frame == 38) f = f + 8;
178 else if (e.frame == 39) f = f + 4;
179 else if (e.frame == 40) f = f + 2;
182 else if (e.frame >= 103 && e.frame <= 118)
184 if (e.frame >= 103 && e.frame <= 104) f = f + 6; //nailattack
185 else if (e.frame >= 105 && e.frame <= 106) f = f + 6; //light
186 else if (e.frame >= 107 && e.frame <= 112) f = f + 7; //rocketattack
187 else if (e.frame >= 112 && e.frame <= 118) f = f + 7; //shotattack
190 self.angles = e.angles + '0 0 -45';
191 setorigin (self, e.origin + '0 0 0' - f*v + v_right * 22);
192 self.nextthink = time + 0.01;
195 float flagcaptimerecord;
196 .float flagpickuptime;
205 if (other.classname != "player")
207 if (other.health < 1) // ignore dead players
210 if (self.cnt == FLAG_CARRY)
213 if (self.cnt == FLAG_BASE)
214 if (other.team == self.team)
215 if (other.flagcarried) // he's got a flag
216 if (other.flagcarried.team != self.team) // capture
218 if (other.flagcarried == world)
222 t = time - other.flagpickuptime;
223 if (flagcaptimerecord == 0)
225 if (other.flagcarried.team == 5)
226 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), " seconds\n");
228 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), " seconds\n");
229 flagcaptimerecord = t;
231 else if (t < flagcaptimerecord)
233 if (other.flagcarried.team == 5)
234 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
236 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
237 flagcaptimerecord = t;
241 if (other.flagcarried.team == 5)
242 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
244 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
247 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
248 head = find(head, classname, "player");
251 if (head.team == self.team)
252 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
253 head = find(head, classname, "player");
255 RegenFlag (other.flagcarried);
256 other.flagcarried = world;
257 other.next_take_time = time + 1;
259 if (self.cnt == FLAG_BASE)
260 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
261 if (other.team != self.team)
262 if (!other.flagcarried)
264 if (other.next_take_time > time)
267 other.flagpickuptime = time; // used for timing runs
268 self.solid = SOLID_NOT;
269 setorigin(self, self.origin); // relink
271 other.flagcarried = self;
272 self.cnt = FLAG_CARRY;
273 if (other.flagcarried.team == 5)
274 bprint(other.netname, "^7 got the RED flag\n");
276 bprint(other.netname, "^7 got the BLUE flag\n");
277 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
278 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
280 player = find(world, classname, "player");
282 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
283 player = find(player, classname, "player");
289 if (self.cnt == FLAG_DROPPED)
291 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
292 if (other.team == self.team || (other.team != 5 && other.team != 14))
296 bprint(other.netname, "^7 returned the RED flag\n");
298 bprint(other.netname, "^7 returned the BLUE flag\n");
299 if (other.team == 5 || other.team == 14)
300 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
302 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
303 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
306 else if (!other.flagcarried)
309 other.flagpickuptime = time; // used for timing runs
310 self.solid = SOLID_NOT;
311 setorigin(self, self.origin); // relink
313 other.flagcarried = self;
314 self.cnt = FLAG_CARRY;
316 bprint(other.netname, "^7 picked up the RED flag\n");
318 bprint(other.netname, "^7 picked up the BLUE flag\n");
319 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
320 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
322 player = find(world, classname, "player");
324 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
325 player = find(player, classname, "player");
331 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
332 CTF Starting point for a player
337 viewing angle when spawning
339 void() info_player_team1 =
342 self.classname = "info_player_deathmatch";
344 //self.team = 4;self.classname = "info_player_start";info_player_start();};
346 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
347 CTF Starting point for a player in
352 viewing angle when spawning
354 void() info_player_team2 =
357 self.classname = "info_player_deathmatch";
359 //self.team = 13;self.classname = "info_player_start";info_player_start();};
361 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
362 CTF Starting point for a player in
367 viewing angle when spawning
369 void() info_player_team3 =
372 self.classname = "info_player_deathmatch";
376 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
377 CTF Starting point for a player in
382 viewing angle when spawning
384 void() info_player_team4 =
387 self.classname = "info_player_deathmatch";
393 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
394 CTF flag for team one (Red).
395 Multiple are allowed.
399 Angle the flag will point
402 model to use, note this needs red and blue as skins 0 and 1
403 (default models/ctf/flag.md3)
405 sound played when flag is picked up
406 (default ctf/take.wav)
408 sound played when flag is returned by a teammate
409 (default ctf/return.wav)
411 sound played when flag is captured
412 (default ctf/capture.wav)
414 sound played when flag is lost in the field and respawns itself
415 (default ctf/respawn.wav)
418 void() item_flag_team1 =
422 //if(!cvar("teamplay"))
423 // cvar_set("teamplay", "3");
425 self.team = 5; // color 4 team (red)
426 self.items = IT_KEY2; // gold key (redish enough)
429 self.model = "models/ctf/flag_red.md3";
431 self.noise = "ctf/take.wav";
433 self.noise1 = "ctf/return.wav";
435 self.noise2 = "ctf/capture.wav";
437 self.noise3 = "ctf/respawn.wav";
438 precache_model (self.model);
439 setmodel (self, self.model);
440 precache_sound (self.noise);
441 precache_sound (self.noise1);
442 precache_sound (self.noise2);
443 precache_sound (self.noise3);
444 setsize(self, '-16 -16 -37', '16 16 37');
445 setorigin(self, self.origin + '0 0 37');
446 self.nextthink = time + 0.2; // start after doors etc
447 self.think = place_flag;
451 //if(!self.glow_size)
452 // self.glow_size = 50;
454 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
458 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
459 CTF flag for team two (Blue).
460 Multiple are allowed.
464 Angle the flag will point
469 void() item_flag_team2 =
473 //if(!cvar("teamplay"))
474 // cvar_set("teamplay", "3");
476 self.team = 14; // color 13 team (blue)
477 self.items = IT_KEY1; // silver key (bluish enough)
480 self.model = "models/ctf/flag_blue.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);
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;
510 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
511 Team declaration for CTF gameplay, this allows you to decide what team
512 names and control point models are used in your map.
514 Note: If you use ctf_team entities you must define at least 2! However, unlike
515 domination, you don't need to make a blank one too.
519 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
521 Scoreboard color of the team (for example 4 is red and 13 is blue)
527 self.classname = "ctf_team";
528 self.team = self.cnt + 1;
531 // code from here on is just to support maps that don't have control point and team entities
532 void ctf_spawnteam (string teamname, float teamcolor)
534 local entity oldself;
537 self.classname = "ctf_team";
538 self.netname = teamname;
539 self.cnt = teamcolor;
546 // spawn some default teams if the map is not set up for ctf
547 void() ctf_spawnteams =
551 numteams = 2;//cvar("g_ctf_default_teams");
553 ctf_spawnteam("Red", 4);
554 ctf_spawnteam("Blue", 13);
557 void() ctf_delayedinit =
559 self.think = SUB_Remove;
560 self.nextthink = time;
561 // if no teams are found, spawn defaults
562 if (find(world, classname, "ctf_team") == world)
570 e.think = ctf_delayedinit;
571 e.nextthink = time + 0.1;