View Single Post
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 01-18-2019 , 13:24   Re: Sorting spawning points
Reply With Quote #3

Well, I made my version of it.
If you can show me a better way, I'm open for it!

PHP Code:
// [Team] Spawns
//                Group all spawns for each team
team_spawns()
{
    
// Get the positions of all spawn-spots
    
new Float:spawn_origins[ (GAME_TEAMPLAYERS GAME_TEAMS)+][3],
        
spawn_entity,
        
spawn_index

    
while( (spawn_entity find_ent_by_class(spawn_entity"info_player_deathmatch")) )
    {
        
pev(spawn_entitypev_originspawn_origins[spawn_index])
        
spawn_origins[spawn_index][2] -= 30.0
        spawn_index 
+= 1
    
}

    
log_amx("[CRASH BALL-DEBUG] Found %i spawningpoints (%.2f %.2f)"spawn_indexspawn_origins[0][0], spawn_origins[0][1])

    
// Sort all the spawns by x & y
    
new Float:sorted_x[ (GAME_TEAMPLAYERS GAME_TEAMS)+][3],
        
Float:sorted_y[ (GAME_TEAMPLAYERS GAME_TEAMS)+][3],
        
swap_typeswap_index

    
//xs_vec_copy(spawn_origins[0], sorted_x[0])
    //xs_vec_copy(spawn_origins[0], sorted_y[0])

    
for(new 0spawn_indexi++)
    {
        
swap_type 0
        swap_index 
i
        xs_vec_copy
(spawn_origins[i], sorted_x[i])
        
xs_vec_copy(spawn_origins[i], sorted_y[i])

        if(!
i)
            continue

        
reswap:

        if(
sorted_x[i-1][0] > sorted_x[i][0])
        {
            
swap_origin_position(sorted_x[i-1], sorted_x[i])
            
swap_type 1
        
}
        if(
sorted_y[i-1][1] > sorted_y[i][1])
        {
            
swap_origin_position(sorted_y[i-1], sorted_y[i])
            
swap_type 1
        
}

        
// If swaped, check if it can go even lower..
        
if(swap_type 0
            
&& 1)
        {
            
swap_type = -1
            i 
-= 1
            
goto reswap
        
}
        
// If swaped all it could
        
if(swap_type == -1
            
|| <= 1)
        {
            
swap_index
        
}
    }

    
// Now we have a list sorted by x and y
    
spawn_index -= 1
    
for(new 0GAME_TEAMPLAYERSi++)
    {
        
// #Team 1
        
xs_vec_copy(sorted_x[i], g_team_spawns[0][i])

        
// #Team 2
        
xs_vec_copy(sorted_x[ (spawn_index i) ], g_team_spawns[1][i])

        
// #Team 3
        
xs_vec_copy(sorted_y[i], g_team_spawns[2][i])

        
// #Team 4
        
xs_vec_copy(sorted_y[ (spawn_index i) ], g_team_spawns[3][i])
    }

__________________
Retired.
Xalus is offline