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;
11 #define FLAG_CARRY_POS '-15 0 7'
19 self.t_width = 0.1; // frame animation rate
21 self.t_length = 119; // maximum frame
23 setattachment(self, world, "");
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;
38 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
42 self.oldorigin = self.origin;
45 void LogCTF(string mode, float flagteam, entity actor)
48 if(!cvar("sv_eventlog"))
50 s = strcat(":ctf:", mode);
51 s = strcat(s, ":", ftos(flagteam));
53 s = strcat(s, ":", ftos(actor.playerid));
54 GameLogEcho(s, FALSE);
57 void(entity e) RegenFlag =
59 setattachment(e, world, "");
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"));
95 LogCTF("dropped", p.team, p.flagcarried);
97 setattachment(e, world, "");
99 if (p.flagcarried == e)
100 p.flagcarried = world;
103 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
104 e.solid = SOLID_TRIGGER;
105 e.movetype = MOVETYPE_TOSS;
106 // setsize(e, '-16 -16 0', '16 16 74');
107 setorigin(e, p.origin - '0 0 24' + '0 0 37');
108 e.cnt = FLAG_DROPPED;
109 e.velocity = '0 0 300';
110 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
112 trace_startsolid = FALSE;
113 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
115 dprint("FLAG FALLTHROUGH will happen SOON\n");
120 if(self.delay > time)
122 self.delay = time + self.t_width;
123 if(self.nextthink > self.delay)
124 self.nextthink = self.delay;
126 self.frame = self.frame + 1;
127 if(self.frame > self.t_length)
135 self.nextthink = time + 0.1;
139 if (self.cnt == FLAG_BASE)
142 if (self.cnt == FLAG_DROPPED)
144 // flag fallthrough? FIXME remove this if bug is really fixed now
145 if(self.origin_z < -131072)
147 dprint("FLAG FALLTHROUGH just happened\n");
148 self.pain_finished = 0;
150 setattachment(self, world, "");
151 if (time > self.pain_finished)
153 bprint(strcat("The ", self.netname, " has returned to base\n"));
154 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
155 LogCTF("returned", self.team, world);
162 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
164 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
170 float flagcaptimerecord;
171 .float flagpickuptime;
180 if (other.classname != "player")
182 if (other.health < 1) // ignore dead players
185 if (self.cnt == FLAG_CARRY)
188 if (self.cnt == FLAG_BASE)
189 if (other.team == self.team)
190 if (other.flagcarried) // he's got a flag
191 if (other.flagcarried.team != self.team) // capture
193 if (other.flagcarried == world)
197 t = time - other.flagcarried.flagpickuptime;
198 if (flagcaptimerecord == 0)
200 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), " seconds\n");
201 flagcaptimerecord = t;
203 else if (t < flagcaptimerecord)
205 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
206 flagcaptimerecord = t;
210 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
213 LogCTF("capture", other.flagcarried.team, other);
214 // give credit to the individual player
215 UpdateFrags(other, cvar("g_ctf_flagscore_capture"));
217 // give credit to all players of the team (rewards large teams)
218 // NOTE: this defaults to 0
219 FOR_EACH_PLAYER(head)
220 if (head.team == self.team)
221 UpdateFrags(head, cvar("g_ctf_flagscore_capture_team"));
223 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
224 RegenFlag (other.flagcarried);
225 other.flagcarried = world;
226 other.next_take_time = time + 1;
228 if (self.cnt == FLAG_BASE)
229 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
230 if (other.team != self.team)
231 if (!other.flagcarried)
233 if (other.next_take_time > time)
236 self.flagpickuptime = time; // used for timing runs
237 self.solid = SOLID_NOT;
238 setorigin(self, self.origin); // relink
240 other.flagcarried = self;
241 self.cnt = FLAG_CARRY;
242 bprint(other.netname, "^7 got the ", self.netname, "\n");
243 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
244 LogCTF("steal", self.team, other);
245 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
247 FOR_EACH_PLAYER(player)
248 if(player.team == self.team)
249 centerprint(player, "The enemy got your flag! Retrieve it!");
251 self.movetype = MOVETYPE_NONE;
252 setorigin(self, FLAG_CARRY_POS);
253 setattachment(self, other, "");
258 if (self.cnt == FLAG_DROPPED)
260 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
261 if (other.team == self.team || (other.team != 5 && other.team != 14))
264 bprint(other.netname, "^7 returned the ", self.netname, "\n");
265 if (other.team == 5 || other.team == 14)
266 UpdateFrags(other, cvar("g_ctf_flagscore_return"));
268 UpdateFrags(other, cvar("g_ctf_flagscore_return_rogue"));
269 LogCTF("return", self.team, other);
270 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
273 else if (!other.flagcarried)
276 self.solid = SOLID_NOT;
277 setorigin(self, self.origin); // relink
279 other.flagcarried = self;
280 self.cnt = FLAG_CARRY;
281 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
282 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
283 LogCTF("pickup", self.team, other);
284 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
286 FOR_EACH_PLAYER(player)
287 if(player.team == self.team)
288 centerprint(player, "The enemy got your flag! Retrieve it!");
290 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
291 setorigin(self, FLAG_CARRY_POS);
292 setattachment(self, other, "");
297 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
298 CTF Starting point for a player
303 viewing angle when spawning
305 void() info_player_team1 =
307 self.classname = "info_player_deathmatch";
308 self.team = 5; // red
309 relocate_spawnpoint();
311 //self.team = 4;self.classname = "info_player_start";info_player_start();};
313 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
314 CTF Starting point for a player in
319 viewing angle when spawning
321 void() info_player_team2 =
323 self.classname = "info_player_deathmatch";
324 self.team = 14; // blue
325 relocate_spawnpoint();
327 //self.team = 13;self.classname = "info_player_start";info_player_start();};
329 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
330 CTF Starting point for a player in
331 team three (Magenta).
335 viewing angle when spawning
337 void() info_player_team3 =
339 self.classname = "info_player_deathmatch";
340 self.team = 10; // purple
341 relocate_spawnpoint();
345 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
346 CTF Starting point for a player in
351 viewing angle when spawning
353 void() info_player_team4 =
355 self.classname = "info_player_deathmatch";
356 self.team = 13; // yellow
357 relocate_spawnpoint();
363 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
364 CTF flag for team one (Red).
365 Multiple are allowed.
369 Angle the flag will point
372 model to use, note this needs red and blue as skins 0 and 1
373 (default models/ctf/flag.md3)
375 sound played when flag is picked up
376 (default ctf/take.wav)
378 sound played when flag is returned by a teammate
379 (default ctf/return.wav)
381 sound played when flag is captured
382 (default ctf/capture.wav)
384 sound played when flag is lost in the field and respawns itself
385 (default ctf/respawn.wav)
388 void() item_flag_team1 =
392 //if(!cvar("teamplay"))
393 // cvar_set("teamplay", "3");
395 self.classname = "item_flag_team1";
396 self.team = 5; // color 4 team (red)
397 self.items = IT_KEY2; // gold key (redish enough)
398 self.netname = "^1RED^7 flag";
399 self.target = "###item###";
402 self.model = "models/ctf/flag_red.md3";
404 self.noise = "ctf/take.wav";
406 self.noise1 = "ctf/return.wav";
408 self.noise2 = "ctf/capture.wav";
410 self.noise3 = "ctf/respawn.wav";
411 precache_model (self.model);
412 setmodel (self, self.model);
413 precache_sound (self.noise);
414 precache_sound (self.noise1);
415 precache_sound (self.noise2);
416 precache_sound (self.noise3);
417 setsize(self, '-16 -16 -37', '16 16 37');
418 setorigin(self, self.origin + '0 0 37');
419 self.nextthink = time + 0.2; // start after doors etc
420 self.think = place_flag;
424 //if(!self.glow_size)
425 // self.glow_size = 50;
427 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
430 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
431 CTF flag for team two (Blue).
432 Multiple are allowed.
436 Angle the flag will point
441 void() item_flag_team2 =
445 //if(!cvar("teamplay"))
446 // cvar_set("teamplay", "3");
448 self.classname = "item_flag_team2";
449 self.team = 14; // color 13 team (blue)
450 self.items = IT_KEY1; // silver key (bluish enough)
451 self.netname = "^4BLUE^7 flag";
452 self.target = "###item###";
455 self.model = "models/ctf/flag_blue.md3";
457 self.noise = "ctf/take.wav";
459 self.noise1 = "ctf/return.wav";
461 self.noise2 = "ctf/capture.wav";
463 self.noise3 = "ctf/respawn.wav";
464 precache_model (self.model);
465 setmodel (self, self.model);
466 precache_sound (self.noise);
467 precache_sound (self.noise1);
468 precache_sound (self.noise2);
469 precache_sound (self.noise3);
470 setsize(self, '-16 -16 -37', '16 16 37');
471 setorigin(self, self.origin + '0 0 37');
472 self.nextthink = time + 0.2; // start after doors etc
473 self.think = place_flag;
477 //if(!self.glow_size)
478 // self.glow_size = 50;
480 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
484 // spawnfunctions for q3 flags
485 void team_CTF_redflag()
490 void team_CTF_blueflag()
496 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
497 Team declaration for CTF gameplay, this allows you to decide what team
498 names and control point models are used in your map.
500 Note: If you use ctf_team entities you must define at least 2! However, unlike
501 domination, you don't need to make a blank one too.
505 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
507 Scoreboard color of the team (for example 4 is red and 13 is blue)
513 self.classname = "ctf_team";
514 self.team = self.cnt + 1;
517 // code from here on is just to support maps that don't have control point and team entities
518 void ctf_spawnteam (string teamname, float teamcolor)
520 local entity oldself;
523 self.classname = "ctf_team";
524 self.netname = teamname;
525 self.cnt = teamcolor;
532 // spawn some default teams if the map is not set up for ctf
533 void() ctf_spawnteams =
537 numteams = 2;//cvar("g_ctf_default_teams");
539 ctf_spawnteam("Red", 4);
540 ctf_spawnteam("Blue", 13);
543 void() ctf_delayedinit =
545 self.think = SUB_Remove;
546 self.nextthink = time;
547 // if no teams are found, spawn defaults
548 if (find(world, classname, "ctf_team") == world)
556 e.think = ctf_delayedinit;
557 e.nextthink = time + 0.1;
560 void(entity flag) ctf_setstatus2 =
564 if (flag.team == 5) shift = IT_RED_FLAG_TAKEN;
565 else if (flag.team == 14) shift = IT_BLUE_FLAG_TAKEN;
569 if (flag.cnt == FLAG_CARRY)
570 if (flag.owner == self) status = 3;
572 else if (flag.cnt == FLAG_DROPPED) status = 2;
575 self.items = self.items | (shift * status);
579 void() ctf_setstatus =
581 self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
582 self.items = self.items - (self.items & IT_RED_FLAG_LOST);
583 self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
584 self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
588 flag = find(world, classname, "item_flag_team1");
589 ctf_setstatus2(flag);
590 flag = find(world, classname, "item_flag_team2");
591 ctf_setstatus2(flag);