6 MUTATOR_HOOKFUNCTION(msnt_Spawn_Score)
8 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint)
13 spawn_spot.msnt_lookat = world;
18 RandomSelection_Init();
19 FOR_EACH_PLAYER(p) if(p != self) if(p.team == self.team) if(!p.deadflag)
21 float l = vlen(spawn_spot.origin - p.origin);
22 if(l > autocvar_g_spawn_near_teammate_distance)
26 if(!checkpvs(spawn_spot.origin, p))
28 RandomSelection_Add(p, 0, string_null, 1, 1);
31 if(RandomSelection_chosen_ent)
33 spawn_spot.msnt_lookat = RandomSelection_chosen_ent;
34 spawn_score_x += SPAWN_PRIO_NEAR_TEAMMATE_FOUND;
36 else if(self.team == spawn_spot.team)
37 spawn_score_x += SPAWN_PRIO_NEAR_TEAMMATE_SAMETEAM; // prefer same team, if we can't find a spawn near teammate
42 MUTATOR_HOOKFUNCTION(msnt_PlayerSpawn)
44 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint)
46 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death)
47 self.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death;
49 entity team_mate, best_mate = world;
50 vector best_spot = '0 0 0';
51 float pc = 0, best_dist = 0, dist = 0;
52 FOR_EACH_PLAYER(team_mate)
54 if((autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health >= 0 && team_mate.health >= autocvar_g_balance_health_regenstable) || autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health == 0)
55 if(team_mate.deadflag == DEAD_NO)
56 if(team_mate.msnt_timer < time)
57 if(!IsDifferentTeam(self, team_mate))
58 if(time > team_mate.spawnshieldtime) // spawn shielding
59 if(team_mate.freezetag_frozen == 0)
62 tracebox(team_mate.origin, PL_MIN, PL_MAX, team_mate.origin - '0 0 100', MOVE_WORLDONLY, team_mate);
63 if(trace_fraction != 1.0)
64 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
66 pc = pointcontents(trace_endpos + '0 0 1');
67 if(pc == CONTENT_EMPTY)
69 if(vlen(team_mate.velocity) > 5)
70 fixedmakevectors(vectoangles(team_mate.velocity));
72 fixedmakevectors(team_mate.angles);
74 for(pc = 0; pc != 5; ++pc) // test 5 diffrent spots close to mate
79 tracebox(team_mate.origin , PL_MIN, PL_MAX, team_mate.origin + v_right * 128, MOVE_NORMAL, team_mate);
82 tracebox(team_mate.origin , PL_MIN, PL_MAX, team_mate.origin - v_right * 128 , MOVE_NORMAL, team_mate);
85 tracebox(team_mate.origin , PL_MIN, PL_MAX, team_mate.origin + v_right * 64 - v_forward * 64, MOVE_NORMAL, team_mate);
88 tracebox(team_mate.origin , PL_MIN, PL_MAX, team_mate.origin - v_right * 64 - v_forward * 64, MOVE_NORMAL, team_mate);
91 tracebox(team_mate.origin , PL_MIN, PL_MAX, team_mate.origin - v_forward * 128, MOVE_NORMAL, team_mate);
95 if(trace_fraction == 1.0)
97 traceline(trace_endpos + '0 0 4', trace_endpos - '0 0 100', MOVE_NORMAL, team_mate);
98 if(trace_fraction != 1.0)
100 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath)
102 dist = vlen(trace_endpos - self.msnt_deathloc);
103 if(dist < best_dist || best_dist == 0)
106 best_spot = trace_endpos;
107 best_mate = team_mate;
112 setorigin(self, trace_endpos);
113 self.angles = team_mate.angles;
114 team_mate.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;
125 if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath)
128 setorigin(self, best_spot);
129 self.angles = best_mate.angles;
130 self.fixangle = TRUE;
131 best_mate.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;
134 else if(spawn_spot.msnt_lookat)
136 self.angles = vectoangles(spawn_spot.msnt_lookat.origin - self.origin);
137 self.angles_x = -self.angles_x;
139 sprint(self, "You should be looking at ", spawn_spot.msnt_lookat.netname, "^7.\n");
140 sprint(self, "distance: ", vtos(spawn_spot.msnt_lookat.origin - self.origin), "\n");
141 sprint(self, "angles: ", vtos(self.angles), "\n");
148 MUTATOR_HOOKFUNCTION(msnt_PlayerDies)
150 self.msnt_deathloc = self.origin;
154 MUTATOR_DEFINITION(mutator_spawn_near_teammate)
156 MUTATOR_HOOK(Spawn_Score, msnt_Spawn_Score, CBC_ORDER_ANY);
157 MUTATOR_HOOK(PlayerSpawn, msnt_PlayerSpawn, CBC_ORDER_ANY);
158 MUTATOR_HOOK(PlayerDies, msnt_PlayerDies, CBC_ORDER_ANY);