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;
17 self.t_width = 0.1; // frame animation rate
19 self.t_length = 119; // maximum frame
21 self.mdl = self.model;
23 self.solid = SOLID_TRIGGER;
24 self.movetype = MOVETYPE_TOSS;
25 self.velocity = '0 0 0';
26 self.origin_z = self.origin_z + 6;
27 self.think = FlagThink;
28 self.touch = FlagTouch;
29 self.nextthink = time + 0.1;
31 self.mangle = self.angles;
32 //self.effects = self.effects | EF_DIMLIGHT;
33 if (!droptofloor(0, 0))
35 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
39 self.oldorigin = self.origin;
42 void LogCTF(string mode, float flagteam, entity actor)
45 if(!cvar("sv_eventlog"))
47 s = strcat(":ctf:", mode);
48 s = strcat(s, ":", ftos(flagteam));
50 s = strcat(s, ":", ftos(actor.playerid));
51 GameLogEcho(s, FALSE);
54 void(entity e) RegenFlag =
56 e.movetype = MOVETYPE_TOSS;
57 e.solid = SOLID_TRIGGER;
58 // TODO: play a sound here
59 setorigin(e, e.oldorigin);
63 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
66 void(entity e) ReturnFlag =
69 if (e.owner.flagcarried == e)
70 e.owner.flagcarried = world;
75 void(entity e) DropFlag =
81 dprint("FLAG: drop - no owner?!?!\n");
85 if (p.flagcarried != e)
87 dprint("FLAG: drop - owner is not carrying this flag??\n");
90 bprint(strcat(p.netname, "^7 lost the ", e.netname, "\n"));
92 if (p.flagcarried == e)
93 p.flagcarried = world;
96 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
97 e.solid = SOLID_TRIGGER;
98 e.movetype = MOVETYPE_TOSS;
99 // setsize(e, '-16 -16 0', '16 16 74');
100 setorigin(e, p.origin - '0 0 24');
101 e.cnt = FLAG_DROPPED;
102 e.velocity = '0 0 300';
103 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
108 if(self.delay > time)
110 self.delay = time + self.t_width;
111 if(self.nextthink > self.delay)
112 self.nextthink = self.delay;
114 self.frame = self.frame + 1;
115 if(self.frame > self.t_length)
125 self.nextthink = time + 0.1;
129 if (self.cnt == FLAG_BASE)
132 if (self.cnt == FLAG_DROPPED)
134 if (time > self.pain_finished)
136 bprint(strcat("The ", self.netname, " has returned to base\n"));
137 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
138 LogCTF("returned", self.team, world);
145 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
148 LogCTF("dropped", self.team, e);
152 // borrowed from threewave CTF, because it would be way too much work
154 makevectors (e.angles);
156 v_z = 0 - v_z; // reverse z
160 if (e.frame >= 29 && e.frame <= 40)
162 if (e.frame >= 29 && e.frame <= 34)
165 if (e.frame == 29) f = f + 2;
166 else if (e.frame == 30) f = f + 8;
167 else if (e.frame == 31) f = f + 12;
168 else if (e.frame == 32) f = f + 11;
169 else if (e.frame == 33) f = f + 10;
170 else if (e.frame == 34) f = f + 4;
172 else if (e.frame >= 35 && e.frame <= 40)
175 if (e.frame == 35) f = f + 2;
176 else if (e.frame == 36) f = f + 10;
177 else if (e.frame == 37) f = f + 10;
178 else if (e.frame == 38) f = f + 8;
179 else if (e.frame == 39) f = f + 4;
180 else if (e.frame == 40) f = f + 2;
183 else if (e.frame >= 103 && e.frame <= 118)
185 if (e.frame >= 103 && e.frame <= 104) f = f + 6; //nailattack
186 else if (e.frame >= 105 && e.frame <= 106) f = f + 6; //light
187 else if (e.frame >= 107 && e.frame <= 112) f = f + 7; //rocketattack
188 else if (e.frame >= 112 && e.frame <= 118) f = f + 7; //shotattack
191 self.angles = e.angles + '0 0 -45';
192 setorigin (self, e.origin + '0 0 0' - f*v + v_right * 22);
193 self.nextthink = time + 0.01;
196 float flagcaptimerecord;
197 .float flagpickuptime;
206 if (other.classname != "player")
208 if (other.health < 1) // ignore dead players
211 if (self.cnt == FLAG_CARRY)
214 if (self.cnt == FLAG_BASE)
215 if (other.team == self.team)
216 if (other.flagcarried) // he's got a flag
217 if (other.flagcarried.team != self.team) // capture
219 if (other.flagcarried == world)
223 t = time - other.flagcarried.flagpickuptime;
224 if (flagcaptimerecord == 0)
226 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), " seconds\n");
227 flagcaptimerecord = t;
229 else if (t < flagcaptimerecord)
231 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
232 flagcaptimerecord = t;
236 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
239 LogCTF("capture", other.flagcarried.team, other);
240 // give credit to the individual player
241 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
242 // give credit to all players of the team (rewards large teams)
243 // NOTE: this defaults to 0
244 head = find(head, classname, "player");
247 if (head.team == self.team)
248 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
249 head = find(head, classname, "player");
251 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
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 self.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 bprint(other.netname, "^7 got the ", self.netname, "\n");
271 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
272 LogCTF("steal", self.team, other);
273 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
275 player = find(world, classname, "player");
277 if(player.team == self.team) centermsg_setfor(player, CENTERMSG_CTF, "The enemy got your flag! Retrieve it!");
278 player = find(player, classname, "player");
284 if (self.cnt == FLAG_DROPPED)
286 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
287 if (other.team == self.team || (other.team != 5 && other.team != 14))
290 bprint(other.netname, "^7 returned the ", self.netname, "\n");
291 if (other.team == 5 || other.team == 14)
292 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
294 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
295 LogCTF("return", self.team, other);
296 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
299 else if (!other.flagcarried)
302 self.solid = SOLID_NOT;
303 setorigin(self, self.origin); // relink
305 other.flagcarried = self;
306 self.cnt = FLAG_CARRY;
307 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
308 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
309 LogCTF("pickup", self.team, other);
310 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
312 player = find(world, classname, "player");
314 if(player.team == self.team) centermsg_setfor(player, CENTERMSG_CTF, "The enemy got your flag! Retrieve it!");
315 player = find(player, classname, "player");
321 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
322 CTF Starting point for a player
327 viewing angle when spawning
329 void() info_player_team1 =
331 self.classname = "info_player_deathmatch";
332 self.team = 5; // red
333 relocate_spawnpoint();
335 //self.team = 4;self.classname = "info_player_start";info_player_start();};
337 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
338 CTF Starting point for a player in
343 viewing angle when spawning
345 void() info_player_team2 =
347 self.classname = "info_player_deathmatch";
348 self.team = 14; // blue
349 relocate_spawnpoint();
351 //self.team = 13;self.classname = "info_player_start";info_player_start();};
353 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
354 CTF Starting point for a player in
355 team three (Magenta).
359 viewing angle when spawning
361 void() info_player_team3 =
363 self.classname = "info_player_deathmatch";
364 self.team = 10; // purple
365 relocate_spawnpoint();
369 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
370 CTF Starting point for a player in
375 viewing angle when spawning
377 void() info_player_team4 =
379 self.classname = "info_player_deathmatch";
380 self.team = 13; // yellow
381 relocate_spawnpoint();
387 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
388 CTF flag for team one (Red).
389 Multiple are allowed.
393 Angle the flag will point
396 model to use, note this needs red and blue as skins 0 and 1
397 (default models/ctf/flag.md3)
399 sound played when flag is picked up
400 (default ctf/take.wav)
402 sound played when flag is returned by a teammate
403 (default ctf/return.wav)
405 sound played when flag is captured
406 (default ctf/capture.wav)
408 sound played when flag is lost in the field and respawns itself
409 (default ctf/respawn.wav)
412 void() item_flag_team1 =
416 //if(!cvar("teamplay"))
417 // cvar_set("teamplay", "3");
419 self.team = 5; // color 4 team (red)
420 self.items = IT_KEY2; // gold key (redish enough)
421 self.netname = "^1RED^7 flag";
422 self.target = "###item###";
425 self.model = "models/ctf/flag_red.md3";
427 self.noise = "ctf/take.wav";
429 self.noise1 = "ctf/return.wav";
431 self.noise2 = "ctf/capture.wav";
433 self.noise3 = "ctf/respawn.wav";
434 precache_model (self.model);
435 setmodel (self, self.model);
436 precache_sound (self.noise);
437 precache_sound (self.noise1);
438 precache_sound (self.noise2);
439 precache_sound (self.noise3);
440 setsize(self, '-16 -16 -37', '16 16 37');
441 setorigin(self, self.origin + '0 0 37');
442 self.nextthink = time + 0.2; // start after doors etc
443 self.think = place_flag;
447 //if(!self.glow_size)
448 // self.glow_size = 50;
450 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
453 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
454 CTF flag for team two (Blue).
455 Multiple are allowed.
459 Angle the flag will point
464 void() item_flag_team2 =
468 //if(!cvar("teamplay"))
469 // cvar_set("teamplay", "3");
471 self.team = 14; // color 13 team (blue)
472 self.items = IT_KEY1; // silver key (bluish enough)
473 self.netname = "^4BLUE^7 flag";
474 self.target = "###item###";
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;