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;
36 if (!droptofloor(0, 0))
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"));
96 setattachment(e, world, "");
98 if (p.flagcarried == e)
99 p.flagcarried = world;
102 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
103 e.solid = SOLID_TRIGGER;
104 e.movetype = MOVETYPE_TOSS;
105 // setsize(e, '-16 -16 0', '16 16 74');
106 setorigin(e, p.origin - '0 0 24');
107 e.cnt = FLAG_DROPPED;
108 e.velocity = '0 0 300';
109 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
114 if(self.delay > time)
116 self.delay = time + self.t_width;
117 if(self.nextthink > self.delay)
118 self.nextthink = self.delay;
120 self.frame = self.frame + 1;
121 if(self.frame > self.t_length)
129 self.nextthink = time + 0.1;
133 if (self.cnt == FLAG_BASE)
136 if (self.cnt == FLAG_DROPPED)
138 setattachment(self, world, "");
139 if (time > self.pain_finished)
141 bprint(strcat("The ", self.netname, " has returned to base\n"));
142 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
143 LogCTF("returned", self.team, world);
150 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
153 LogCTF("dropped", self.team, e);
158 float flagcaptimerecord;
159 .float flagpickuptime;
168 if (other.classname != "player")
170 if (other.health < 1) // ignore dead players
173 if (self.cnt == FLAG_CARRY)
176 if (self.cnt == FLAG_BASE)
177 if (other.team == self.team)
178 if (other.flagcarried) // he's got a flag
179 if (other.flagcarried.team != self.team) // capture
181 if (other.flagcarried == world)
185 t = time - other.flagcarried.flagpickuptime;
186 if (flagcaptimerecord == 0)
188 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), " seconds\n");
189 flagcaptimerecord = t;
191 else if (t < flagcaptimerecord)
193 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n");
194 flagcaptimerecord = t;
198 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n");
201 LogCTF("capture", other.flagcarried.team, other);
202 // give credit to the individual player
203 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
204 // give credit to all players of the team (rewards large teams)
205 // NOTE: this defaults to 0
206 head = find(head, classname, "player");
209 if (head.team == self.team)
210 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
211 head = find(head, classname, "player");
213 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
214 RegenFlag (other.flagcarried);
215 other.flagcarried = world;
216 other.next_take_time = time + 1;
218 if (self.cnt == FLAG_BASE)
219 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
220 if (other.team != self.team)
221 if (!other.flagcarried)
223 if (other.next_take_time > time)
226 self.flagpickuptime = time; // used for timing runs
227 self.solid = SOLID_NOT;
228 setorigin(self, self.origin); // relink
230 other.flagcarried = self;
231 self.cnt = FLAG_CARRY;
232 bprint(other.netname, "^7 got the ", self.netname, "\n");
233 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
234 LogCTF("steal", self.team, other);
235 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
237 player = find(world, classname, "player");
239 if(player.team == self.team) centermsg_setfor(player, CENTERMSG_CTF, "The enemy got your flag! Retrieve it!");
240 player = find(player, classname, "player");
243 self.movetype = MOVETYPE_NONE;
244 setorigin(self, FLAG_CARRY_POS);
245 setattachment(self, other, "");
250 if (self.cnt == FLAG_DROPPED)
252 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
253 if (other.team == self.team || (other.team != 5 && other.team != 14))
256 bprint(other.netname, "^7 returned the ", self.netname, "\n");
257 if (other.team == 5 || other.team == 14)
258 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
260 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
261 LogCTF("return", self.team, other);
262 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
265 else if (!other.flagcarried)
268 self.solid = SOLID_NOT;
269 setorigin(self, self.origin); // relink
271 other.flagcarried = self;
272 self.cnt = FLAG_CARRY;
273 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
274 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
275 LogCTF("pickup", self.team, other);
276 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
278 player = find(world, classname, "player");
280 if(player.team == self.team) centermsg_setfor(player, CENTERMSG_CTF, "The enemy got your flag! Retrieve it!");
281 player = find(player, classname, "player");
283 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
284 setorigin(self, FLAG_CARRY_POS);
285 setattachment(self, other, "");
290 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
291 CTF Starting point for a player
296 viewing angle when spawning
298 void() info_player_team1 =
300 self.classname = "info_player_deathmatch";
301 self.team = 5; // red
302 relocate_spawnpoint();
304 //self.team = 4;self.classname = "info_player_start";info_player_start();};
306 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
307 CTF Starting point for a player in
312 viewing angle when spawning
314 void() info_player_team2 =
316 self.classname = "info_player_deathmatch";
317 self.team = 14; // blue
318 relocate_spawnpoint();
320 //self.team = 13;self.classname = "info_player_start";info_player_start();};
322 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
323 CTF Starting point for a player in
324 team three (Magenta).
328 viewing angle when spawning
330 void() info_player_team3 =
332 self.classname = "info_player_deathmatch";
333 self.team = 10; // purple
334 relocate_spawnpoint();
338 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
339 CTF Starting point for a player in
344 viewing angle when spawning
346 void() info_player_team4 =
348 self.classname = "info_player_deathmatch";
349 self.team = 13; // yellow
350 relocate_spawnpoint();
356 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
357 CTF flag for team one (Red).
358 Multiple are allowed.
362 Angle the flag will point
365 model to use, note this needs red and blue as skins 0 and 1
366 (default models/ctf/flag.md3)
368 sound played when flag is picked up
369 (default ctf/take.wav)
371 sound played when flag is returned by a teammate
372 (default ctf/return.wav)
374 sound played when flag is captured
375 (default ctf/capture.wav)
377 sound played when flag is lost in the field and respawns itself
378 (default ctf/respawn.wav)
381 void() item_flag_team1 =
385 //if(!cvar("teamplay"))
386 // cvar_set("teamplay", "3");
388 self.classname = "item_flag_team1";
389 self.team = 5; // color 4 team (red)
390 self.items = IT_KEY2; // gold key (redish enough)
391 self.netname = "^1RED^7 flag";
392 self.target = "###item###";
395 self.model = "models/ctf/flag_red.md3";
397 self.noise = "ctf/take.wav";
399 self.noise1 = "ctf/return.wav";
401 self.noise2 = "ctf/capture.wav";
403 self.noise3 = "ctf/respawn.wav";
404 precache_model (self.model);
405 setmodel (self, self.model);
406 precache_sound (self.noise);
407 precache_sound (self.noise1);
408 precache_sound (self.noise2);
409 precache_sound (self.noise3);
410 setsize(self, '-16 -16 -37', '16 16 37');
411 setorigin(self, self.origin + '0 0 37');
412 self.nextthink = time + 0.2; // start after doors etc
413 self.think = place_flag;
417 //if(!self.glow_size)
418 // self.glow_size = 50;
420 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
423 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
424 CTF flag for team two (Blue).
425 Multiple are allowed.
429 Angle the flag will point
434 void() item_flag_team2 =
438 //if(!cvar("teamplay"))
439 // cvar_set("teamplay", "3");
441 self.classname = "item_flag_team2";
442 self.team = 14; // color 13 team (blue)
443 self.items = IT_KEY1; // silver key (bluish enough)
444 self.netname = "^4BLUE^7 flag";
445 self.target = "###item###";
448 self.model = "models/ctf/flag_blue.md3";
450 self.noise = "ctf/take.wav";
452 self.noise1 = "ctf/return.wav";
454 self.noise2 = "ctf/capture.wav";
456 self.noise3 = "ctf/respawn.wav";
457 precache_model (self.model);
458 setmodel (self, self.model);
459 precache_sound (self.noise);
460 precache_sound (self.noise1);
461 precache_sound (self.noise2);
462 precache_sound (self.noise3);
463 setsize(self, '-16 -16 -37', '16 16 37');
464 setorigin(self, self.origin + '0 0 37');
465 self.nextthink = time + 0.2; // start after doors etc
466 self.think = place_flag;
470 //if(!self.glow_size)
471 // self.glow_size = 50;
473 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
477 // spawnfunctions for q3 flags
478 void team_CTF_redflag()
483 void team_CTF_blueflag()
489 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
490 Team declaration for CTF gameplay, this allows you to decide what team
491 names and control point models are used in your map.
493 Note: If you use ctf_team entities you must define at least 2! However, unlike
494 domination, you don't need to make a blank one too.
498 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
500 Scoreboard color of the team (for example 4 is red and 13 is blue)
506 self.classname = "ctf_team";
507 self.team = self.cnt + 1;
510 // code from here on is just to support maps that don't have control point and team entities
511 void ctf_spawnteam (string teamname, float teamcolor)
513 local entity oldself;
516 self.classname = "ctf_team";
517 self.netname = teamname;
518 self.cnt = teamcolor;
525 // spawn some default teams if the map is not set up for ctf
526 void() ctf_spawnteams =
530 numteams = 2;//cvar("g_ctf_default_teams");
532 ctf_spawnteam("Red", 4);
533 ctf_spawnteam("Blue", 13);
536 void() ctf_delayedinit =
538 self.think = SUB_Remove;
539 self.nextthink = time;
540 // if no teams are found, spawn defaults
541 if (find(world, classname, "ctf_team") == world)
549 e.think = ctf_delayedinit;
550 e.nextthink = time + 0.1;
553 void(entity flag) ctf_setstatus2 =
557 if (flag.team == 5) shift = IT_RED_FLAG_TAKEN;
558 else if (flag.team == 14) shift = IT_BLUE_FLAG_TAKEN;
562 if (flag.cnt == FLAG_CARRY)
563 if (flag.owner == self) status = 3;
565 else if (flag.cnt == FLAG_DROPPED) status = 2;
568 self.items = self.items | (shift * status);
572 void() ctf_setstatus =
574 self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
575 self.items = self.items - (self.items & IT_RED_FLAG_LOST);
576 self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
577 self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
581 flag = find(world, classname, "item_flag_team1");
582 ctf_setstatus2(flag);
583 flag = find(world, classname, "item_flag_team2");
584 ctf_setstatus2(flag);