4 //float FLAGSCORE_PICKUP = 1;
5 //float FLAGSCORE_RETURN = 5; // returned by owner team
6 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
7 //float FLAGSCORE_CAPTURE = 5;
8 //float FLAGSCORE_CAPTURE_TEAM = 20;
12 float FLAG_DROPPED = 3;
20 self.t_width = 0.1; // frame animation rate
22 self.t_length = 119; // maximum frame
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(entity e) RegenFlag =
47 e.movetype = MOVETYPE_TOSS;
48 e.solid = SOLID_TRIGGER;
49 // TODO: play a sound here
50 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
51 setorigin(e, e.oldorigin);
55 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
58 void(entity e) ReturnFlag =
61 if (e.owner.flagcarried == e)
62 e.owner.flagcarried = world;
67 void(entity e) DropFlag =
73 dprint("FLAG: drop - no owner?!?!\n");
77 if (p.flagcarried != e)
79 dprint("FLAG: drop - owner is not carrying this flag??\n");
84 bprint(" lost the RED flag\n");
86 bprint(" lost the BLUE flag\n");
87 if (p.flagcarried == e)
88 p.flagcarried = world;
91 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
92 e.solid = SOLID_TRIGGER;
93 e.movetype = MOVETYPE_TOSS;
94 // setsize(e, '-16 -16 0', '16 16 74');
95 setorigin(e, p.origin - '0 0 24');
97 e.velocity = '0 0 300';
98 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
103 if(self.delay > time)
105 self.delay = time + self.t_width;
106 if(self.nextthink > self.delay)
107 self.nextthink = self.delay;
109 self.frame = self.frame + 1;
110 if(self.frame > self.t_length)
120 self.nextthink = time + 0.1;
124 if (self.cnt == FLAG_BASE)
127 if (self.cnt == FLAG_DROPPED)
129 if (time > self.pain_finished)
132 bprint("The RED flag has returned to base\n");
134 bprint("The BLUE flag has returned to base\n");
141 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
147 // borrowed from threewave CTF, because it would be way too much work
149 makevectors (e.angles);
151 v_z = 0 - v_z; // reverse z
155 if (e.frame >= 29 && e.frame <= 40)
157 if (e.frame >= 29 && e.frame <= 34)
160 if (e.frame == 29) f = f + 2;
161 else if (e.frame == 30) f = f + 8;
162 else if (e.frame == 31) f = f + 12;
163 else if (e.frame == 32) f = f + 11;
164 else if (e.frame == 33) f = f + 10;
165 else if (e.frame == 34) f = f + 4;
167 else if (e.frame >= 35 && e.frame <= 40)
170 if (e.frame == 35) f = f + 2;
171 else if (e.frame == 36) f = f + 10;
172 else if (e.frame == 37) f = f + 10;
173 else if (e.frame == 38) f = f + 8;
174 else if (e.frame == 39) f = f + 4;
175 else if (e.frame == 40) f = f + 2;
178 else if (e.frame >= 103 && e.frame <= 118)
180 if (e.frame >= 103 && e.frame <= 104) f = f + 6; //nailattack
181 else if (e.frame >= 105 && e.frame <= 106) f = f + 6; //light
182 else if (e.frame >= 107 && e.frame <= 112) f = f + 7; //rocketattack
183 else if (e.frame >= 112 && e.frame <= 118) f = f + 7; //shotattack
186 self.angles = e.angles + '0 0 -45';
187 setorigin (self, e.origin + '0 0 0' - f*v + v_right * 22);
188 self.nextthink = time + 0.01;
191 float flagcaptimerecord;
192 .float flagpickuptime;
198 if (other.classname != "player")
200 if (other.health < 1) // ignore dead players
203 if (self.cnt == FLAG_CARRY)
206 if (self.cnt == FLAG_BASE)
207 if (other.team == self.team)
208 if (other.flagcarried) // he's got a flag
209 if (other.flagcarried.team != self.team) // capture
211 t = time - other.flagpickuptime;
212 if (flagcaptimerecord == 0)
214 if (other.flagcarried.team == 5)
215 bprint(other.netname, " captured the RED flag in ", ftos(t), " seconds\n");
217 bprint(other.netname, " captured the BLUE flag in ", ftos(t), " seconds\n");
218 flagcaptimerecord = t;
220 else if (t < flagcaptimerecord)
222 if (other.flagcarried.team == 5)
223 bprint(other.netname, " captured the RED flag in ", ftos(t), ", breaking the previous record of", ftos(flagcaptimerecord), " seconds\n");
225 bprint(other.netname, " captured the BLUE flag in ", ftos(t), ", breaking the previous record of", ftos(flagcaptimerecord), " seconds\n");
226 flagcaptimerecord = t;
230 if (other.flagcarried.team == 5)
231 bprint(other.netname, " captured the RED flag in ", ftos(t), ", failing to break the previous record of", ftos(flagcaptimerecord), " seconds\n");
233 bprint(other.netname, " captured the BLUE flag in ", ftos(t), ", failing to break the previous record of", ftos(flagcaptimerecord), " seconds\n");
235 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
236 head = find(head, classname, "player");
239 if (head.team == self.team)
240 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
241 head = find(head, classname, "player");
243 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
244 ReturnFlag(other.flagcarried);
246 if (self.cnt == FLAG_BASE)
247 if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
248 if (other.team != self.team)
249 if (!other.flagcarried)
252 other.flagpickuptime = time; // used for timing runs
253 self.solid = SOLID_NOT;
254 setorigin(self, self.origin); // relink
256 other.flagcarried = self;
257 self.cnt = FLAG_CARRY;
258 if (other.flagcarried.team == 5)
259 bprint(other.netname, " got the RED flag\n");
261 bprint(other.netname, " got the BLUE flag\n");
262 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
263 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
266 player = find(world, classname, "player");
268 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
269 player = find(player, classname, "player");
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 != 5 && other.team != 14))
282 bprint(other.netname, " returned the RED flag\n");
284 bprint(other.netname, " returned the BLUE flag\n");
285 if (other.team == 5 || other.team == 14)
286 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
288 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
289 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
292 else if (!other.flagcarried)
295 other.flagpickuptime = time; // used for timing runs
296 self.solid = SOLID_NOT;
297 setorigin(self, self.origin); // relink
299 other.flagcarried = self;
300 self.cnt = FLAG_CARRY;
302 bprint(other.netname, " picked up the RED flag\n");
304 bprint(other.netname, " picked up the BLUE flag\n");
305 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
306 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
309 player = find(world, classname, "player");
311 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
312 player = find(player, classname, "player");
318 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
319 CTF Starting point for a player
324 viewing angle when spawning
326 void() info_player_team1 =
329 self.classname = "info_player_deathmatch";
331 //self.team = 4;self.classname = "info_player_start";info_player_start();};
333 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
334 CTF Starting point for a player in
339 viewing angle when spawning
341 void() info_player_team2 =
344 self.classname = "info_player_deathmatch";
346 //self.team = 13;self.classname = "info_player_start";info_player_start();};
348 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
349 CTF Starting point for a player in
354 viewing angle when spawning
356 void() info_player_team3 =
359 self.classname = "info_player_deathmatch";
363 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
364 CTF Starting point for a player in
369 viewing angle when spawning
371 void() info_player_team4 =
374 self.classname = "info_player_deathmatch";
380 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
381 CTF flag for team one (Red).
382 Multiple are allowed.
386 Angle the flag will point
389 model to use, note this needs red and blue as skins 0 and 1
390 (default models/ctf/flag.md3)
392 sound played when flag is picked up
393 (default ctf/take.wav)
395 sound played when flag is returned by a teammate
396 (default ctf/return.wav)
398 sound played when flag is captured
399 (default ctf/capture.wav)
401 sound played when flag is lost in the field and respawns itself
402 (default ctf/respawn.wav)
405 void() item_flag_team1 =
409 //if(!cvar("teamplay"))
410 // cvar_set("teamplay", "3");
412 self.team = 5; // color 4 team (red)
413 self.items = IT_KEY2; // gold key (redish enough)
416 self.model = "models/ctf/flag_red.md3";
418 self.noise = "ctf/take.wav";
420 self.noise1 = "ctf/return.wav";
422 self.noise2 = "ctf/capture.wav";
424 self.noise3 = "ctf/respawn.wav";
425 precache_model (self.model);
426 setmodel (self, self.model);
427 precache_sound (self.noise);
428 precache_sound (self.noise1);
429 precache_sound (self.noise2);
430 precache_sound (self.noise3);
431 setsize(self, '-16 -16 -37', '16 16 37');
432 setorigin(self, self.origin + '0 0 37');
433 self.nextthink = time + 0.2; // start after doors etc
434 self.think = place_flag;
438 //if(!self.glow_size)
439 // self.glow_size = 50;
441 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
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.team = 14; // color 13 team (blue)
463 self.items = IT_KEY1; // silver key (bluish enough)
466 self.model = "models/ctf/flag_blue.md3";
468 self.noise = "ctf/take.wav";
470 self.noise1 = "ctf/return.wav";
472 self.noise2 = "ctf/capture.wav";
474 self.noise3 = "ctf/respawn.wav";
475 precache_model (self.model);
476 setmodel (self, self.model);
477 precache_sound (self.noise);
478 precache_sound (self.noise1);
479 precache_sound (self.noise2);
480 precache_sound (self.noise3);
481 setsize(self, '-16 -16 -37', '16 16 37');
482 setorigin(self, self.origin + '0 0 37');
483 self.nextthink = time + 0.2; // start after doors etc
484 self.think = place_flag;
488 //if(!self.glow_size)
489 // self.glow_size = 50;
491 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
495 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
496 Team declaration for CTF gameplay, this allows you to decide what team
497 names and control point models are used in your map.
499 Note: If you use ctf_team entities you must define at least 2! However, unlike
500 domination, you don't need to make a blank one too.
504 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
506 Scoreboard color of the team (for example 4 is red and 13 is blue)
512 self.classname = "ctf_team";
513 self.team = self.cnt + 1;
516 // code from here on is just to support maps that don't have control point and team entities
517 void ctf_spawnteam (string teamname, float teamcolor)
519 local entity oldself;
522 self.classname = "ctf_team";
523 self.netname = teamname;
524 self.cnt = teamcolor;
531 // spawn some default teams if the map is not set up for ctf
532 void() ctf_spawnteams =
536 numteams = 2;//cvar("g_ctf_default_teams");
538 ctf_spawnteam("Red", 4);
539 ctf_spawnteam("Blue", 13);
542 void() ctf_delayedinit =
544 self.think = SUB_Remove;
545 self.nextthink = time;
546 // if no teams are found, spawn defaults
547 if (find(world, classname, "ctf_team") == world)
555 e.think = ctf_delayedinit;
556 e.nextthink = time + 0.1;