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)
75 WaypointSprite_DetachCarrier(e.owner);
76 e.owner.flagcarried = world;
82 void(entity e) DropFlag =
88 dprint("FLAG: drop - no owner?!?!\n");
92 if (p.flagcarried != e)
94 dprint("FLAG: drop - owner is not carrying this flag??\n");
97 bprint(p.netname, "^7 lost the ", e.netname, "\n");
98 WaypointSprite_DetachCarrier(p);
99 LogCTF("dropped", p.team, p.flagcarried);
101 setattachment(e, world, "");
103 if (p.flagcarried == e)
104 p.flagcarried = world;
107 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
108 e.solid = SOLID_TRIGGER;
109 e.movetype = MOVETYPE_TOSS;
110 // setsize(e, '-16 -16 0', '16 16 74');
111 setorigin(e, p.origin - '0 0 24' + '0 0 37');
112 e.cnt = FLAG_DROPPED;
113 e.velocity = '0 0 300';
114 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
116 trace_startsolid = FALSE;
117 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
119 dprint("FLAG FALLTHROUGH will happen SOON\n");
124 if(self.delay > time)
126 self.delay = time + self.t_width;
127 if(self.nextthink > self.delay)
128 self.nextthink = self.delay;
130 self.frame = self.frame + 1;
131 if(self.frame > self.t_length)
139 self.nextthink = time + 0.1;
143 if (self.cnt == FLAG_BASE)
146 if (self.cnt == FLAG_DROPPED)
148 // flag fallthrough? FIXME remove this if bug is really fixed now
149 if(self.origin_z < -131072)
151 dprint("FLAG FALLTHROUGH just happened\n");
152 self.pain_finished = 0;
154 setattachment(self, world, "");
155 if (time > self.pain_finished)
157 bprint("The ", self.netname, " has returned to base\n");
158 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
159 LogCTF("returned", self.team, world);
166 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
168 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
174 float flagcaptimerecord;
175 .float flagpickuptime;
185 if (other.classname != "player")
187 if (other.health < 1) // ignore dead players
190 if (self.cnt == FLAG_CARRY)
193 if (self.cnt == FLAG_BASE)
194 if (other.team == self.team)
195 if (other.flagcarried) // he's got a flag
196 if (other.flagcarried.team != self.team) // capture
198 if (other.flagcarried == world)
202 t = time - other.flagcarried.flagpickuptime;
203 s = ftos_decimals(t, 2);
204 s0 = ftos_decimals(flagcaptimerecord, 2);
205 if (flagcaptimerecord == 0)
207 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
208 flagcaptimerecord = t;
210 else if (t < flagcaptimerecord)
212 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking the previous record of ", s0, " seconds\n");
213 flagcaptimerecord = t;
217 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break the previous record of ", s0, " seconds\n");
220 LogCTF("capture", other.flagcarried.team, other);
221 // give credit to the individual player
222 UpdateFrags(other, cvar("g_ctf_flagscore_capture"));
224 // give credit to all players of the team (rewards large teams)
225 // NOTE: this defaults to 0
226 FOR_EACH_PLAYER(head)
227 if (head.team == self.team)
228 UpdateFrags(head, cvar("g_ctf_flagscore_capture_team"));
230 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
231 WaypointSprite_DetachCarrier(other);
232 RegenFlag (other.flagcarried);
233 other.flagcarried = world;
234 other.next_take_time = time + 1;
236 if (self.cnt == FLAG_BASE)
237 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
238 if (other.team != self.team)
239 if (!other.flagcarried)
241 if (other.next_take_time > time)
244 self.flagpickuptime = time; // used for timing runs
245 self.solid = SOLID_NOT;
246 setorigin(self, self.origin); // relink
248 other.flagcarried = self;
249 self.cnt = FLAG_CARRY;
250 self.angles = '0 0 0';
251 bprint(other.netname, "^7 got the ", self.netname, "\n");
252 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
253 LogCTF("steal", self.team, other);
254 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
256 FOR_EACH_PLAYER(player)
257 if(player.team == self.team)
258 centerprint(player, "The enemy got your flag! Retrieve it!");
260 self.movetype = MOVETYPE_NONE;
261 setorigin(self, FLAG_CARRY_POS);
262 setattachment(self, other, "");
263 WaypointSprite_AttachCarrier("flagcarrier", other);
268 if (self.cnt == FLAG_DROPPED)
270 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
271 if (other.team == self.team || (other.team != 5 && other.team != 14))
274 bprint(other.netname, "^7 returned the ", self.netname, "\n");
275 if (other.team == 5 || other.team == 14)
276 UpdateFrags(other, cvar("g_ctf_flagscore_return"));
278 UpdateFrags(other, cvar("g_ctf_flagscore_return_rogue"));
279 LogCTF("return", self.team, other);
280 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
283 else if (!other.flagcarried)
286 self.solid = SOLID_NOT;
287 setorigin(self, self.origin); // relink
289 other.flagcarried = self;
290 self.cnt = FLAG_CARRY;
291 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
292 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
293 LogCTF("pickup", self.team, other);
294 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
296 FOR_EACH_PLAYER(player)
297 if(player.team == self.team)
298 centerprint(player, "The enemy got your flag! Retrieve it!");
300 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
301 setorigin(self, FLAG_CARRY_POS);
302 setattachment(self, other, "");
303 WaypointSprite_AttachCarrier("flagcarrier", other);
308 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
309 CTF Starting point for a player
314 viewing angle when spawning
316 void() info_player_team1 =
318 self.classname = "info_player_deathmatch";
319 self.team = 5; // red
320 relocate_spawnpoint();
322 //self.team = 4;self.classname = "info_player_start";info_player_start();};
324 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
325 CTF Starting point for a player in
330 viewing angle when spawning
332 void() info_player_team2 =
334 self.classname = "info_player_deathmatch";
335 self.team = 14; // blue
336 relocate_spawnpoint();
338 //self.team = 13;self.classname = "info_player_start";info_player_start();};
340 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
341 CTF Starting point for a player in
342 team three (Magenta).
346 viewing angle when spawning
348 void() info_player_team3 =
350 self.classname = "info_player_deathmatch";
351 self.team = 10; // purple
352 relocate_spawnpoint();
356 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
357 CTF Starting point for a player in
362 viewing angle when spawning
364 void() info_player_team4 =
366 self.classname = "info_player_deathmatch";
367 self.team = 13; // yellow
368 relocate_spawnpoint();
374 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
375 CTF flag for team one (Red).
376 Multiple are allowed.
380 Angle the flag will point
383 model to use, note this needs red and blue as skins 0 and 1
384 (default models/ctf/flag.md3)
386 sound played when flag is picked up
387 (default ctf/take.wav)
389 sound played when flag is returned by a teammate
390 (default ctf/return.wav)
392 sound played when flag is captured
393 (default ctf/capture.wav)
395 sound played when flag is lost in the field and respawns itself
396 (default ctf/respawn.wav)
399 void() item_flag_team1 =
403 //if(!cvar("teamplay"))
404 // cvar_set("teamplay", "3");
406 self.classname = "item_flag_team1";
407 self.team = 5; // color 4 team (red)
408 self.items = IT_KEY2; // gold key (redish enough)
409 self.netname = "^1RED^7 flag";
410 self.target = "###item###";
413 self.model = "models/ctf/flag_red.md3";
415 self.noise = "ctf/take.wav";
417 self.noise1 = "ctf/return.wav";
419 self.noise2 = "ctf/capture.wav";
421 self.noise3 = "ctf/respawn.wav";
422 precache_model (self.model);
423 setmodel (self, self.model); // precision set below
424 precache_sound (self.noise);
425 precache_sound (self.noise1);
426 precache_sound (self.noise2);
427 precache_sound (self.noise3);
428 setsize(self, '-16 -16 -37', '16 16 37');
429 setorigin(self, self.origin + '0 0 37');
430 self.nextthink = time + 0.2; // start after doors etc
431 self.think = place_flag;
435 //if(!self.glow_size)
436 // self.glow_size = 50;
438 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
441 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37');
444 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
445 CTF flag for team two (Blue).
446 Multiple are allowed.
450 Angle the flag will point
455 void() item_flag_team2 =
459 //if(!cvar("teamplay"))
460 // cvar_set("teamplay", "3");
462 self.classname = "item_flag_team2";
463 self.team = 14; // color 13 team (blue)
464 self.items = IT_KEY1; // silver key (bluish enough)
465 self.netname = "^4BLUE^7 flag";
466 self.target = "###item###";
469 self.model = "models/ctf/flag_blue.md3";
471 self.noise = "ctf/take.wav";
473 self.noise1 = "ctf/return.wav";
475 self.noise2 = "ctf/capture.wav";
477 self.noise3 = "ctf/respawn.wav";
478 precache_model (self.model);
479 setmodel (self, self.model); // precision set below
480 precache_sound (self.noise);
481 precache_sound (self.noise1);
482 precache_sound (self.noise2);
483 precache_sound (self.noise3);
484 setsize(self, '-16 -16 -37', '16 16 37');
485 setorigin(self, self.origin + '0 0 37');
486 self.nextthink = time + 0.2; // start after doors etc
487 self.think = place_flag;
491 //if(!self.glow_size)
492 // self.glow_size = 50;
494 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
497 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37');
501 // spawnfunctions for q3 flags
502 void team_CTF_redflag()
507 void team_CTF_blueflag()
513 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
514 Team declaration for CTF gameplay, this allows you to decide what team
515 names and control point models are used in your map.
517 Note: If you use ctf_team entities you must define at least 2! However, unlike
518 domination, you don't need to make a blank one too.
522 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
524 Scoreboard color of the team (for example 4 is red and 13 is blue)
530 self.classname = "ctf_team";
531 self.team = self.cnt + 1;
534 // code from here on is just to support maps that don't have control point and team entities
535 void ctf_spawnteam (string teamname, float teamcolor)
537 local entity oldself;
540 self.classname = "ctf_team";
541 self.netname = teamname;
542 self.cnt = teamcolor;
549 // spawn some default teams if the map is not set up for ctf
550 void() ctf_spawnteams =
554 numteams = 2;//cvar("g_ctf_default_teams");
556 ctf_spawnteam("Red", 4);
557 ctf_spawnteam("Blue", 13);
560 void() ctf_delayedinit =
562 self.think = SUB_Remove;
563 self.nextthink = time;
564 // if no teams are found, spawn defaults
565 if (find(world, classname, "ctf_team") == world)
573 e.think = ctf_delayedinit;
574 e.nextthink = time + 0.1;
577 void(entity flag) ctf_setstatus2 =
581 if (flag.team == 5) shift = IT_RED_FLAG_TAKEN;
582 else if (flag.team == 14) shift = IT_BLUE_FLAG_TAKEN;
586 if (flag.cnt == FLAG_CARRY)
587 if (flag.owner == self) status = 3;
589 else if (flag.cnt == FLAG_DROPPED) status = 2;
592 self.items = self.items | (shift * status);
596 void() ctf_setstatus =
598 self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
599 self.items = self.items - (self.items & IT_RED_FLAG_LOST);
600 self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
601 self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
605 flag = find(world, classname, "item_flag_team1");
606 ctf_setstatus2(flag);
607 flag = find(world, classname, "item_flag_team2");
608 ctf_setstatus2(flag);