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.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 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
241 head = find(head, classname, "player");
244 if (head.team == self.team)
245 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
246 head = find(head, classname, "player");
248 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
249 RegenFlag (other.flagcarried);
250 other.flagcarried = world;
251 other.next_take_time = time + 1;
253 if (self.cnt == FLAG_BASE)
254 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
255 if (other.team != self.team)
256 if (!other.flagcarried)
258 if (other.next_take_time > time)
261 other.flagpickuptime = time; // used for timing runs
262 self.solid = SOLID_NOT;
263 setorigin(self, self.origin); // relink
265 other.flagcarried = self;
266 self.cnt = FLAG_CARRY;
267 bprint(other.netname, "^7 got the ", self.netname, "\n");
268 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
269 LogCTF("steal", self.team, other);
270 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
272 player = find(world, classname, "player");
274 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
275 player = find(player, classname, "player");
281 if (self.cnt == FLAG_DROPPED)
283 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
284 if (other.team == self.team || (other.team != 5 && other.team != 14))
287 bprint(other.netname, "^7 returned the ", self.netname, "\n");
288 if (other.team == 5 || other.team == 14)
289 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
291 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
292 LogCTF("return", self.team, other);
293 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
296 else if (!other.flagcarried)
299 other.flagpickuptime = time; // used for timing runs
300 self.solid = SOLID_NOT;
301 setorigin(self, self.origin); // relink
303 other.flagcarried = self;
304 self.cnt = FLAG_CARRY;
305 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
306 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
307 LogCTF("pickup", self.team, other);
308 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
310 player = find(world, classname, "player");
312 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
313 player = find(player, classname, "player");
319 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
320 CTF Starting point for a player
325 viewing angle when spawning
327 void() info_player_team1 =
329 self.classname = "info_player_deathmatch";
330 self.team = 5; // red
331 relocate_spawnpoint();
333 //self.team = 4;self.classname = "info_player_start";info_player_start();};
335 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
336 CTF Starting point for a player in
341 viewing angle when spawning
343 void() info_player_team2 =
345 self.classname = "info_player_deathmatch";
346 self.team = 14; // blue
347 relocate_spawnpoint();
349 //self.team = 13;self.classname = "info_player_start";info_player_start();};
351 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
352 CTF Starting point for a player in
353 team three (Magenta).
357 viewing angle when spawning
359 void() info_player_team3 =
361 self.classname = "info_player_deathmatch";
362 self.team = 10; // purple
363 relocate_spawnpoint();
367 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
368 CTF Starting point for a player in
373 viewing angle when spawning
375 void() info_player_team4 =
377 self.classname = "info_player_deathmatch";
378 self.team = 13; // yellow
379 relocate_spawnpoint();
385 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
386 CTF flag for team one (Red).
387 Multiple are allowed.
391 Angle the flag will point
394 model to use, note this needs red and blue as skins 0 and 1
395 (default models/ctf/flag.md3)
397 sound played when flag is picked up
398 (default ctf/take.wav)
400 sound played when flag is returned by a teammate
401 (default ctf/return.wav)
403 sound played when flag is captured
404 (default ctf/capture.wav)
406 sound played when flag is lost in the field and respawns itself
407 (default ctf/respawn.wav)
410 void() item_flag_team1 =
414 //if(!cvar("teamplay"))
415 // cvar_set("teamplay", "3");
417 self.team = 5; // color 4 team (red)
418 self.items = IT_KEY2; // gold key (redish enough)
419 self.netname = "^1RED^7 flag";
420 self.target = "###item###";
423 self.model = "models/ctf/flag_red.md3";
425 self.noise = "ctf/take.wav";
427 self.noise1 = "ctf/return.wav";
429 self.noise2 = "ctf/capture.wav";
431 self.noise3 = "ctf/respawn.wav";
432 precache_model (self.model);
433 setmodel (self, self.model);
434 precache_sound (self.noise);
435 precache_sound (self.noise1);
436 precache_sound (self.noise2);
437 precache_sound (self.noise3);
438 setsize(self, '-16 -16 -37', '16 16 37');
439 setorigin(self, self.origin + '0 0 37');
440 self.nextthink = time + 0.2; // start after doors etc
441 self.think = place_flag;
445 //if(!self.glow_size)
446 // self.glow_size = 50;
448 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
451 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
452 CTF flag for team two (Blue).
453 Multiple are allowed.
457 Angle the flag will point
462 void() item_flag_team2 =
466 //if(!cvar("teamplay"))
467 // cvar_set("teamplay", "3");
469 self.team = 14; // color 13 team (blue)
470 self.items = IT_KEY1; // silver key (bluish enough)
471 self.netname = "^4BLUE^7 flag";
472 self.target = "###item###";
475 self.model = "models/ctf/flag_blue.md3";
477 self.noise = "ctf/take.wav";
479 self.noise1 = "ctf/return.wav";
481 self.noise2 = "ctf/capture.wav";
483 self.noise3 = "ctf/respawn.wav";
484 precache_model (self.model);
485 setmodel (self, self.model);
486 precache_sound (self.noise);
487 precache_sound (self.noise1);
488 precache_sound (self.noise2);
489 precache_sound (self.noise3);
490 setsize(self, '-16 -16 -37', '16 16 37');
491 setorigin(self, self.origin + '0 0 37');
492 self.nextthink = time + 0.2; // start after doors etc
493 self.think = place_flag;
497 //if(!self.glow_size)
498 // self.glow_size = 50;
500 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
504 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
505 Team declaration for CTF gameplay, this allows you to decide what team
506 names and control point models are used in your map.
508 Note: If you use ctf_team entities you must define at least 2! However, unlike
509 domination, you don't need to make a blank one too.
513 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
515 Scoreboard color of the team (for example 4 is red and 13 is blue)
521 self.classname = "ctf_team";
522 self.team = self.cnt + 1;
525 // code from here on is just to support maps that don't have control point and team entities
526 void ctf_spawnteam (string teamname, float teamcolor)
528 local entity oldself;
531 self.classname = "ctf_team";
532 self.netname = teamname;
533 self.cnt = teamcolor;
540 // spawn some default teams if the map is not set up for ctf
541 void() ctf_spawnteams =
545 numteams = 2;//cvar("g_ctf_default_teams");
547 ctf_spawnteam("Red", 4);
548 ctf_spawnteam("Blue", 13);
551 void() ctf_delayedinit =
553 self.think = SUB_Remove;
554 self.nextthink = time;
555 // if no teams are found, spawn defaults
556 if (find(world, classname, "ctf_team") == world)
564 e.think = ctf_delayedinit;
565 e.nextthink = time + 0.1;