4 //float FLAGSCORE_PICKUP = 1;
5 //float FLAGSCORE_RETURN = 5; // returned by owner team
6 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
7 //float FLAGSCORE_CAPTURE = 5;
8 //float FLAGSCORE_CAPTURE_TEAM = 20;
12 float FLAG_DROPPED = 3;
20 self.t_width = 0.1; // frame animation rate
22 self.t_length = 119; // maximum frame
24 self.mdl = self.model;
26 self.solid = SOLID_TRIGGER;
27 self.movetype = MOVETYPE_TOSS;
28 self.velocity = '0 0 0';
29 self.origin_z = self.origin_z + 6;
30 self.think = FlagThink;
31 self.touch = FlagTouch;
32 self.nextthink = time + 0.1;
34 self.mangle = self.angles;
35 //self.effects = self.effects | EF_DIMLIGHT;
36 if (!droptofloor(0, 0))
38 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
42 self.oldorigin = self.origin;
45 void(entity e) RegenFlag =
47 e.movetype = MOVETYPE_TOSS;
48 e.solid = SOLID_TRIGGER;
49 // TODO: play a sound here
50 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
51 setorigin(e, e.oldorigin);
55 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
58 void(entity e) ReturnFlag =
61 if (e.owner.flagcarried == e)
62 e.owner.flagcarried = world;
67 void(entity e) DropFlag =
73 dprint("FLAG: drop - no owner?!?!\n");
77 if (p.flagcarried != e)
79 dprint("FLAG: drop - owner is not carrying this flag??\n");
84 bprint("^7 lost the RED flag\n");
86 bprint("^7 lost the BLUE flag\n");
87 if (p.flagcarried == e)
88 p.flagcarried = world;
91 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
92 e.solid = SOLID_TRIGGER;
93 e.movetype = MOVETYPE_TOSS;
94 // setsize(e, '-16 -16 0', '16 16 74');
95 setorigin(e, p.origin - '0 0 24');
97 e.velocity = '0 0 300';
98 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
103 if(self.delay > time)
105 self.delay = time + self.t_width;
106 if(self.nextthink > self.delay)
107 self.nextthink = self.delay;
109 self.frame = self.frame + 1;
110 if(self.frame > self.t_length)
120 self.nextthink = time + 0.1;
124 if (self.cnt == FLAG_BASE)
127 if (self.cnt == FLAG_DROPPED)
129 if (time > self.pain_finished)
132 bprint("The RED flag has returned to base\n");
134 bprint("The BLUE flag has returned to base\n");
141 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
147 // borrowed from threewave CTF, because it would be way too much work
149 makevectors (e.angles);
151 v_z = 0 - v_z; // reverse z
155 if (e.frame >= 29 && e.frame <= 40)
157 if (e.frame >= 29 && e.frame <= 34)
160 if (e.frame == 29) f = f + 2;
161 else if (e.frame == 30) f = f + 8;
162 else if (e.frame == 31) f = f + 12;
163 else if (e.frame == 32) f = f + 11;
164 else if (e.frame == 33) f = f + 10;
165 else if (e.frame == 34) f = f + 4;
167 else if (e.frame >= 35 && e.frame <= 40)
170 if (e.frame == 35) f = f + 2;
171 else if (e.frame == 36) f = f + 10;
172 else if (e.frame == 37) f = f + 10;
173 else if (e.frame == 38) f = f + 8;
174 else if (e.frame == 39) f = f + 4;
175 else if (e.frame == 40) f = f + 2;
178 else if (e.frame >= 103 && e.frame <= 118)
180 if (e.frame >= 103 && e.frame <= 104) f = f + 6; //nailattack
181 else if (e.frame >= 105 && e.frame <= 106) f = f + 6; //light
182 else if (e.frame >= 107 && e.frame <= 112) f = f + 7; //rocketattack
183 else if (e.frame >= 112 && e.frame <= 118) f = f + 7; //shotattack
186 self.angles = e.angles + '0 0 -45';
187 setorigin (self, e.origin + '0 0 0' - f*v + v_right * 22);
188 self.nextthink = time + 0.01;
191 float flagcaptimerecord;
192 .float flagpickuptime;
199 if (other.classname != "player")
201 if (other.health < 1) // ignore dead players
204 if (self.cnt == FLAG_CARRY)
207 if (self.cnt == FLAG_BASE)
208 if (other.team == self.team)
209 if (other.flagcarried) // he's got a flag
210 if (other.flagcarried.team != self.team) // capture
212 t = time - other.flagpickuptime;
213 if (flagcaptimerecord == 0)
215 if (other.flagcarried.team == 5)
216 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), " seconds\n");
218 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), " seconds\n");
219 flagcaptimerecord = t;
221 else if (t < flagcaptimerecord)
223 if (other.flagcarried.team == 5)
224 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", breaking the previous record of", ftos(flagcaptimerecord), " seconds\n");
226 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", breaking the previous record of", ftos(flagcaptimerecord), " seconds\n");
227 flagcaptimerecord = t;
231 if (other.flagcarried.team == 5)
232 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", failing to break the previous record of", ftos(flagcaptimerecord), " seconds\n");
234 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", failing to break the previous record of", ftos(flagcaptimerecord), " seconds\n");
236 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
237 head = find(head, classname, "player");
240 if (head.team == self.team)
241 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
242 head = find(head, classname, "player");
244 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
245 ReturnFlag(other.flagcarried);
247 if (self.cnt == FLAG_BASE)
248 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
249 if (other.team != self.team)
250 if (!other.flagcarried)
253 other.flagpickuptime = time; // used for timing runs
254 self.solid = SOLID_NOT;
255 setorigin(self, self.origin); // relink
257 other.flagcarried = self;
258 self.cnt = FLAG_CARRY;
259 if (other.flagcarried.team == 5)
260 bprint(other.netname, "^7 got the RED flag\n");
262 bprint(other.netname, "^7 got the BLUE flag\n");
263 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
264 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
266 player = find(world, classname, "player");
268 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
269 player = find(player, classname, "player");
275 if (self.cnt == FLAG_DROPPED)
277 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
278 if (other.team == self.team || (other.team != 5 && other.team != 14))
282 bprint(other.netname, "^7 returned the RED flag\n");
284 bprint(other.netname, "^7 returned the BLUE flag\n");
285 if (other.team == 5 || other.team == 14)
286 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
288 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
289 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
292 else if (!other.flagcarried)
295 other.flagpickuptime = time; // used for timing runs
296 self.solid = SOLID_NOT;
297 setorigin(self, self.origin); // relink
299 other.flagcarried = self;
300 self.cnt = FLAG_CARRY;
302 bprint(other.netname, "^7 picked up the RED flag\n");
304 bprint(other.netname, "^7 picked up the BLUE flag\n");
305 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
306 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
308 player = find(world, classname, "player");
310 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
311 player = find(player, classname, "player");
317 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
318 CTF Starting point for a player
323 viewing angle when spawning
325 void() info_player_team1 =
328 self.classname = "info_player_deathmatch";
330 //self.team = 4;self.classname = "info_player_start";info_player_start();};
332 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
333 CTF Starting point for a player in
338 viewing angle when spawning
340 void() info_player_team2 =
343 self.classname = "info_player_deathmatch";
345 //self.team = 13;self.classname = "info_player_start";info_player_start();};
347 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
348 CTF Starting point for a player in
353 viewing angle when spawning
355 void() info_player_team3 =
358 self.classname = "info_player_deathmatch";
362 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
363 CTF Starting point for a player in
368 viewing angle when spawning
370 void() info_player_team4 =
373 self.classname = "info_player_deathmatch";
379 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
380 CTF flag for team one (Red).
381 Multiple are allowed.
385 Angle the flag will point
388 model to use, note this needs red and blue as skins 0 and 1
389 (default models/ctf/flag.md3)
391 sound played when flag is picked up
392 (default ctf/take.wav)
394 sound played when flag is returned by a teammate
395 (default ctf/return.wav)
397 sound played when flag is captured
398 (default ctf/capture.wav)
400 sound played when flag is lost in the field and respawns itself
401 (default ctf/respawn.wav)
404 void() item_flag_team1 =
408 //if(!cvar("teamplay"))
409 // cvar_set("teamplay", "3");
411 self.team = 5; // color 4 team (red)
412 self.items = IT_KEY2; // gold key (redish enough)
415 self.model = "models/ctf/flag_red.md3";
417 self.noise = "ctf/take.wav";
419 self.noise1 = "ctf/return.wav";
421 self.noise2 = "ctf/capture.wav";
423 self.noise3 = "ctf/respawn.wav";
424 precache_model (self.model);
425 setmodel (self, self.model);
426 precache_sound (self.noise);
427 precache_sound (self.noise1);
428 precache_sound (self.noise2);
429 precache_sound (self.noise3);
430 setsize(self, '-16 -16 -37', '16 16 37');
431 setorigin(self, self.origin + '0 0 37');
432 self.nextthink = time + 0.2; // start after doors etc
433 self.think = place_flag;
437 //if(!self.glow_size)
438 // self.glow_size = 50;
440 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
443 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
444 CTF flag for team two (Blue).
445 Multiple are allowed.
449 Angle the flag will point
454 void() item_flag_team2 =
458 //if(!cvar("teamplay"))
459 // cvar_set("teamplay", "3");
461 self.team = 14; // color 13 team (blue)
462 self.items = IT_KEY1; // silver key (bluish enough)
465 self.model = "models/ctf/flag_blue.md3";
467 self.noise = "ctf/take.wav";
469 self.noise1 = "ctf/return.wav";
471 self.noise2 = "ctf/capture.wav";
473 self.noise3 = "ctf/respawn.wav";
474 precache_model (self.model);
475 setmodel (self, self.model);
476 precache_sound (self.noise);
477 precache_sound (self.noise1);
478 precache_sound (self.noise2);
479 precache_sound (self.noise3);
480 setsize(self, '-16 -16 -37', '16 16 37');
481 setorigin(self, self.origin + '0 0 37');
482 self.nextthink = time + 0.2; // start after doors etc
483 self.think = place_flag;
487 //if(!self.glow_size)
488 // self.glow_size = 50;
490 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
494 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
495 Team declaration for CTF gameplay, this allows you to decide what team
496 names and control point models are used in your map.
498 Note: If you use ctf_team entities you must define at least 2! However, unlike
499 domination, you don't need to make a blank one too.
503 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
505 Scoreboard color of the team (for example 4 is red and 13 is blue)
511 self.classname = "ctf_team";
512 self.team = self.cnt + 1;
515 // code from here on is just to support maps that don't have control point and team entities
516 void ctf_spawnteam (string teamname, float teamcolor)
518 local entity oldself;
521 self.classname = "ctf_team";
522 self.netname = teamname;
523 self.cnt = teamcolor;
530 // spawn some default teams if the map is not set up for ctf
531 void() ctf_spawnteams =
535 numteams = 2;//cvar("g_ctf_default_teams");
537 ctf_spawnteam("Red", 4);
538 ctf_spawnteam("Blue", 13);
541 void() ctf_delayedinit =
543 self.think = SUB_Remove;
544 self.nextthink = time;
545 // if no teams are found, spawn defaults
546 if (find(world, classname, "ctf_team") == world)
554 e.think = ctf_delayedinit;
555 e.nextthink = time + 0.1;