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'
13 void FakeTimeLimit(entity e, float t)
16 WriteByte(MSG_ONE, 3); // svc_updatestat
17 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
19 WriteCoord(MSG_ONE, cvar("timelimit"));
21 WriteCoord(MSG_ONE, (t + 1) / 60);
24 float flagcaptimerecord;
25 .float flagpickuptime;
33 self.t_width = 0.1; // frame animation rate
35 self.t_length = 119; // maximum frame
37 setattachment(self, world, "");
38 self.mdl = self.model;
40 self.solid = SOLID_TRIGGER;
41 self.movetype = MOVETYPE_NONE;
42 self.velocity = '0 0 0';
43 self.origin_z = self.origin_z + 6;
44 self.think = FlagThink;
45 self.touch = FlagTouch;
46 self.nextthink = time + 0.1;
48 self.mangle = self.angles;
49 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
50 //self.effects = self.effects | EF_DIMLIGHT;
53 self.movetype = MOVETYPE_TOSS;
56 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
61 self.oldorigin = self.origin;
64 void LogCTF(string mode, float flagteam, entity actor)
67 if(!cvar("sv_eventlog"))
69 s = strcat(":ctf:", mode);
70 s = strcat(s, ":", ftos(flagteam));
72 s = strcat(s, ":", ftos(actor.playerid));
73 GameLogEcho(s, FALSE);
76 void(entity e) RegenFlag =
78 setattachment(e, world, "");
79 e.movetype = MOVETYPE_NONE;
81 e.movetype = MOVETYPE_TOSS;
82 e.solid = SOLID_TRIGGER;
83 // TODO: play a sound here
84 setorigin(e, e.oldorigin);
88 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
91 void(entity e) ReturnFlag =
94 if (e.owner.flagcarried == e)
96 WaypointSprite_DetachCarrier(e.owner);
97 e.owner.flagcarried = world;
100 FakeTimeLimit(e.owner, -1);
106 void(entity e) DropFlag =
118 dprint("FLAG: drop - no owner?!?!\n");
122 if (p.flagcarried != e)
124 dprint("FLAG: drop - owner is not carrying this flag??\n");
127 bprint(p.netname, "^7 lost the ", e.netname, "\n");
128 WaypointSprite_DetachCarrier(p);
129 LogCTF("dropped", p.team, p.flagcarried);
131 setattachment(e, world, "");
133 if (p.flagcarried == e)
134 p.flagcarried = world;
137 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
138 e.solid = SOLID_TRIGGER;
139 e.movetype = MOVETYPE_TOSS;
140 // setsize(e, '-16 -16 0', '16 16 74');
141 setorigin(e, p.origin - '0 0 24' + '0 0 37');
142 e.cnt = FLAG_DROPPED;
143 e.velocity = '0 0 300';
144 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
146 trace_startsolid = FALSE;
147 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
149 dprint("FLAG FALLTHROUGH will happen SOON\n");
154 if(self.delay > time)
156 self.delay = time + self.t_width;
157 if(self.nextthink > self.delay)
158 self.nextthink = self.delay;
160 self.frame = self.frame + 1;
161 if(self.frame > self.t_length)
169 self.nextthink = time + 0.1;
173 if(self.speedrunning)
174 if(self.cnt == FLAG_CARRY)
177 if(flagcaptimerecord)
178 if(time >= self.flagpickuptime + flagcaptimerecord)
180 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
182 self.owner.impulse = 77; // returning!
192 if (self.cnt == FLAG_BASE)
195 if (self.cnt == FLAG_DROPPED)
197 // flag fallthrough? FIXME remove this if bug is really fixed now
198 if(self.origin_z < -131072)
200 dprint("FLAG FALLTHROUGH just happened\n");
201 self.pain_finished = 0;
203 setattachment(self, world, "");
204 if (time > self.pain_finished)
206 bprint("The ", self.netname, " has returned to base\n");
207 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
208 LogCTF("returned", self.team, world);
215 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
217 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
230 local string s, s0, h0, h1;
231 if (other.classname != "player")
233 if (other.health < 1) // ignore dead players
236 if (self.cnt == FLAG_CARRY)
239 if (self.cnt == FLAG_BASE)
240 if (other.team == self.team)
241 if (other.flagcarried) // he's got a flag
242 if (other.flagcarried.team != self.team) // capture
244 if (other.flagcarried == world)
248 t = time - other.flagcarried.flagpickuptime;
249 s = ftos_decimals(t, 2);
250 s0 = ftos_decimals(flagcaptimerecord, 2);
251 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
252 h1 = strreplace(other.netname, "\\", "\xDC"); // h1: current netname, escaped for DB (\ is 5C, other \ is DC)
256 h0 = strcat(strreplace(h0, "\xDC", "\\"), "^7's"); // h0: display text for previous netname
257 if (flagcaptimerecord == 0)
259 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
260 flagcaptimerecord = t;
261 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
262 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
264 else if (t < flagcaptimerecord)
266 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
267 flagcaptimerecord = t;
268 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
269 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
273 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
276 LogCTF("capture", other.flagcarried.team, other);
277 // give credit to the individual player
278 UpdateFrags(other, cvar("g_ctf_flagscore_capture"));
280 // give credit to all players of the team (rewards large teams)
281 // NOTE: this defaults to 0
282 FOR_EACH_PLAYER(head)
283 if (head.team == self.team)
284 UpdateFrags(head, cvar("g_ctf_flagscore_capture_team"));
286 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
287 WaypointSprite_DetachCarrier(other);
288 if(self.speedrunning)
289 FakeTimeLimit(other, -1);
290 RegenFlag (other.flagcarried);
291 other.flagcarried = world;
292 other.next_take_time = time + 1;
294 if (self.cnt == FLAG_BASE)
295 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
296 if (other.team != self.team)
297 if (!other.flagcarried)
299 if (other.next_take_time > time)
302 self.flagpickuptime = time; // used for timing runs
303 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
304 if(other.speedrunning)
305 if(flagcaptimerecord)
306 FakeTimeLimit(other, time + flagcaptimerecord);
307 self.solid = SOLID_NOT;
308 setorigin(self, self.origin); // relink
310 other.flagcarried = self;
311 self.cnt = FLAG_CARRY;
312 self.angles = '0 0 0';
313 bprint(other.netname, "^7 got the ", self.netname, "\n");
314 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
315 LogCTF("steal", self.team, other);
316 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
318 FOR_EACH_PLAYER(player)
319 if(player.team == self.team)
320 centerprint(player, "The enemy got your flag! Retrieve it!");
322 self.movetype = MOVETYPE_NONE;
323 setorigin(self, FLAG_CARRY_POS);
324 setattachment(self, other, "");
325 WaypointSprite_AttachCarrier("flagcarrier", other);
330 if (self.cnt == FLAG_DROPPED)
332 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
333 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
336 bprint(other.netname, "^7 returned the ", self.netname, "\n");
337 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
338 UpdateFrags(other, cvar("g_ctf_flagscore_return"));
340 UpdateFrags(other, cvar("g_ctf_flagscore_return_rogue"));
341 LogCTF("return", self.team, other);
342 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
345 else if (!other.flagcarried)
348 self.solid = SOLID_NOT;
349 setorigin(self, self.origin); // relink
351 other.flagcarried = self;
352 self.cnt = FLAG_CARRY;
353 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
354 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
355 LogCTF("pickup", self.team, other);
356 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
358 FOR_EACH_PLAYER(player)
359 if(player.team == self.team)
360 centerprint(player, "The enemy got your flag! Retrieve it!");
362 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
363 setorigin(self, FLAG_CARRY_POS);
364 setattachment(self, other, "");
365 WaypointSprite_AttachCarrier("flagcarrier", other);
370 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
371 CTF Starting point for a player
376 viewing angle when spawning
378 void() info_player_team1 =
380 self.team = COLOR_TEAM1; // red
381 info_player_deathmatch();
383 //self.team = 4;self.classname = "info_player_start";info_player_start();};
385 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
386 CTF Starting point for a player in
391 viewing angle when spawning
393 void() info_player_team2 =
395 self.team = COLOR_TEAM2; // blue
396 info_player_deathmatch();
398 //self.team = 13;self.classname = "info_player_start";info_player_start();};
400 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
401 CTF Starting point for a player in
402 team three (Magenta).
406 viewing angle when spawning
408 void() info_player_team3 =
410 self.team = COLOR_TEAM3; // purple
411 info_player_deathmatch();
415 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
416 CTF Starting point for a player in
421 viewing angle when spawning
423 void() info_player_team4 =
425 self.team = COLOR_TEAM4; // yellow
426 info_player_deathmatch();
432 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
433 CTF flag for team one (Red).
434 Multiple are allowed.
438 Angle the flag will point
441 model to use, note this needs red and blue as skins 0 and 1
442 (default models/ctf/flag.md3)
444 sound played when flag is picked up
445 (default ctf/take.wav)
447 sound played when flag is returned by a teammate
448 (default ctf/return.wav)
450 sound played when flag is captured
451 (default ctf/capture.wav)
453 sound played when flag is lost in the field and respawns itself
454 (default ctf/respawn.wav)
457 void() item_flag_team1 =
461 //if(!cvar("teamplay"))
462 // cvar_set("teamplay", "3");
464 self.classname = "item_flag_team1";
465 self.team = COLOR_TEAM1; // color 4 team (red)
466 self.items = IT_KEY2; // gold key (redish enough)
467 self.netname = "^1RED^7 flag";
468 self.target = "###item###";
470 if(self.spawnflags & 1)
473 self.model = "models/ctf/flag_red.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("redbase", self.origin + '0 0 37', self, enemy);
505 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
506 CTF flag for team two (Blue).
507 Multiple are allowed.
511 Angle the flag will point
516 void() item_flag_team2 =
520 //if(!cvar("teamplay"))
521 // cvar_set("teamplay", "3");
523 self.classname = "item_flag_team2";
524 self.team = COLOR_TEAM2; // color 13 team (blue)
525 self.items = IT_KEY1; // silver key (bluish enough)
526 self.netname = "^4BLUE^7 flag";
527 self.target = "###item###";
529 if(self.spawnflags & 1)
532 self.model = "models/ctf/flag_blue.md3";
534 self.noise = "ctf/take.wav";
536 self.noise1 = "ctf/return.wav";
538 self.noise2 = "ctf/capture.wav";
540 self.noise3 = "ctf/respawn.wav";
541 precache_model (self.model);
542 setmodel (self, self.model); // precision set below
543 precache_sound (self.noise);
544 precache_sound (self.noise1);
545 precache_sound (self.noise2);
546 precache_sound (self.noise3);
547 setsize(self, '-16 -16 -37', '16 16 37');
548 setorigin(self, self.origin + '0 0 37');
549 self.nextthink = time + 0.2; // start after doors etc
550 self.think = place_flag;
554 //if(!self.glow_size)
555 // self.glow_size = 50;
557 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
561 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, enemy);
565 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
566 Team declaration for CTF gameplay, this allows you to decide what team
567 names and control point models are used in your map.
569 Note: If you use ctf_team entities you must define at least 2! However, unlike
570 domination, you don't need to make a blank one too.
574 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
576 Scoreboard color of the team (for example 4 is red and 13 is blue)
582 self.classname = "ctf_team";
583 self.team = self.cnt + 1;
586 // code from here on is just to support maps that don't have control point and team entities
587 void ctf_spawnteam (string teamname, float teamcolor)
589 local entity oldself;
592 self.classname = "ctf_team";
593 self.netname = teamname;
594 self.cnt = teamcolor;
601 // spawn some default teams if the map is not set up for ctf
602 void() ctf_spawnteams =
606 numteams = 2;//cvar("g_ctf_default_teams");
608 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
609 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
612 void() ctf_delayedinit =
614 self.think = SUB_Remove;
615 self.nextthink = time;
616 // if no teams are found, spawn defaults
617 if (find(world, classname, "ctf_team") == world)
625 e.think = ctf_delayedinit;
626 e.nextthink = time + 0.1;
627 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
630 void(entity flag) ctf_setstatus2 =
634 if (flag.team == COLOR_TEAM1) shift = IT_RED_FLAG_TAKEN;
635 else if (flag.team == COLOR_TEAM2) shift = IT_BLUE_FLAG_TAKEN;
639 if (flag.cnt == FLAG_CARRY)
640 if (flag.owner == self) status = 3;
642 else if (flag.cnt == FLAG_DROPPED) status = 2;
645 self.items = self.items | (shift * status);
649 void() ctf_setstatus =
651 self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
652 self.items = self.items - (self.items & IT_RED_FLAG_LOST);
653 self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
654 self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
658 flag = find(world, classname, "item_flag_team1");
659 ctf_setstatus2(flag);
660 flag = find(world, classname, "item_flag_team2");
661 ctf_setstatus2(flag);