set g_spawn_near_teammate 0 "if set, players prefer spawns near a team mate"
set g_spawn_near_teammate_distance 640 "max distance to consider a spawn to be near a team mate"
set g_spawn_near_teammate_ignore_spawnpoint 0 "ignore spawnpoints and spawn right at team mates, if 2, clients can ignore this option"
+set g_spawn_near_teammate_ignore_spawnpoint_max 10 "if set, test at most this many of the available teammates"
set g_spawn_near_teammate_ignore_spawnpoint_delay 2.5 "how long to wait before its OK to spawn at a player after someone just spawned at this player"
set g_spawn_near_teammate_ignore_spawnpoint_delay_death 3 "how long to wait before its OK to spawn at a player after death"
set g_spawn_near_teammate_ignore_spawnpoint_check_health 1 "only allow spawn at this player if their health is full"
float autocvar_g_spawn_near_teammate_distance;
int autocvar_g_spawn_near_teammate_ignore_spawnpoint;
+int autocvar_g_spawn_near_teammate_ignore_spawnpoint_max;
float autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;
float autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death;
bool autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health;
entity best_mate = NULL;
vector best_pos = '0 0 0';
float best_dist2 = FLOAT_MAX;
+ int tested = 0;
FOREACH_CLIENT_RANDOM(IS_PLAYER(it), LAMBDA(
+ if (autocvar_g_spawn_near_teammate_ignore_spawnpoint_max && tested >= autocvar_g_spawn_near_teammate_ignore_spawnpoint_max) break;
if (!SAME_TEAM(player, it)) continue;
if (autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health && it.health < autocvar_g_balance_health_regenstable) continue;
if (IS_DEAD(it)) continue;
if (forbidWeaponUse(it)) continue;
if (it == player) continue;
+ tested++; // i consider a teammate to be available when he passes the checks above
+
vector horiz_vel = vec2(it.velocity);
// when walking slowly sideways, we assume the player wants a clear shot ahead - spawn behind him according to where he's looking
// when running fast, spawn behind him according to his direction of movement to prevent colliding with the newly spawned player