derpderp()
{
a = getCvar("g_gametype");
teambased = false;
if(a == "tdm" || a == "sd" || a == "zom" || a == "ctf" || a == "codjumper" || a == "bel")
teambased = true;
// var for setting the radius in which it counts the people around a spawnpoint: default = 750
radius = 750;
// var to deal with spawnpoints that get assigned the same score: default = 1
safetyfirst = 1;
// var to defined the maximum amount of people that can be in the radius for the spawn to be used: default = 99
maxpeopleinradius = 99;
// var to defined if you only want to get teleported to a spawnpoint with no one around it: default = 0
// safetyfirst needs to be on for this to work
absolutesafety = 0;
//#####----------##########----------#####//
// set up arrays
//#####----------##########----------#####//
players = getentarray("player","classname");
if(!teambased)
spawnpoints = getentarray("mp_dm_spawn", "classname");
else
{
spawnpoints = getentarray("mp_tdm_spawn", "classname");
if(!isDefined(spawnpoints))
spawnpoints = getentarray("mp_sd_spawn", "classname");
if(!isDefined(spawnpoints))
spawnpoints = getentarray("mp_ctf_spawn", "classname");
}
if(!isDefined(players) || !isDefined(spawnpoints))
return;
enemies = [];
for(a=0;a<players.size;a++)
if(isDefined(players[a].team) && players[a].team != "spectator" && self.team != players[a].team)
enemies[enemies.size] = players[a];
for(a=0;a<spawnpoints.size;a++)
spawnpoints[a].inarray = false;
//#####----------##########----------#####//
// build list with all spawnpoints -- highest rated (biggest distance) gets first spot in array ([0])
//#####----------##########----------#####//
dist = [];
for(a=0;a<spawnpoints.size;a++)
{
furthest = undefined;
for(b=0;b<spawnpoints.size;b++)
{
if(spawnpoints[b].inarray)
continue;
if(!isDefined(furthest))
furthest = self;
if(distancesquared(spawnpoints[b].origin, self.origin) > distancesquared(furthest.origin, self.origin))
furthest = spawnpoints[b];
}
num = dist.size;
dist[num] = spawnstruct();
dist[num].orig = furthest.origin;
furthest.inarray = true;
}
// debugging - prints array with distance
// for(a=0;a<dist.size;a++)
// {
// wait .25;
// iprintlnbold("dist[" + a + "] == " + distance(self.origin, dist[a].orig));
// }
//#####----------##########----------#####//
// list number of enemies around each spawnpoint
//#####----------##########----------#####//
if(teambased)
people = enemies; // people refers to the enemies array
else
people = players; // players refers to everyone
for(a=0;a<dist.size;a++)
{
dist[a].peopleinradius = 0;
for(b=0;b<people.size;b++)
if(people[b] == self)
continue;
else if(distancesquared(dist[a].orig, enemies[b]) < radius * radius)
dist[a].peopleinradius++;
}
if(maxpeopleinradius != 99)
{
temparray = [];
for(a=0;a<dist.size;a++)
if(dist[a].peopleinradius < maxpeopleinradius)
{
num = temparray.size;
temparray[num] = spawnstruct();
temparray[num].orig = dist[a].orig;
temparray[num].peopleinradius = dist[a].peopleinradius;
}
if(temparray.size == 0)
return;
dist = temparray;
}
//#####----------##########----------#####//
// give all spawnpoints a certain score according to the distance from self and the people around it
// lower score means better
// if multiple spawnpoints have the same score:
// -take spawnpoint furthest away (var: safetyfirst = 0)
// -take spawnpoint with least a mount of players (var: safetyfirst = 1 (default)
//#####----------##########----------#####//
safest = [];
for(a=0;a<dist.size;a++)
dist[a].score = a + dist[a].peopleinradius;
for(a=0;a<dist.size;a++)
if(!isDefined(bestscore))
bestscore = dist[a];
else if(dist[a].score < bestscore.score)
bestscore = dist[a];
safest[0] = spawnstruct();
safest[0].orig = bestscore.orig;
safest[0].peopleinradius = bestscore.peopleinradius;
safest[0].score = bestscore.score;
for(a=0;a<dist.size;a++)
if(dist[a].score == safest[0].score && safest[0].orig != dist[a].orig)
{
num = safest.size;
safest[num] = spawnstruct();
safest[num].orig = dist[a].orig;
safest[num].peopleinradius = dist[a].peopleinradius;
}
if(safetyfirst)
{
for(a=0;a<safest.size;a++)
if(!isDefined(bestspawn))
bestspawn = safest[a];
else if(safest[a].peopleinradius < bestspawn.peopleinradius)
bestspawn = safest[a];
if(absolutesafety && bestspawn.peopleinradius != 0)
{
self iprintln("There are people near your teleport location");
self iprintln("Press melee if you still want to teleport");
wait .5;
time = 0;
first = true;
second = true;
iprintln("^33.");
while(time <= 3)
{
wait .05;
time += .05;
if(time > 1 && first)
{
iprintln("^22.");
first = false;
}
if(time > 2 && second)
{
iprintln("^11.");
second = false;
}
if(self meleebuttonpressed())
break;
}
if(time >= 3)
{
iprintln("You did not teleport.");
return;
}
}
//----- check if spawnpoints have the same people in radius.
// if yes -> build new 'safest' array and decide by distance
temparray = undefined;
temparray = [];
temparray[0] = spawnstruct();
temparray[0].orig = bestspawn.orig;
temparray[0].peopleinradius = bestspawn.peopleinradius;
for(a=0;a<safest.size;a++)
if(safest[a].orig == temparray[0].orig)
continue;
else if(safest[a].peopleinradius == temparray[0].peopleinradius)
{
num = temparray.size;
temparray[num] = spawnstruct();
temparray[num].orig = safest[a].orig;
}
if(temparray.size > 1)
{
safetyfirst = false;
safest = temparray;
}
}
if(!safetyfirst)
{
for(a=0;a<safest.size;a++)
if(!isDefined(bestspawn))
bestspawn = safest[a];
else if(distancesquared(self.origin, safest[a].orig) > distancesquared(self.origin, bestspawn.orig))
bestspawn = safest[a];
}
spawnpoint = bestspawn.orig;
self setOrigin(spawnpoint);
}