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");
94 bprint(strcat(p.netname, "^7 lost the ", e.netname, "\n"));
96 if (p.flagcarried == e)
97 p.flagcarried = world;
100 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
101 e.solid = SOLID_TRIGGER;
102 e.movetype = MOVETYPE_TOSS;
103 // setsize(e, '-16 -16 0', '16 16 74');
104 setorigin(e, p.origin - '0 0 24');
105 e.cnt = FLAG_DROPPED;
106 e.velocity = '0 0 300';
107 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
112 if(self.delay > time)
114 self.delay = time + self.t_width;
115 if(self.nextthink > self.delay)
116 self.nextthink = self.delay;
118 self.frame = self.frame + 1;
119 if(self.frame > self.t_length)
129 self.nextthink = time + 0.1;
133 if (self.cnt == FLAG_BASE)
136 if (self.cnt == FLAG_DROPPED)
138 if (time > self.pain_finished)
140 bprint(strcat("The ", self.netname, " has returned to base\n"));
141 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
142 LogCTF("returned", self.team, world);
149 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
152 LogCTF("dropped", self.team, e);
156 // borrowed from threewave CTF, because it would be way too much work
158 makevectors (e.angles);
160 v_z = 0 - v_z; // reverse z
164 if (e.frame >= 29 && e.frame <= 40)
166 if (e.frame >= 29 && e.frame <= 34)
169 if (e.frame == 29) f = f + 2;
170 else if (e.frame == 30) f = f + 8;
171 else if (e.frame == 31) f = f + 12;
172 else if (e.frame == 32) f = f + 11;
173 else if (e.frame == 33) f = f + 10;
174 else if (e.frame == 34) f = f + 4;
176 else if (e.frame >= 35 && e.frame <= 40)
179 if (e.frame == 35) f = f + 2;
180 else if (e.frame == 36) f = f + 10;
181 else if (e.frame == 37) f = f + 10;
182 else if (e.frame == 38) f = f + 8;
183 else if (e.frame == 39) f = f + 4;
184 else if (e.frame == 40) f = f + 2;
187 else if (e.frame >= 103 && e.frame <= 118)
189 if (e.frame >= 103 && e.frame <= 104) f = f + 6; //nailattack
190 else if (e.frame >= 105 && e.frame <= 106) f = f + 6; //light
191 else if (e.frame >= 107 && e.frame <= 112) f = f + 7; //rocketattack
192 else if (e.frame >= 112 && e.frame <= 118) f = f + 7; //shotattack
195 self.angles = e.angles + '0 0 -45';
196 setorigin (self, e.origin + '0 0 0' - f*v + v_right * 22);
197 self.nextthink = time + 0.01;
200 float flagcaptimerecord;
201 .float flagpickuptime;
210 if (other.classname != "player")
212 if (other.health < 1) // ignore dead players
215 if (self.cnt == FLAG_CARRY)
218 if (self.cnt == FLAG_BASE)
219 if (other.team == self.team)
220 if (other.flagcarried) // he's got a flag
221 if (other.flagcarried.team != self.team) // capture
223 if (other.flagcarried == world)
227 t = time - other.flagpickuptime;
228 if (flagcaptimerecord == 0)
230 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), " seconds\n");
231 flagcaptimerecord = t;
233 else if (t < flagcaptimerecord)
235 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
236 flagcaptimerecord = t;
240 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
243 LogCTF("capture", other.flagcarried.team, other);
244 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
245 head = find(head, classname, "player");
248 if (head.team == self.team)
249 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
250 head = find(head, classname, "player");
252 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
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 bprint(other.netname, "^7 got the ", self.netname, "\n");
272 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
273 LogCTF("steal", self.team, other);
274 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
276 player = find(world, classname, "player");
278 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
279 player = find(player, classname, "player");
285 if (self.cnt == FLAG_DROPPED)
287 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
288 if (other.team == self.team || (other.team != 5 && other.team != 14))
291 bprint(other.netname, "^7 returned the ", self.netname, "\n");
292 if (other.team == 5 || other.team == 14)
293 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
295 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
296 LogCTF("return", self.team, other);
297 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
300 else if (!other.flagcarried)
303 other.flagpickuptime = time; // used for timing runs
304 self.solid = SOLID_NOT;
305 setorigin(self, self.origin); // relink
307 other.flagcarried = self;
308 self.cnt = FLAG_CARRY;
309 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
310 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
311 LogCTF("pickup", self.team, other);
312 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
314 player = find(world, classname, "player");
316 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
317 player = find(player, classname, "player");
323 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
324 CTF Starting point for a player
329 viewing angle when spawning
331 void() info_player_team1 =
333 self.classname = "info_player_deathmatch";
334 self.team = 5; // red
335 relocate_spawnpoint();
337 //self.team = 4;self.classname = "info_player_start";info_player_start();};
339 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
340 CTF Starting point for a player in
345 viewing angle when spawning
347 void() info_player_team2 =
349 self.classname = "info_player_deathmatch";
350 self.team = 14; // blue
351 relocate_spawnpoint();
353 //self.team = 13;self.classname = "info_player_start";info_player_start();};
355 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
356 CTF Starting point for a player in
357 team three (Magenta).
361 viewing angle when spawning
363 void() info_player_team3 =
365 self.classname = "info_player_deathmatch";
366 self.team = 10; // purple
367 relocate_spawnpoint();
371 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
372 CTF Starting point for a player in
377 viewing angle when spawning
379 void() info_player_team4 =
381 self.classname = "info_player_deathmatch";
382 self.team = 13; // yellow
383 relocate_spawnpoint();
389 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
390 CTF flag for team one (Red).
391 Multiple are allowed.
395 Angle the flag will point
398 model to use, note this needs red and blue as skins 0 and 1
399 (default models/ctf/flag.md3)
401 sound played when flag is picked up
402 (default ctf/take.wav)
404 sound played when flag is returned by a teammate
405 (default ctf/return.wav)
407 sound played when flag is captured
408 (default ctf/capture.wav)
410 sound played when flag is lost in the field and respawns itself
411 (default ctf/respawn.wav)
414 void() item_flag_team1 =
418 //if(!cvar("teamplay"))
419 // cvar_set("teamplay", "3");
421 self.team = 5; // color 4 team (red)
422 self.items = IT_KEY2; // gold key (redish enough)
423 self.netname = "^1RED^7 flag";
424 self.target = "###item###";
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)
475 self.netname = "^4BLUE^7 flag";
476 self.target = "###item###";
479 self.model = "models/ctf/flag_blue.md3";
481 self.noise = "ctf/take.wav";
483 self.noise1 = "ctf/return.wav";
485 self.noise2 = "ctf/capture.wav";
487 self.noise3 = "ctf/respawn.wav";
488 precache_model (self.model);
489 setmodel (self, self.model);
490 precache_sound (self.noise);
491 precache_sound (self.noise1);
492 precache_sound (self.noise2);
493 precache_sound (self.noise3);
494 setsize(self, '-16 -16 -37', '16 16 37');
495 setorigin(self, self.origin + '0 0 37');
496 self.nextthink = time + 0.2; // start after doors etc
497 self.think = place_flag;
501 //if(!self.glow_size)
502 // self.glow_size = 50;
504 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
508 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
509 Team declaration for CTF gameplay, this allows you to decide what team
510 names and control point models are used in your map.
512 Note: If you use ctf_team entities you must define at least 2! However, unlike
513 domination, you don't need to make a blank one too.
517 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
519 Scoreboard color of the team (for example 4 is red and 13 is blue)
525 self.classname = "ctf_team";
526 self.team = self.cnt + 1;
529 // code from here on is just to support maps that don't have control point and team entities
530 void ctf_spawnteam (string teamname, float teamcolor)
532 local entity oldself;
535 self.classname = "ctf_team";
536 self.netname = teamname;
537 self.cnt = teamcolor;
544 // spawn some default teams if the map is not set up for ctf
545 void() ctf_spawnteams =
549 numteams = 2;//cvar("g_ctf_default_teams");
551 ctf_spawnteam("Red", 4);
552 ctf_spawnteam("Blue", 13);
555 void() ctf_delayedinit =
557 self.think = SUB_Remove;
558 self.nextthink = time;
559 // if no teams are found, spawn defaults
560 if (find(world, classname, "ctf_team") == world)
568 e.think = ctf_delayedinit;
569 e.nextthink = time + 0.1;