#include < amxmodx > 

#include < zombieplague > 

#define PLUGIN  "[ZP] Addon: Survivor" 
#define VERSION "1.0" 
#define AUTHOR  "Weltgericht" 

#define MAXPLAYERS 32 

public plugin_init() 
{ 
    register_plugin(PLUGIN, VERSION, AUTHOR) 
} 

public zp_round_started(gamemode) 
{ 
    new Players = fnGetAlivePlayers() 
     
    if (Players < 2) 
        return PLUGIN_CONTINUE 
     
    if(gamemode == MODE_INFECTION || gamemode == MODE_MULTI) 
    { 
        new player = fnGetRandomAlive(random_num(1, Players)) 
         
        zp_make_user_survivor(player) 
    } 
    return PLUGIN_CONTINUE 
} 

fnGetRandomAlive(n) 
{ 
    static iAlive, id 
    iAlive = 0 
     
    for (id = 1; id <= MAXPLAYERS; id++) 
    { 
        if (is_user_alive(id)) 
            iAlive++ 
         
        if (iAlive == n) 
            return id; 
    } 
     
    return -1; 
} 

fnGetAlivePlayers() 
{ 
    new number = 0 

    for(new id = 1; id <= MAXPLAYERS; id++) 
    { 
        if(is_user_alive(id) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id)) 
                number++ 
    } 

    return number 

} 