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
6 //float FLAGSCORE_PICKUP = 1;
7 //float FLAGSCORE_RETURN = 5; // returned by owner team
8 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
9 //float FLAGSCORE_CAPTURE = 5;
10 //float FLAGSCORE_CAPTURE_TEAM = 20;
12 #define FLAG_CARRY_POS '-15 0 7'
20 self.t_width = 0.1; // frame animation rate
22 self.t_length = 119; // maximum frame
24 setattachment(self, world, "");
25 self.mdl = self.model;
27 self.solid = SOLID_TRIGGER;
28 self.movetype = self.movetype_orig;
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.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
37 //self.effects = self.effects | EF_DIMLIGHT;
41 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
45 self.oldorigin = self.origin;
48 void LogCTF(string mode, float flagteam, entity actor)
51 if(!cvar("sv_eventlog"))
53 s = strcat(":ctf:", mode);
54 s = strcat(s, ":", ftos(flagteam));
56 s = strcat(s, ":", ftos(actor.playerid));
57 GameLogEcho(s, FALSE);
60 void(entity e) RegenFlag =
62 setattachment(e, world, "");
63 e.movetype = self.movetype_orig;
64 e.solid = SOLID_TRIGGER;
65 // TODO: play a sound here
66 setorigin(e, e.oldorigin);
70 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
73 void(entity e) ReturnFlag =
76 if (e.owner.flagcarried == e)
78 WaypointSprite_DetachCarrier(e.owner);
79 e.owner.flagcarried = world;
85 void(entity e) DropFlag =
91 dprint("FLAG: drop - no owner?!?!\n");
95 if (p.flagcarried != e)
97 dprint("FLAG: drop - owner is not carrying this flag??\n");
100 bprint(p.netname, "^7 lost the ", e.netname, "\n");
101 WaypointSprite_DetachCarrier(p);
102 LogCTF("dropped", p.team, p.flagcarried);
104 setattachment(e, world, "");
106 if (p.flagcarried == e)
107 p.flagcarried = world;
110 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
111 e.solid = SOLID_TRIGGER;
112 e.movetype = MOVETYPE_TOSS;
113 // setsize(e, '-16 -16 0', '16 16 74');
114 setorigin(e, p.origin - '0 0 24' + '0 0 37');
115 e.cnt = FLAG_DROPPED;
116 e.velocity = '0 0 300';
117 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
119 trace_startsolid = FALSE;
120 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
122 dprint("FLAG FALLTHROUGH will happen SOON\n");
127 if(self.delay > time)
129 self.delay = time + self.t_width;
130 if(self.nextthink > self.delay)
131 self.nextthink = self.delay;
133 self.frame = self.frame + 1;
134 if(self.frame > self.t_length)
142 self.nextthink = time + 0.1;
146 if (self.cnt == FLAG_BASE)
149 if (self.cnt == FLAG_DROPPED)
151 // flag fallthrough? FIXME remove this if bug is really fixed now
152 if(self.origin_z < -131072)
154 dprint("FLAG FALLTHROUGH just happened\n");
155 self.pain_finished = 0;
157 setattachment(self, world, "");
158 if (time > self.pain_finished)
160 bprint("The ", self.netname, " has returned to base\n");
161 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
162 LogCTF("returned", self.team, world);
169 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
171 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
177 float flagcaptimerecord;
178 .float flagpickuptime;
188 if (other.classname != "player")
190 if (other.health < 1) // ignore dead players
193 if (self.cnt == FLAG_CARRY)
196 if (self.cnt == FLAG_BASE)
197 if (other.team == self.team)
198 if (other.flagcarried) // he's got a flag
199 if (other.flagcarried.team != self.team) // capture
201 if (other.flagcarried == world)
205 t = time - other.flagcarried.flagpickuptime;
206 s = ftos_decimals(t, 2);
207 s0 = ftos_decimals(flagcaptimerecord, 2);
208 if (flagcaptimerecord == 0)
210 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
211 flagcaptimerecord = t;
213 else if (t < flagcaptimerecord)
215 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking the previous record of ", s0, " seconds\n");
216 flagcaptimerecord = t;
220 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break the previous record of ", s0, " seconds\n");
223 LogCTF("capture", other.flagcarried.team, other);
224 // give credit to the individual player
225 UpdateFrags(other, cvar("g_ctf_flagscore_capture"));
227 // give credit to all players of the team (rewards large teams)
228 // NOTE: this defaults to 0
229 FOR_EACH_PLAYER(head)
230 if (head.team == self.team)
231 UpdateFrags(head, cvar("g_ctf_flagscore_capture_team"));
233 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
234 WaypointSprite_DetachCarrier(other);
235 RegenFlag (other.flagcarried);
236 other.flagcarried = world;
237 other.next_take_time = time + 1;
239 if (self.cnt == FLAG_BASE)
240 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
241 if (other.team != self.team)
242 if (!other.flagcarried)
244 if (other.next_take_time > time)
247 self.flagpickuptime = time; // used for timing runs
248 self.solid = SOLID_NOT;
249 setorigin(self, self.origin); // relink
251 other.flagcarried = self;
252 self.cnt = FLAG_CARRY;
253 self.angles = '0 0 0';
254 bprint(other.netname, "^7 got the ", self.netname, "\n");
255 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
256 LogCTF("steal", self.team, other);
257 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
259 FOR_EACH_PLAYER(player)
260 if(player.team == self.team)
261 centerprint(player, "The enemy got your flag! Retrieve it!");
263 self.movetype = MOVETYPE_NONE;
264 setorigin(self, FLAG_CARRY_POS);
265 setattachment(self, other, "");
266 WaypointSprite_AttachCarrier("flagcarrier", other);
271 if (self.cnt == FLAG_DROPPED)
273 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
274 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
277 bprint(other.netname, "^7 returned the ", self.netname, "\n");
278 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
279 UpdateFrags(other, cvar("g_ctf_flagscore_return"));
281 UpdateFrags(other, cvar("g_ctf_flagscore_return_rogue"));
282 LogCTF("return", self.team, other);
283 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
286 else if (!other.flagcarried)
289 self.solid = SOLID_NOT;
290 setorigin(self, self.origin); // relink
292 other.flagcarried = self;
293 self.cnt = FLAG_CARRY;
294 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
295 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
296 LogCTF("pickup", self.team, other);
297 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
299 FOR_EACH_PLAYER(player)
300 if(player.team == self.team)
301 centerprint(player, "The enemy got your flag! Retrieve it!");
303 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
304 setorigin(self, FLAG_CARRY_POS);
305 setattachment(self, other, "");
306 WaypointSprite_AttachCarrier("flagcarrier", other);
311 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
312 CTF Starting point for a player
317 viewing angle when spawning
319 void() info_player_team1 =
321 self.team = COLOR_TEAM1; // red
322 info_player_deathmatch();
324 //self.team = 4;self.classname = "info_player_start";info_player_start();};
326 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
327 CTF Starting point for a player in
332 viewing angle when spawning
334 void() info_player_team2 =
336 self.team = COLOR_TEAM2; // blue
337 info_player_deathmatch();
339 //self.team = 13;self.classname = "info_player_start";info_player_start();};
341 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
342 CTF Starting point for a player in
343 team three (Magenta).
347 viewing angle when spawning
349 void() info_player_team3 =
351 self.team = COLOR_TEAM3; // purple
352 info_player_deathmatch();
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.team = COLOR_TEAM4; // yellow
367 info_player_deathmatch();
373 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
374 CTF flag for team one (Red).
375 Multiple are allowed.
379 Angle the flag will point
382 model to use, note this needs red and blue as skins 0 and 1
383 (default models/ctf/flag.md3)
385 sound played when flag is picked up
386 (default ctf/take.wav)
388 sound played when flag is returned by a teammate
389 (default ctf/return.wav)
391 sound played when flag is captured
392 (default ctf/capture.wav)
394 sound played when flag is lost in the field and respawns itself
395 (default ctf/respawn.wav)
398 void() item_flag_team1 =
402 //if(!cvar("teamplay"))
403 // cvar_set("teamplay", "3");
405 self.classname = "item_flag_team1";
406 self.team = COLOR_TEAM1; // color 4 team (red)
407 self.items = IT_KEY2; // gold key (redish enough)
408 self.netname = "^1RED^7 flag";
409 self.target = "###item###";
411 if(self.spawnflags & 1)
414 self.model = "models/ctf/flag_red.md3";
416 self.noise = "ctf/take.wav";
418 self.noise1 = "ctf/return.wav";
420 self.noise2 = "ctf/capture.wav";
422 self.noise3 = "ctf/respawn.wav";
423 precache_model (self.model);
424 setmodel (self, self.model); // precision set below
425 precache_sound (self.noise);
426 precache_sound (self.noise1);
427 precache_sound (self.noise2);
428 precache_sound (self.noise3);
429 setsize(self, '-16 -16 -37', '16 16 37');
430 setorigin(self, self.origin + '0 0 37');
431 self.nextthink = time + 0.2; // start after doors etc
432 self.think = place_flag;
436 //if(!self.glow_size)
437 // self.glow_size = 50;
439 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
443 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37');
446 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
447 CTF flag for team two (Blue).
448 Multiple are allowed.
452 Angle the flag will point
457 void() item_flag_team2 =
461 //if(!cvar("teamplay"))
462 // cvar_set("teamplay", "3");
464 self.classname = "item_flag_team2";
465 self.team = COLOR_TEAM2; // color 13 team (blue)
466 self.items = IT_KEY1; // silver key (bluish enough)
467 self.netname = "^4BLUE^7 flag";
468 self.target = "###item###";
470 if(self.spawnflags & 1)
473 self.model = "models/ctf/flag_blue.md3";
475 self.noise = "ctf/take.wav";
477 self.noise1 = "ctf/return.wav";
479 self.noise2 = "ctf/capture.wav";
481 self.noise3 = "ctf/respawn.wav";
482 precache_model (self.model);
483 setmodel (self, self.model); // precision set below
484 precache_sound (self.noise);
485 precache_sound (self.noise1);
486 precache_sound (self.noise2);
487 precache_sound (self.noise3);
488 setsize(self, '-16 -16 -37', '16 16 37');
489 setorigin(self, self.origin + '0 0 37');
490 self.nextthink = time + 0.2; // start after doors etc
491 self.think = place_flag;
495 //if(!self.glow_size)
496 // self.glow_size = 50;
498 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
502 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37');
506 // spawnfunctions for q3 flags
507 void team_CTF_redflag()
512 void team_CTF_blueflag()
518 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
519 Team declaration for CTF gameplay, this allows you to decide what team
520 names and control point models are used in your map.
522 Note: If you use ctf_team entities you must define at least 2! However, unlike
523 domination, you don't need to make a blank one too.
527 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
529 Scoreboard color of the team (for example 4 is red and 13 is blue)
535 self.classname = "ctf_team";
536 self.team = self.cnt + 1;
539 // code from here on is just to support maps that don't have control point and team entities
540 void ctf_spawnteam (string teamname, float teamcolor)
542 local entity oldself;
545 self.classname = "ctf_team";
546 self.netname = teamname;
547 self.cnt = teamcolor;
554 // spawn some default teams if the map is not set up for ctf
555 void() ctf_spawnteams =
559 numteams = 2;//cvar("g_ctf_default_teams");
561 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
562 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
565 void() ctf_delayedinit =
567 self.think = SUB_Remove;
568 self.nextthink = time;
569 // if no teams are found, spawn defaults
570 if (find(world, classname, "ctf_team") == world)
578 e.think = ctf_delayedinit;
579 e.nextthink = time + 0.1;
582 void(entity flag) ctf_setstatus2 =
586 if (flag.team == COLOR_TEAM1) shift = IT_RED_FLAG_TAKEN;
587 else if (flag.team == COLOR_TEAM2) shift = IT_BLUE_FLAG_TAKEN;
591 if (flag.cnt == FLAG_CARRY)
592 if (flag.owner == self) status = 3;
594 else if (flag.cnt == FLAG_DROPPED) status = 2;
597 self.items = self.items | (shift * status);
601 void() ctf_setstatus =
603 self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
604 self.items = self.items - (self.items & IT_RED_FLAG_LOST);
605 self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
606 self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
610 flag = find(world, classname, "item_flag_team1");
611 ctf_setstatus2(flag);
612 flag = find(world, classname, "item_flag_team2");
613 ctf_setstatus2(flag);