3 float autocvar_g_spawn_near_teammate_distance;
4 int autocvar_g_spawn_near_teammate_ignore_spawnpoint;
5 float autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;
6 float autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death;
7 int autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health;
8 bool autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath;
10 REGISTER_MUTATOR(spawn_near_teammate, cvar("g_spawn_near_teammate"));
15 .vector msnt_deathloc;
17 .float cvar_cl_spawn_near_teammate;
19 MUTATOR_HOOKFUNCTION(spawn_near_teammate, Spawn_Score)
21 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint == 1 || (autocvar_g_spawn_near_teammate_ignore_spawnpoint == 2 && self.cvar_cl_spawn_near_teammate))
24 spawn_spot.msnt_lookat = world;
29 RandomSelection_Init();
30 FOREACH_CLIENT(IS_PLAYER(it) && it != self && SAME_TEAM(it, self) && !IS_DEAD(it), LAMBDA(
31 if(vdist(spawn_spot.origin - it.origin, >, autocvar_g_spawn_near_teammate_distance))
33 if(vdist(spawn_spot.origin - it.origin, <, 48))
35 if(!checkpvs(spawn_spot.origin, it))
37 RandomSelection_Add(it, 0, string_null, 1, 1);
40 if(RandomSelection_chosen_ent)
42 spawn_spot.msnt_lookat = RandomSelection_chosen_ent;
43 spawn_score.x += SPAWN_PRIO_NEAR_TEAMMATE_FOUND;
45 else if(self.team == spawn_spot.team)
46 spawn_score.x += SPAWN_PRIO_NEAR_TEAMMATE_SAMETEAM; // prefer same team, if we can't find a spawn near teammate
51 MUTATOR_HOOKFUNCTION(spawn_near_teammate, PlayerSpawn)
53 if(!teamplay) { return false; }
55 int num_red = 0, num_blue = 0, num_yellow = 0, num_pink = 0;
56 FOREACH_CLIENT(IS_PLAYER(it),
60 case NUM_TEAM_1: ++num_red; break;
61 case NUM_TEAM_2: ++num_blue; break;
62 case NUM_TEAM_3: ++num_yellow; break;
63 case NUM_TEAM_4: ++num_pink; break;
67 if(num_red == 1 || num_blue == 1 || num_yellow == 1 || num_pink == 1)
68 return false; // at least 1 team has only 1 player, let's not give the bigger team too much of an advantage!
70 // Note: when entering this, fixangle is already set.
71 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint == 1 || (autocvar_g_spawn_near_teammate_ignore_spawnpoint == 2 && self.cvar_cl_spawn_near_teammate))
73 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death)
74 self.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death;
76 entity best_mate = world;
77 vector best_spot = '0 0 0';
78 float pc = 0, best_dist = 0, dist = 0;
79 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
80 if((autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health >= 0 && it.health >= autocvar_g_balance_health_regenstable) || autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health == 0)
82 if(it.msnt_timer < time)
83 if(SAME_TEAM(self, it))
84 if(time > it.spawnshieldtime) // spawn shielding
85 if(STAT(FROZEN, it) == 0)
88 tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - '0 0 100', MOVE_NOMONSTERS, it);
89 if(trace_fraction != 1.0)
90 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
92 pc = pointcontents(trace_endpos + '0 0 1');
93 if(pc == CONTENT_EMPTY)
95 if(vdist(it.velocity, >, 5))
96 fixedmakevectors(vectoangles(it.velocity));
98 fixedmakevectors(it.angles);
100 for(pc = 0; pc < 4; ++pc) // test 4 diffrent spots close to mate
105 tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin + v_right * 128, MOVE_NOMONSTERS, it);
108 tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_right * 128 , MOVE_NOMONSTERS, it);
111 tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin + v_right * 128 - v_forward * 64, MOVE_NOMONSTERS, it);
114 tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_right * 128 - v_forward * 64, MOVE_NOMONSTERS, it);
117 //tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_forward * 128, MOVE_NOMONSTERS, it);
121 if(trace_fraction == 1.0)
123 traceline(trace_endpos + '0 0 4', trace_endpos - '0 0 100', MOVE_NOMONSTERS, it);
124 if(trace_fraction != 1.0)
126 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath)
128 dist = vlen(trace_endpos - self.msnt_deathloc);
129 if(dist < best_dist || best_dist == 0)
132 best_spot = trace_endpos;
138 setorigin(self, trace_endpos);
139 self.angles = it.angles;
140 self.angles_z = 0; // never spawn tilted even if the spot says to
141 it.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;
152 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath)
155 setorigin(self, best_spot);
156 self.angles = best_mate.angles;
157 self.angles_z = 0; // never spawn tilted even if the spot says to
158 best_mate.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;
161 else if(spawn_spot.msnt_lookat)
163 self.angles = vectoangles(spawn_spot.msnt_lookat.origin - self.origin);
164 self.angles_x = -self.angles.x;
165 self.angles_z = 0; // never spawn tilted even if the spot says to
167 sprint(self, "You should be looking at ", spawn_spot.msnt_lookat.netname, "^7.\n");
168 sprint(self, "distance: ", vtos(spawn_spot.msnt_lookat.origin - self.origin), "\n");
169 sprint(self, "angles: ", vtos(self.angles), "\n");
176 MUTATOR_HOOKFUNCTION(spawn_near_teammate, PlayerDies)
178 frag_target.msnt_deathloc = frag_target.origin;
182 REPLICATE(cvar_cl_spawn_near_teammate, bool, "cl_spawn_near_teammate");