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_NONE;
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.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
36 //self.effects = self.effects | EF_DIMLIGHT;
39 self.movetype = MOVETYPE_TOSS;
42 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
47 self.oldorigin = self.origin;
50 void LogCTF(string mode, float flagteam, entity actor)
53 if(!cvar("sv_eventlog"))
55 s = strcat(":ctf:", mode);
56 s = strcat(s, ":", ftos(flagteam));
58 s = strcat(s, ":", ftos(actor.playerid));
59 GameLogEcho(s, FALSE);
62 void(entity e) RegenFlag =
64 setattachment(e, world, "");
65 e.movetype = MOVETYPE_NONE;
67 e.movetype = MOVETYPE_TOSS;
68 e.solid = SOLID_TRIGGER;
69 // TODO: play a sound here
70 setorigin(e, e.oldorigin);
74 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
77 void(entity e) ReturnFlag =
80 if (e.owner.flagcarried == e)
82 WaypointSprite_DetachCarrier(e.owner);
83 e.owner.flagcarried = world;
89 void(entity e) DropFlag =
95 dprint("FLAG: drop - no owner?!?!\n");
99 if (p.flagcarried != e)
101 dprint("FLAG: drop - owner is not carrying this flag??\n");
104 bprint(p.netname, "^7 lost the ", e.netname, "\n");
105 WaypointSprite_DetachCarrier(p);
106 LogCTF("dropped", p.team, p.flagcarried);
108 setattachment(e, world, "");
110 if (p.flagcarried == e)
111 p.flagcarried = world;
114 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
115 e.solid = SOLID_TRIGGER;
116 e.movetype = MOVETYPE_TOSS;
117 // setsize(e, '-16 -16 0', '16 16 74');
118 setorigin(e, p.origin - '0 0 24' + '0 0 37');
119 e.cnt = FLAG_DROPPED;
120 e.velocity = '0 0 300';
121 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
123 trace_startsolid = FALSE;
124 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
126 dprint("FLAG FALLTHROUGH will happen SOON\n");
131 if(self.delay > time)
133 self.delay = time + self.t_width;
134 if(self.nextthink > self.delay)
135 self.nextthink = self.delay;
137 self.frame = self.frame + 1;
138 if(self.frame > self.t_length)
146 self.nextthink = time + 0.1;
150 if (self.cnt == FLAG_BASE)
153 if (self.cnt == FLAG_DROPPED)
155 // flag fallthrough? FIXME remove this if bug is really fixed now
156 if(self.origin_z < -131072)
158 dprint("FLAG FALLTHROUGH just happened\n");
159 self.pain_finished = 0;
161 setattachment(self, world, "");
162 if (time > self.pain_finished)
164 bprint("The ", self.netname, " has returned to base\n");
165 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
166 LogCTF("returned", self.team, world);
173 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
175 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
181 float flagcaptimerecord;
182 .float flagpickuptime;
192 if (other.classname != "player")
194 if (other.health < 1) // ignore dead players
197 if (self.cnt == FLAG_CARRY)
200 if (self.cnt == FLAG_BASE)
201 if (other.team == self.team)
202 if (other.flagcarried) // he's got a flag
203 if (other.flagcarried.team != self.team) // capture
205 if (other.flagcarried == world)
209 t = time - other.flagcarried.flagpickuptime;
210 s = ftos_decimals(t, 2);
211 s0 = ftos_decimals(flagcaptimerecord, 2);
212 if (flagcaptimerecord == 0)
214 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
215 flagcaptimerecord = t;
217 else if (t < flagcaptimerecord)
219 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking the previous record of ", s0, " seconds\n");
220 flagcaptimerecord = t;
224 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break the previous record of ", s0, " seconds\n");
227 LogCTF("capture", other.flagcarried.team, other);
228 // give credit to the individual player
229 UpdateFrags(other, cvar("g_ctf_flagscore_capture"));
231 // give credit to all players of the team (rewards large teams)
232 // NOTE: this defaults to 0
233 FOR_EACH_PLAYER(head)
234 if (head.team == self.team)
235 UpdateFrags(head, cvar("g_ctf_flagscore_capture_team"));
237 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
238 WaypointSprite_DetachCarrier(other);
239 RegenFlag (other.flagcarried);
240 other.flagcarried = world;
241 other.next_take_time = time + 1;
243 if (self.cnt == FLAG_BASE)
244 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
245 if (other.team != self.team)
246 if (!other.flagcarried)
248 if (other.next_take_time > time)
251 self.flagpickuptime = time; // used for timing runs
252 self.solid = SOLID_NOT;
253 setorigin(self, self.origin); // relink
255 other.flagcarried = self;
256 self.cnt = FLAG_CARRY;
257 self.angles = '0 0 0';
258 bprint(other.netname, "^7 got the ", self.netname, "\n");
259 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
260 LogCTF("steal", self.team, other);
261 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
263 FOR_EACH_PLAYER(player)
264 if(player.team == self.team)
265 centerprint(player, "The enemy got your flag! Retrieve it!");
267 self.movetype = MOVETYPE_NONE;
268 setorigin(self, FLAG_CARRY_POS);
269 setattachment(self, other, "");
270 WaypointSprite_AttachCarrier("flagcarrier", other);
275 if (self.cnt == FLAG_DROPPED)
277 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
278 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
281 bprint(other.netname, "^7 returned the ", self.netname, "\n");
282 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
283 UpdateFrags(other, cvar("g_ctf_flagscore_return"));
285 UpdateFrags(other, cvar("g_ctf_flagscore_return_rogue"));
286 LogCTF("return", self.team, other);
287 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
290 else if (!other.flagcarried)
293 self.solid = SOLID_NOT;
294 setorigin(self, self.origin); // relink
296 other.flagcarried = self;
297 self.cnt = FLAG_CARRY;
298 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
299 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
300 LogCTF("pickup", self.team, other);
301 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
303 FOR_EACH_PLAYER(player)
304 if(player.team == self.team)
305 centerprint(player, "The enemy got your flag! Retrieve it!");
307 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
308 setorigin(self, FLAG_CARRY_POS);
309 setattachment(self, other, "");
310 WaypointSprite_AttachCarrier("flagcarrier", other);
315 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
316 CTF Starting point for a player
321 viewing angle when spawning
323 void() info_player_team1 =
325 self.team = COLOR_TEAM1; // red
326 info_player_deathmatch();
328 //self.team = 4;self.classname = "info_player_start";info_player_start();};
330 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
331 CTF Starting point for a player in
336 viewing angle when spawning
338 void() info_player_team2 =
340 self.team = COLOR_TEAM2; // blue
341 info_player_deathmatch();
343 //self.team = 13;self.classname = "info_player_start";info_player_start();};
345 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
346 CTF Starting point for a player in
347 team three (Magenta).
351 viewing angle when spawning
353 void() info_player_team3 =
355 self.team = COLOR_TEAM3; // purple
356 info_player_deathmatch();
360 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
361 CTF Starting point for a player in
366 viewing angle when spawning
368 void() info_player_team4 =
370 self.team = COLOR_TEAM4; // yellow
371 info_player_deathmatch();
377 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
378 CTF flag for team one (Red).
379 Multiple are allowed.
383 Angle the flag will point
386 model to use, note this needs red and blue as skins 0 and 1
387 (default models/ctf/flag.md3)
389 sound played when flag is picked up
390 (default ctf/take.wav)
392 sound played when flag is returned by a teammate
393 (default ctf/return.wav)
395 sound played when flag is captured
396 (default ctf/capture.wav)
398 sound played when flag is lost in the field and respawns itself
399 (default ctf/respawn.wav)
402 void() item_flag_team1 =
406 //if(!cvar("teamplay"))
407 // cvar_set("teamplay", "3");
409 self.classname = "item_flag_team1";
410 self.team = COLOR_TEAM1; // color 4 team (red)
411 self.items = IT_KEY2; // gold key (redish enough)
412 self.netname = "^1RED^7 flag";
413 self.target = "###item###";
415 if(self.spawnflags & 1)
418 self.model = "models/ctf/flag_red.md3";
420 self.noise = "ctf/take.wav";
422 self.noise1 = "ctf/return.wav";
424 self.noise2 = "ctf/capture.wav";
426 self.noise3 = "ctf/respawn.wav";
427 precache_model (self.model);
428 setmodel (self, self.model); // precision set below
429 precache_sound (self.noise);
430 precache_sound (self.noise1);
431 precache_sound (self.noise2);
432 precache_sound (self.noise3);
433 setsize(self, '-16 -16 -37', '16 16 37');
434 setorigin(self, self.origin + '0 0 37');
435 self.nextthink = time + 0.2; // start after doors etc
436 self.think = place_flag;
440 //if(!self.glow_size)
441 // self.glow_size = 50;
443 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
447 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37');
450 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
451 CTF flag for team two (Blue).
452 Multiple are allowed.
456 Angle the flag will point
461 void() item_flag_team2 =
465 //if(!cvar("teamplay"))
466 // cvar_set("teamplay", "3");
468 self.classname = "item_flag_team2";
469 self.team = COLOR_TEAM2; // color 13 team (blue)
470 self.items = IT_KEY1; // silver key (bluish enough)
471 self.netname = "^4BLUE^7 flag";
472 self.target = "###item###";
474 if(self.spawnflags & 1)
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); // precision set below
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 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37');
510 // spawnfunctions for q3 flags
511 void team_CTF_redflag()
516 void team_CTF_blueflag()
522 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
523 Team declaration for CTF gameplay, this allows you to decide what team
524 names and control point models are used in your map.
526 Note: If you use ctf_team entities you must define at least 2! However, unlike
527 domination, you don't need to make a blank one too.
531 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
533 Scoreboard color of the team (for example 4 is red and 13 is blue)
539 self.classname = "ctf_team";
540 self.team = self.cnt + 1;
543 // code from here on is just to support maps that don't have control point and team entities
544 void ctf_spawnteam (string teamname, float teamcolor)
546 local entity oldself;
549 self.classname = "ctf_team";
550 self.netname = teamname;
551 self.cnt = teamcolor;
558 // spawn some default teams if the map is not set up for ctf
559 void() ctf_spawnteams =
563 numteams = 2;//cvar("g_ctf_default_teams");
565 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
566 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
569 void() ctf_delayedinit =
571 self.think = SUB_Remove;
572 self.nextthink = time;
573 // if no teams are found, spawn defaults
574 if (find(world, classname, "ctf_team") == world)
582 e.think = ctf_delayedinit;
583 e.nextthink = time + 0.1;
586 void(entity flag) ctf_setstatus2 =
590 if (flag.team == COLOR_TEAM1) shift = IT_RED_FLAG_TAKEN;
591 else if (flag.team == COLOR_TEAM2) shift = IT_BLUE_FLAG_TAKEN;
595 if (flag.cnt == FLAG_CARRY)
596 if (flag.owner == self) status = 3;
598 else if (flag.cnt == FLAG_DROPPED) status = 2;
601 self.items = self.items | (shift * status);
605 void() ctf_setstatus =
607 self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
608 self.items = self.items - (self.items & IT_RED_FLAG_LOST);
609 self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
610 self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
614 flag = find(world, classname, "item_flag_team1");
615 ctf_setstatus2(flag);
616 flag = find(world, classname, "item_flag_team2");
617 ctf_setstatus2(flag);