// IW6 GSC SOURCE
// Generated by https://github.com/xensik/gsc-tool

player_healthbar_update()
{
    self endon( "death" );
    waittillframeend;

    for (;;)
    {
        var_0 = self.health / self.maxhealth;
        setdvar( "alien_player_health", self.health / self.maxhealth );

        while ( var_0 == self.health / self.maxhealth )
            wait 0.1;
    }
}

enable_alien_scripted()
{
    self.alien_scripted = 1;
    self notify( "alien_main_loop_restart" );
}

disable_alien_scripted()
{
    self.alien_scripted = 0;
}

set_alien_emissive( var_0, var_1 )
{
    var_2 = self.maxemissive - self.defaultemissive;
    var_3 = var_1 * var_2 + self.defaultemissive;
    self emissiveblend( var_0, var_3 );
}

set_alien_emissive_default( var_0 )
{
    self emissiveblend( var_0, self.defaultemissive );
}

get_players()
{
    return level.players;
}

any_player_nearby( var_0, var_1 )
{
    foreach ( var_3 in level.players )
    {
        if ( distancesquared( var_3.origin, var_0 ) < var_1 )
            return 1;
    }

    return 0;
}

min_dist_from_all_locations( var_0, var_1, var_2 )
{
    var_3 = var_2 * var_2;

    foreach ( var_5 in var_1 )
    {
        if ( distance2dsquared( var_0.origin, var_5.origin ) < var_3 )
            return 0;
    }

    return 1;
}

set_vision_set_player( var_0, var_1 )
{
    if ( init_vision_set( var_0 ) )
        return;

    if ( !isdefined( var_1 ) )
        var_1 = 1;

    self visionsetnakedforplayer( var_0, var_1 );
}

init_vision_set( var_0 )
{
    level.lvl_visionset = var_0;

    if ( !isdefined( level.vision_cheat_enabled ) )
        level.vision_cheat_enabled = 0;

    return level.vision_cheat_enabled;
}

restore_client_fog( var_0 )
{
    if ( !isdefined( level.restore_fog_setting ) )
        return;

    var_1 = level.restore_fog_setting;
    self playersetexpfog( var_1.startdist, var_1.halfwaydist, var_1.red, var_1.green, var_1.blue, var_1.hdrcolorintensity, var_1.maxopacity, var_0, var_1.sunred, var_1.sungreen, var_1.sunblue, var_1.hdrsuncolorintensity, var_1.sundir, var_1.sunbeginfadeangle, var_1.sunendfadeangle, var_1.normalfogscale, var_1.skyfogintensity, var_1.skyfogminangle, var_1.skyfogmaxangle );
}

ent_flag_wait( var_0 )
{
    if ( isplayer( self ) )
        self endon( "disconnect" );

    while ( isdefined( self ) && !self.ent_flag[var_0] )
        self waittill( var_0 );
}

ent_flag_wait_either( var_0, var_1 )
{
    if ( isplayer( self ) )
        self endon( "disconnect" );

    while ( isdefined( self ) )
    {
        if ( ent_flag( var_0 ) )
            return;

        if ( ent_flag( var_1 ) )
            return;

        common_scripts\utility::waittill_either( var_0, var_1 );
    }
}

ent_flag_wait_or_timeout( var_0, var_1 )
{
    if ( isplayer( self ) )
        self endon( "disconnect" );

    var_2 = gettime();

    while ( isdefined( self ) )
    {
        if ( self.ent_flag[var_0] )
            break;

        if ( gettime() >= var_2 + var_1 * 1000 )
            break;

        ent_wait_for_flag_or_time_elapses( var_0, var_1 );
    }
}

ent_wait_for_flag_or_time_elapses( var_0, var_1 )
{
    self endon( var_0 );
    wait( var_1 );
}

ent_flag_waitopen( var_0 )
{
    while ( isdefined( self ) && self.ent_flag[var_0] )
        self waittill( var_0 );
}

ent_flag_assert( var_0 )
{

}

ent_flag_waitopen_either( var_0, var_1 )
{
    while ( isdefined( self ) )
    {
        if ( !ent_flag( var_0 ) )
            return;

        if ( !ent_flag( var_1 ) )
            return;

        common_scripts\utility::waittill_either( var_0, var_1 );
    }
}

ent_flag_init( var_0 )
{
    if ( !isdefined( self.ent_flag ) )
    {
        self.ent_flag = [];
        self.ent_flags_lock = [];
    }

    self.ent_flag[var_0] = 0;
}

ent_flag_exist( var_0 )
{
    if ( isdefined( self.ent_flag ) && isdefined( self.ent_flag[var_0] ) )
        return 1;

    return 0;
}

ent_flag_set( var_0 )
{
    self.ent_flag[var_0] = 1;
    self notify( var_0 );
}

ent_flag_clear( var_0, var_1 )
{
    if ( self.ent_flag[var_0] )
    {
        self.ent_flag[var_0] = 0;
        self notify( var_0 );
    }

    if ( isdefined( var_1 ) && var_1 )
        self.ent_flag[var_0] = undefined;
}

ent_flag( var_0 )
{
    return self.ent_flag[var_0];
}

alien_mode_has( var_0 )
{
    var_0 = tolower( var_0 );

    if ( !isdefined( level.alien_mode_feature ) )
        return 0;

    if ( !isdefined( level.alien_mode_feature[var_0] ) )
        return 0;

    return level.alien_mode_feature[var_0];
}

alien_mode_enable( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9 )
{
    if ( !isdefined( level.alien_mode_feature ) )
        level.alien_mode_feature = [];

    if ( !isdefined( level.alien_mode_feature_strings ) )
        level.alien_mode_feature_strings = [ "kill_resource", "nogame", "airdrop", "loot", "wave", "lurker", "collectible", "mist", "pillage", "challenge", "outline", "scenes" ];

    if ( var_0 == "all" )
    {
        foreach ( var_11 in level.alien_mode_feature_strings )
            alien_mode_enable_raw( var_11 );

        return;
    }

    var_13 = [];

    if ( isdefined( var_0 ) )
        var_13[var_13.size] = tolower( var_0 );

    if ( isdefined( var_1 ) )
        var_13[var_13.size] = tolower( var_1 );

    if ( isdefined( var_2 ) )
        var_13[var_13.size] = tolower( var_2 );

    if ( isdefined( var_3 ) )
        var_13[var_13.size] = tolower( var_3 );

    if ( isdefined( var_4 ) )
        var_13[var_13.size] = tolower( var_4 );

    if ( isdefined( var_5 ) )
        var_13[var_13.size] = tolower( var_5 );

    if ( isdefined( var_6 ) )
        var_13[var_13.size] = tolower( var_6 );

    if ( isdefined( var_7 ) )
        var_13[var_13.size] = tolower( var_7 );

    if ( isdefined( var_8 ) )
        var_13[var_13.size] = tolower( var_8 );

    if ( isdefined( var_9 ) )
        var_13[var_13.size] = tolower( var_9 );

    check_feature_dependencies( var_13 );

    foreach ( var_11 in var_13 )
        alien_mode_enable_raw( var_11 );
}

check_feature_dependencies( var_0 )
{
    foreach ( var_2 in var_0 )
    {
        if ( var_2 == "loot" && !common_scripts\utility::array_contains( var_0, "collectible" ) )
        {

        }

        if ( var_2 == "airdrop" && !common_scripts\utility::array_contains( var_0, "wave" ) )
        {

        }

        if ( var_2 == "lurker" && !common_scripts\utility::array_contains( var_0, "wave" ) )
        {

        }

        if ( var_2 == "mist" && !common_scripts\utility::array_contains( var_0, "wave" ) )
        {

        }
    }
}

alien_mode_enable_raw( var_0 )
{
    if ( !common_scripts\utility::array_contains( level.alien_mode_feature_strings, var_0 ) )
    {
        var_1 = "";

        foreach ( var_3 in level.alien_mode_feature_strings )
            var_1 = var_1 + var_3 + " ";
    }

    level.alien_mode_feature[var_0] = 1;
}

alien_area_init( var_0 )
{
    level.world_areas = [];
    level.area_array = var_0;
    level.current_area_index = 0;

    foreach ( var_2 in var_0 )
    {
        var_3 = getent( var_2, "targetname" );
        level.world_areas[var_2] = var_3;
    }
}

get_current_area_name()
{
    return level.area_array[level.current_area_index];
}

inc_current_area_index()
{
    level.current_area_index++;
}

store_weapons_status( var_0 )
{
    self.copy_fullweaponlist = self getweaponslistall();
    self.copy_weapon_current = self getcurrentweapon();

    foreach ( var_2 in self.copy_fullweaponlist )
    {
        self.copy_weapon_ammo_clip[var_2] = self getweaponammoclip( var_2 );
        self.copy_weapon_ammo_stock[var_2] = self getweaponammostock( var_2 );
    }

    if ( isdefined( var_0 ) )
    {
        var_4 = [];

        foreach ( var_2 in self.copy_fullweaponlist )
        {
            var_6 = 0;

            foreach ( var_8 in var_0 )
            {
                if ( var_2 == var_8 )
                {
                    var_6 = 1;
                    break;
                }
            }

            if ( var_6 )
                continue;

            var_4[var_4.size] = var_2;
        }

        self.copy_fullweaponlist = var_4;

        foreach ( var_8 in var_0 )
        {
            if ( self.copy_weapon_current == var_8 )
            {
                self.copy_weapon_current = "none";
                break;
            }
        }
    }
}

restore_weapons_status( var_0 )
{
    if ( !isdefined( self.copy_fullweaponlist ) || !isdefined( self.copy_weapon_current ) || !isdefined( self.copy_weapon_ammo_clip ) || !isdefined( self.copy_weapon_ammo_stock ) )
    {

    }

    var_1 = self getweaponslistall();

    foreach ( var_3 in var_1 )
    {
        if ( !common_scripts\utility::array_contains( self.copy_fullweaponlist, var_3 ) && !in_inclusion_list( var_0, var_3 ) )
            self takeweapon( var_3 );
    }

    foreach ( var_3 in self.copy_fullweaponlist )
    {
        if ( !self hasweapon( var_3 ) )
            self giveweapon( var_3 );

        self setweaponammoclip( var_3, self.copy_weapon_ammo_clip[var_3] );
        self setweaponammostock( var_3, self.copy_weapon_ammo_stock[var_3] );
    }

    var_7 = self.copy_weapon_current;

    if ( !isdefined( var_7 ) || var_7 == "none" )
        var_7 = self.copy_fullweaponlist[0];

    self switchtoweapon( var_7 );
    self.copy_fullweaponlist = undefined;
    self.copy_weapon_current = undefined;
    self.copy_weapon_ammo_clip = undefined;
    self.copy_weapon_ammo_stock = undefined;
}

in_inclusion_list( var_0, var_1 )
{
    if ( !isdefined( var_0 ) )
        return 0;

    return common_scripts\utility::array_contains( var_0, var_1 );
}

remove_weapons()
{
    var_0 = self getweaponslistprimaries();

    foreach ( var_2 in var_0 )
    {
        var_3 = strtok( var_2, "_" );

        if ( var_3[0] == "alt" )
            continue;

        self takeweapon( var_2 );
    }
}

get_alien_type()
{
    return self.alien_type;
}

should_explode()
{
    switch ( get_alien_type() )
    {
        case "minion":
            return 1;
        default:
            return 0;
    }
}

is_normal_upright( var_0 )
{
    var_1 = ( 0, 0, 1 );
    var_2 = 0.85;
    return vectordot( var_0, var_1 ) > var_2;
}

always_play_pain_sound( var_0 )
{
    if ( !animhasnotetrack( var_0, "alien_pain_light" ) && !animhasnotetrack( var_0, "alien_pain_heavy" ) )
        self playsoundonmovingent( "alien_pain_light" );
}

register_pain( var_0 )
{
    self.pain_registered = 1;
    thread pain_interval_monitor( var_0 );
}

pain_interval_monitor( var_0 )
{
    self endon( "death" );
    var_1 = get_alien_type();
    var_2 = level.alien_types[var_1].attributes["pain_interval"];
    wait( var_2 + getanimlength( var_0 ) );
    self.pain_registered = 0;
}

is_pain_available( var_0, var_1 )
{
    if ( isdefined( self.pain_registered ) && self.pain_registered )
        return 0;

    if ( isdefined( self.oriented ) && self.oriented )
        return 0;

    if ( var_1 == "MOD_MELEE" )
        return 1;

    if ( isdefined( var_0 ) && isplayer( var_0 ) && var_0 has_stun_ammo() )
        return 1;

    return 1;
}

mp_ents_clean_up()
{
    wait 0.5;
    var_0 = getentarray( "heli_start", "targetname" );

    foreach ( var_2 in var_0 )
        get_linked_nodes_and_delete( var_2 );

    var_4 = getentarray( "heli_loop_start", "targetname" );

    foreach ( var_6 in var_4 )
        get_linked_nodes_and_delete( var_6 );

    var_8 = getentarray( "heli_crash_start", "targetname" );

    foreach ( var_10 in var_8 )
        get_linked_nodes_and_delete( var_10 );
}

get_linked_nodes_and_delete( var_0 )
{
    var_1 = var_0;

    while ( isdefined( var_1.target ) )
    {
        var_2 = getent( var_1.target, "targetname" );

        if ( isdefined( var_2 ) )
        {
            var_1 delete();
            var_1 = var_2;
            continue;
        }

        break;
    }

    if ( isdefined( var_1 ) )
        var_1 delete();
}

is_holding_deployable()
{
    return self.is_holding_deployable;
}

has_special_weapon()
{
    return self.has_special_weapon;
}

type_has_head_armor( var_0 )
{
    switch ( var_0 )
    {
        case "brute4":
        case "brute3":
        case "brute2":
        case "brute1":
            return 1;
        default:
            return 0;
    }

    return 0;
}

get_closest_living_player()
{
    var_0 = 1073741824;
    var_1 = undefined;

    foreach ( var_3 in level.players )
    {
        var_4 = distancesquared( self.origin, var_3.origin );

        if ( maps\mp\_utility::isreallyalive( var_3 ) && var_4 < var_0 )
        {
            var_1 = var_3;
            var_0 = var_4;
        }
    }

    return var_1;
}

should_store_ammo_check( var_0, var_1 )
{
    var_2 = 1;

    switch ( var_0 )
    {
        case "explosive":
            if ( isdefined( self.special_ammocount ) && isdefined( self.special_ammocount[var_1] ) && self.special_ammocount[var_1] > 0 )
            {
                self.special_ammocount[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_ap ) && isdefined( self.special_ammocount_ap[var_1] ) && self.special_ammocount_ap[var_1] > 0 )
            {
                self.special_ammocount_ap[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_in ) && isdefined( self.special_ammocount_in[var_1] ) && self.special_ammocount_in[var_1] > 0 )
            {
                self.has_incendiary_ammo = undefined;
                self.special_ammocount_in[var_1] = 0;
                return 0;
            }
            else if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_1] ) && self.special_ammocount_comb[var_1] > 0 )
            {
                self.special_ammocount_comb[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
                maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );
                maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );
                self.has_incendiary_ammo = undefined;
                return 0;
            }

            return 1;
        case "piercing":
        case "ap":
            if ( isdefined( self.special_ammocount ) && isdefined( self.special_ammocount[var_1] ) && self.special_ammocount[var_1] > 0 )
            {
                self.special_ammocount[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_explo ) && isdefined( self.special_ammocount_explo[var_1] ) && self.special_ammocount_explo[var_1] > 0 )
            {
                self.special_ammocount_explo[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_in ) && isdefined( self.special_ammocount_in[var_1] ) && self.special_ammocount_in[var_1] > 0 )
            {
                self.has_incendiary_ammo = undefined;
                self.special_ammocount_in[var_1] = 0;
                return 0;
            }
            else if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_1] ) && self.special_ammocount_comb[var_1] > 0 )
            {
                self.special_ammocount_comb[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
                maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );
                maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );
                self.has_incendiary_ammo = undefined;
                return 0;
            }

            return 1;
        case "stun":
            if ( isdefined( self.special_ammocount_explo ) && isdefined( self.special_ammocount_explo[var_1] ) && self.special_ammocount_explo[var_1] > 0 )
            {
                self.special_ammocount_explo[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_ap ) && isdefined( self.special_ammocount_ap[var_1] ) && self.special_ammocount_ap[var_1] > 0 )
            {
                self.special_ammocount_ap[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_in ) && isdefined( self.special_ammocount_in[var_1] ) && self.special_ammocount_in[var_1] > 0 )
            {
                self.has_incendiary_ammo = undefined;
                self.special_ammocount_in[var_1] = 0;
                return 0;
            }
            else if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_1] ) && self.special_ammocount_comb[var_1] > 0 )
            {
                self.special_ammocount_comb[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
                maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );
                maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );
                self.has_incendiary_ammo = undefined;
                return 0;
            }

            return 1;
        case "incendiary":
            if ( isdefined( self.special_ammocount ) && isdefined( self.special_ammocount[var_1] ) && self.special_ammocount[var_1] > 0 )
            {
                self.special_ammocount[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_ap ) && isdefined( self.special_ammocount_ap[var_1] ) && self.special_ammocount_ap[var_1] > 0 )
            {
                self.special_ammocount_ap[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_explo ) && isdefined( self.special_ammocount_explo[var_1] ) && self.special_ammocount_explo[var_1] > 0 )
            {
                self.special_ammocount_explo[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_1] ) && self.special_ammocount_comb[var_1] > 0 )
            {
                self.special_ammocount_comb[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
                maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );
                maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );
                self.has_incendiary_ammo = undefined;
                return 0;
            }

            return 1;
        case "combined":
            if ( isdefined( self.special_ammocount ) && isdefined( self.special_ammocount[var_1] ) && self.special_ammocount[var_1] > 0 )
            {
                self.special_ammocount[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_ap ) && isdefined( self.special_ammocount_ap[var_1] ) && self.special_ammocount_ap[var_1] > 0 )
            {
                self.special_ammocount_ap[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_explo ) && isdefined( self.special_ammocount_explo[var_1] ) && self.special_ammocount_explo[var_1] > 0 )
            {
                self.special_ammocount_explo[var_1] = 0;
                maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
                return 0;
            }
            else if ( isdefined( self.special_ammocount_in ) && isdefined( self.special_ammocount_in[var_1] ) && self.special_ammocount_in[var_1] > 0 )
            {
                self.has_incendiary_ammo = undefined;
                self.special_ammocount_in[var_1] = 0;
                return 0;
            }

            return 1;
    }
}

is_ammo_already_stored( var_0 )
{
    if ( isdefined( self.stored_ammo[var_0] ) )
        return isdefined( self.stored_ammo[var_0].clipammo ) && isdefined( self.stored_ammo[var_0].ammostock );

    return 0;
}

give_special_ammo_by_weaponclass( var_0, var_1, var_2 )
{
    if ( !isdefined( var_1 ) )
        var_1 = self getcurrentprimaryweapon();

    var_3 = maps\mp\_utility::getweaponclass( var_1 );
    var_4 = 0;

    if ( isdefined( var_0 ) )
    {
        if ( var_0.boxtype != "deployable_specialammo_comb" )
        {
            switch ( var_0.upgrade_rank )
            {
                case 0:
                    var_4 = 0.3;
                    break;
                case 1:
                    var_4 = 0.4;
                    break;
                case 2:
                    var_4 = 0.5;
                    break;
                case 3:
                    var_4 = 0.6;
                    break;
                case 4:
                    var_4 = 0.7;
                    break;
            }
        }
        else
        {
            switch ( var_0.upgrade_rank )
            {
                case 0:
                    var_4 = 0.4;
                    break;
                case 1:
                    var_4 = 0.7;
                    break;
                case 2:
                    var_4 = 1.0;
                    break;
                case 3:
                    var_4 = 1.0;
                    maps\mp\alien\_deployablebox_functions::addfullcombinedcliptoallweapons();
                    break;
                case 4:
                    var_4 = 1.0;
                    maps\mp\alien\_deployablebox_functions::addfullcombinedcliptoallweapons();
                    break;
            }
        }
    }

    var_5 = maps\mp\alien\_deployablebox_functions::check_for_nerf_min_ammo();

    if ( var_5 != 1.0 )
        var_4 = var_5;

    switch ( var_3 )
    {
        case "weapon_pistol":
        case "weapon_shotgun":
        case "weapon_lmg":
        case "weapon_dmr":
        case "weapon_sniper":
        case "weapon_assault":
        case "weapon_smg":
            if ( isdefined( var_2 ) && var_2 )
            {
                if ( level.use_alternate_specialammo_pillage_amounts )
                {
                    var_6 = weaponclipsize( var_1 );
                    return int( var_6 * 2 );
                }

                return int( weaponmaxammo( var_1 ) * 0.2 );
            }
            else
                return int( weaponmaxammo( var_1 ) * var_4 );
        default:
            return 0;
    }
}

player_has_specialized_ammo( var_0 )
{
    var_1 = 0;

    if ( isdefined( self.special_ammocount ) && isdefined( self.special_ammocount[var_0] ) && self.special_ammocount[var_0] > 0 )
        var_1 = 1;

    if ( isdefined( self.special_ammocount_ap ) && isdefined( self.special_ammocount_ap[var_0] ) && self.special_ammocount_ap[var_0] > 0 )
        var_1 = 1;

    if ( isdefined( self.special_ammocount_in ) && isdefined( self.special_ammocount_in[var_0] ) && self.special_ammocount_in[var_0] > 0 )
        var_1 = 1;

    if ( isdefined( self.special_ammocount_explo ) && isdefined( self.special_ammocount_explo[var_0] ) && self.special_ammocount_explo[var_0] > 0 )
        var_1 = 1;

    if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_0] ) && self.special_ammocount_comb[var_0] > 0 )
        var_1 = 1;

    return var_1;
}

has_stun_ammo( var_0 )
{
    if ( !isdefined( var_0 ) )
        var_1 = self getcurrentweapon();
    else
        var_1 = var_0;

    if ( var_1 == "none" )
        var_1 = self getweaponslistprimaries()[0];

    var_2 = getrawbaseweaponname( var_1 );

    if ( is_chaos_mode() && self hasperk( "specialty_bulletdamage", 1 ) )
        return 1;

    if ( isdefined( self.special_ammocount ) && isdefined( self.special_ammocount[var_2] ) && self.special_ammocount[var_2] > 0 )
        return 1;

    if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_2] ) && self.special_ammocount_comb[var_2] > 0 )
        return 1;

    return 0;
}

has_ap_ammo( var_0 )
{
    if ( !isdefined( var_0 ) )
        var_1 = self getcurrentweapon();
    else
        var_1 = var_0;

    if ( var_1 == "none" )
        var_1 = self getweaponslistprimaries()[0];

    var_2 = getrawbaseweaponname( var_1 );

    if ( isdefined( self.special_ammocount_ap ) && isdefined( self.special_ammocount_ap[var_2] ) && self.special_ammocount_ap[var_2] > 0 )
        return 1;

    if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_2] ) && self.special_ammocount_comb[var_2] > 0 )
        return 1;

    return 0;
}

has_explosive_ammo( var_0 )
{
    if ( !isdefined( var_0 ) )
        var_1 = self getcurrentweapon();
    else
        var_1 = var_0;

    if ( var_1 == "none" )
        var_1 = self getweaponslistprimaries()[0];

    var_2 = getrawbaseweaponname( var_1 );

    if ( isdefined( self.special_ammocount_explo ) && isdefined( self.special_ammocount_explo[var_2] ) && self.special_ammocount_explo[var_2] > 0 )
        return 1;

    if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_2] ) && self.special_ammocount_comb[var_2] > 0 )
        return 1;

    return 0;
}

has_incendiary_ammo( var_0 )
{
    if ( !isdefined( var_0 ) )
        var_1 = self getcurrentweapon();
    else
        var_1 = var_0;

    if ( var_1 == "none" )
        var_1 = self getweaponslistprimaries()[0];

    var_2 = getrawbaseweaponname( var_1 );

    if ( isdefined( self.special_ammocount_in ) && isdefined( self.special_ammocount_in[var_2] ) && self.special_ammocount_in[var_2] > 0 )
        return 1;

    if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_2] ) && self.special_ammocount_comb[var_2] > 0 )
        return 1;

    return 0;
}

has_combined_ammo( var_0 )
{
    if ( !isdefined( var_0 ) )
        var_1 = self getcurrentweapon();
    else
        var_1 = var_0;

    if ( var_1 == "none" )
        var_1 = self getweaponslistprimaries()[0];

    var_2 = getrawbaseweaponname( var_1 );

    if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_2] ) && self.special_ammocount_comb[var_2] > 0 )
        return 1;

    return 0;
}

remove_specialized_ammo( var_0 )
{
    var_1 = 0;

    if ( isdefined( self.special_ammocount ) && isdefined( self.special_ammocount[var_0] ) && self.special_ammocount[var_0] > 0 )
        self.special_ammocount[var_0] = 0;

    if ( isdefined( self.special_ammocount_ap ) && isdefined( self.special_ammocount_ap[var_0] ) && self.special_ammocount_ap[var_0] > 0 )
        self.special_ammocount_ap[var_0] = 0;

    if ( isdefined( self.special_ammocount_in ) && isdefined( self.special_ammocount_in[var_0] ) && self.special_ammocount_in[var_0] > 0 )
        self.special_ammocount_in[var_0] = 0;

    if ( isdefined( self.special_ammocount_explo ) && isdefined( self.special_ammocount_explo[var_0] ) && self.special_ammocount_explo[var_0] > 0 )
        self.special_ammocount_explo[var_0] = 0;

    if ( isdefined( self.special_ammocount_comb ) && isdefined( self.special_ammocount_comb[var_0] ) && self.special_ammocount_comb[var_0] > 0 )
        self.special_ammocount_comb[var_0] = 0;
}

get_specialized_ammo_type()
{
    var_0 = self getcurrentweapon();

    if ( var_0 == "none" )
        var_0 = self getweaponslistprimaries()[0];

    var_1 = getrawbaseweaponname( var_0 );
    var_2 = 0;

    if ( isdefined( self.special_ammocount ) && isdefined( self.special_ammocount[var_1] ) && self.special_ammocount[var_1] > 0 )
        return "stun_ammo";

    if ( isdefined( self.special_ammocount_ap ) && isdefined( self.special_ammocount_ap[var_1] ) && self.special_ammocount_ap[var_1] > 0 )
        return "ap_ammo";

    if ( isdefined( self.special_ammocount_in ) && isdefined( self.special_ammocount_in[var_1] ) && self.special_ammocount_in[var_1] > 0 )
        return "incendiary_ammo";

    if ( isdefined( self.special_ammocount_explo ) && isdefined( self.special_ammocount_explo[var_1] ) && self.special_ammocount_explo[var_1] > 0 )
        return "explosive_ammo";

    return "none";
}

mark_dangerous_nodes( var_0, var_1, var_2 )
{
    markdangerousnodes( var_0, var_1, 1 );
    wait( var_2 );
    markdangerousnodes( var_0, var_1, 0 );
}

is_in_laststand()
{
    return self.inlaststand;
}

is_hardcore_mode()
{
    return level.hardcoremode;
}

is_ricochet_damage()
{
    return level.ricochetdamage;
}

is_chaos_mode()
{
    return level.ischaosmode == 1;
}

is_casual_mode()
{
    return level.casualmode == 1;
}

get_chaos_area()
{
    return level.chaos_area;
}

deployable_box_onuse_message( var_0 )
{
    var_1 = "";

    if ( isdefined( var_0 ) && isdefined( var_0.boxtype ) && isdefined( level.boxsettings[var_0.boxtype].eventstring ) )
        var_1 = level.boxsettings[var_0.boxtype].eventstring;

    thread maps\mp\_utility::setlowermessage( "deployable_use", var_1, 3 );
}

set_attack_sync_direction( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    var_6 = [];
    var_6["enterAnim"] = var_1;
    var_6["loopAnim"] = var_2;
    var_6["exitAnim"] = var_3;
    var_6["attackerAnimState"] = var_4;
    var_6["attackerAnimLabel"] = var_5;
    var_6["offset_direction"] = var_0;
    return var_6;
}

set_synch_attack_setup( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7 )
{
    var_8 = spawnstruct();
    var_8.synch_directions = var_0;
    var_8.type_specific = var_1;
    var_8.primary_attacker = undefined;
    var_8.can_synch_attack_func = var_3;
    var_8.begin_attack_func = var_4;
    var_8.end_attack_func = var_6;
    var_8.loop_attack_func = var_5;
    var_8.end_notifies = var_2;
    var_8.identifier = var_7;
    self.synch_attack_setup = var_8;
}

get_synch_direction_list( var_0 )
{
    if ( !isdefined( self.synch_attack_setup ) )
        return [];

    if ( !isdefined( self.synch_attack_setup.synch_directions ) )
        return [];

    if ( !self.synch_attack_setup.type_specific )
        return self.synch_attack_setup.synch_directions;

    var_1 = var_0 get_alien_type();

    if ( !isdefined( self.synch_attack_setup.synch_directions[var_1] ) )
        var_2 = "Synch attack on " + self.synch_attack_setup.identifier + " doesn't handle type: " + var_1;

    return self.synch_attack_setup.synch_directions[var_1];
}

is_alien_agent()
{
    return isagent( self ) && isdefined( self.alien_type );
}

isplayingsolo()
{
    if ( getdvarint( "sv_maxclients" ) == 1 )
        return 1;

    return 0;
}

riotshieldname()
{
    var_0 = self getweaponslist( "primary" );

    if ( !self.hasriotshield )
        return;

    foreach ( var_2 in var_0 )
    {
        if ( weapontype( var_2 ) == "riotshield" )
            return var_2;
    }
}

get_array_of_valid_players( var_0, var_1 )
{
    var_2 = [];

    foreach ( var_4 in level.players )
    {
        if ( var_4 is_valid_player() )
            var_2[var_2.size] = var_4;
    }

    if ( !isdefined( var_0 ) || !var_0 )
        return var_2;

    return common_scripts\utility::get_array_of_closest( var_1, var_2 );
}

is_valid_player()
{
    if ( !isdefined( self ) )
        return 0;

    if ( is_in_laststand() )
        return 0;

    if ( !isalive( self ) )
        return 0;

    if ( self.sessionstate == "spectator" )
        return 0;

    return 1;
}

getrawbaseweaponname( var_0 )
{
    var_1 = strtok( var_0, "_" );

    if ( var_1[0] == "iw5" || var_1[0] == "iw6" )
        var_0 = var_1[1];
    else if ( var_1[0] == "alt" )
        var_0 = var_1[1] + "_" + var_1[2];

    return var_0;
}

get_in_world_area()
{
    foreach ( var_2, var_1 in level.world_areas )
    {
        if ( self istouching( var_1 ) )
            return var_2;
    }

    return "none";
}

is_true( var_0 )
{
    if ( isdefined( var_0 ) && var_0 )
        return 1;

    return 0;
}

is_akimbo_weapon( var_0 )
{
    switch ( var_0 )
    {
        case "iw5_alienmp443_mp_akimbo_barrelrange02_xmags":
        case "iw5_alienm9a1_mp_akimbo_barrelrange02_xmags":
        case "iw5_alienmagnum_mp_akimbo_barrelrange02_xmags":
        case "iw5_alienp226_mp_akimbo_barrelrange02_xmags":
            return 1;
    }

    if ( maps\mp\_utility::getweaponclass( var_0 ) == "weapon_pistol" )
        return issubstr( var_0, "akimbo" );

    return 0;
}

special_ammo_weapon_change_monitor( var_0 )
{
    self endon( "disconnect" );
    level endon( "game_ended" );
    self notify( "special_weapons_monitor" );
    self endon( "special_weapons_monitor" );

    for (;;)
    {
        self waittill( "weapon_change", var_1 );

        if ( var_1 == "none" )
            continue;

        var_2 = getrawbaseweaponname( var_1 );
        var_3 = 0;
        var_4 = undefined;
        var_5 = undefined;

        switch ( var_0 )
        {
            case "stun":
                var_3 = has_stun_ammo( var_2 );
                var_4 = "specialty_bulletdamage";
                var_5 = 1;
                break;
            case "piercing":
                var_3 = has_ap_ammo( var_2 );
                var_4 = "specialty_armorpiercing";
                var_5 = 4;
                break;
            case "incendiary":
                var_3 = has_incendiary_ammo( var_2 );
                var_5 = 2;
                break;
            case "explosive":
                var_3 = has_explosive_ammo( var_2 );
                var_4 = "specialty_explosivebullets";
                var_5 = 3;
                break;
            case "combined":
                var_3 = has_combined_ammo( var_2 );
                var_5 = 5;
                break;
        }

        if ( is_true( var_3 ) )
        {
            if ( isdefined( var_4 ) )
                maps\mp\_utility::giveperk( var_4, 0 );

            if ( var_0 == "combined" )
            {
                self.has_incendiary_ammo = 1;
                maps\mp\_utility::giveperk( "specialty_bulletdamage", 0 );
                maps\mp\_utility::giveperk( "specialty_armorpiercing", 0 );
                maps\mp\_utility::giveperk( "specialty_explosivebullets", 0 );
            }

            if ( var_0 == "incendiary" )
                self.has_incendiary_ammo = 1;

            self setclientomnvar( "ui_alien_specialammo", var_5 );
            continue;
        }

        if ( isdefined( var_4 ) )
        {
            if ( maps\mp\_utility::_hasperk( var_4 ) )
                maps\mp\_utility::_unsetperk( var_4 );
        }

        if ( var_0 == "combined" )
        {
            self.has_incendiary_ammo = undefined;

            if ( maps\mp\_utility::_hasperk( "specialty_bulletdamage" ) )
                maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );

            if ( maps\mp\_utility::_hasperk( "specialty_armorpiercing" ) )
                maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );

            if ( maps\mp\_utility::_hasperk( "specialty_explosivebullets" ) )
                maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
        }

        if ( var_0 == "incendiary" )
            self.has_incendiary_ammo = undefined;

        self setclientomnvar( "ui_alien_specialammo", -1 );
    }
}

special_ammo_weapon_fire_monitor( var_0 )
{
    self notify( "weaponfire_monitor" );
    self endon( "weaponfire_monitor" );

    for (;;)
    {
        self waittill( "weapon_fired", var_1 );
        var_2 = getrawbaseweaponname( var_1 );
        var_3 = 0;
        var_4 = undefined;

        switch ( var_0 )
        {
            case "stun":
                var_3 = has_stun_ammo( var_2 );
                var_4 = "specialty_bulletdamage";
                var_5 = self.special_ammocount;
                break;
            case "piercing":
                var_3 = has_ap_ammo( var_2 );
                var_4 = "specialty_armorpiercing";
                var_5 = self.special_ammocount_ap;
                break;
            case "incendiary":
                var_3 = has_incendiary_ammo( var_2 );
                var_5 = self.special_ammocount_in;
                break;
            case "explosive":
                var_3 = has_explosive_ammo( var_2 );
                var_4 = "specialty_explosivebullets";
                var_5 = self.special_ammocount_explo;
                break;
            case "combined":
                var_3 = has_combined_ammo( var_2 );
                var_5 = self.special_ammocount_comb;
                break;
        }

        if ( is_true( var_3 ) )
        {
            var_6 = self getweaponammoclip( var_1 );
            var_7 = self getweaponammostock( var_1 );

            if ( is_akimbo_weapon( var_1 ) )
            {
                var_8 = self getweaponammoclip( var_1, "left" );
                var_9 = self getweaponammoclip( var_1, "right" );
                var_6 = var_8 + var_9;
            }

            switch ( var_0 )
            {
                case "stun":
                    self.special_ammocount[var_2] = var_6 + var_7;
                    break;
                case "piercing":
                    self.special_ammocount_ap[var_2] = var_6 + var_7;
                    break;
                case "incendiary":
                    self.special_ammocount_in[var_2] = var_6 + var_7;
                    break;
                case "explosive":
                    self.special_ammocount_explo[var_2] = var_6 + var_7;
                    break;
                case "combined":
                    self.special_ammocount_comb[var_2] = var_6 + var_7;
                    break;
            }

            if ( var_6 + var_7 < 1 )
            {
                self setclientomnvar( "ui_alien_specialammo", -1 );

                if ( isdefined( var_4 ) )
                {
                    if ( maps\mp\_utility::_hasperk( var_4 ) )
                        maps\mp\_utility::_unsetperk( var_4 );
                }

                if ( var_0 == "combined" )
                {
                    self.has_incendiary_ammo = undefined;

                    if ( maps\mp\_utility::_hasperk( "specialty_bulletdamage" ) )
                        maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );

                    if ( maps\mp\_utility::_hasperk( "specialty_armorpiercing" ) )
                        maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );

                    if ( maps\mp\_utility::_hasperk( "specialty_explosivebullets" ) )
                        maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
                }

                if ( var_0 == "incendiary" )
                    self.has_incendiary_ammo = undefined;

                if ( isdefined( self.stored_ammo[var_2] ) )
                {
                    self.stored_ammo[var_2].ammostock = self.stored_ammo[var_2].ammostock + self.stored_ammo[var_2].clipammo;
                    self setweaponammoclip( var_1, 0 );
                    self setweaponammostock( var_1, self.stored_ammo[var_2].ammostock );
                    self.stored_ammo[var_2] = undefined;
                    self switchtoweapon( var_1 );
                }

                continue;
            }
        }
    }
}

disable_special_ammo()
{
    self endon( "disconnect" );
    var_0 = self getweaponslistprimaries();

    foreach ( var_2 in var_0 )
    {
        var_3 = getrawbaseweaponname( var_2 );
        var_4 = undefined;
        var_5 = undefined;
        var_6 = undefined;

        if ( has_stun_ammo( var_3 ) )
        {
            var_5 = "specialty_bulletdamage";
            var_6 = 1;
            var_4 = "stun";
        }
        else if ( has_ap_ammo( var_3 ) )
        {
            var_5 = "specialty_armorpiercing";
            var_6 = 4;
            var_4 = "piercing";
        }
        else if ( has_incendiary_ammo( var_3 ) )
        {
            var_4 = "incendiary";
            var_6 = 2;
        }
        else if ( has_explosive_ammo( var_3 ) )
        {
            var_4 = "explosive";
            var_5 = "specialty_explosivebullets";
            var_6 = 3;
        }
        else if ( has_combined_ammo( var_3 ) )
        {
            var_4 = "combined";
            var_6 = 5;
        }

        if ( isdefined( var_4 ) )
        {
            if ( isdefined( var_5 ) )
            {
                if ( maps\mp\_utility::_hasperk( var_5 ) )
                    maps\mp\_utility::_unsetperk( var_5 );
            }

            if ( var_4 == "combined" )
            {
                self.has_incendiary_ammo = undefined;

                if ( maps\mp\_utility::_hasperk( "specialty_bulletdamage" ) )
                    maps\mp\_utility::_unsetperk( "specialty_bulletdamage" );

                if ( maps\mp\_utility::_hasperk( "specialty_armorpiercing" ) )
                    maps\mp\_utility::_unsetperk( "specialty_armorpiercing" );

                if ( maps\mp\_utility::_hasperk( "specialty_explosivebullets" ) )
                    maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );
            }

            if ( var_4 == "incendiary" )
                self.has_incendiary_ammo = undefined;

            self setclientomnvar( "ui_alien_specialammo", -1 );
            return;
        }
    }
}

enable_special_ammo()
{
    self endon( "disconnect" );
    var_0 = self getcurrentprimaryweapon();
    var_1 = getrawbaseweaponname( var_0 );
    var_2 = undefined;
    var_3 = undefined;
    var_4 = undefined;

    if ( has_stun_ammo( var_1 ) )
    {
        var_3 = "specialty_bulletdamage";
        var_4 = 1;
        var_2 = "stun";
    }
    else if ( has_ap_ammo( var_1 ) )
    {
        var_3 = "specialty_armorpiercing";
        var_4 = 4;
        var_2 = "piercing";
    }
    else if ( has_incendiary_ammo( var_1 ) )
    {
        var_2 = "incendiary";
        var_4 = 2;
    }
    else if ( has_explosive_ammo( var_1 ) )
    {
        var_2 = "explosive";
        var_3 = "specialty_explosivebullets";
        var_4 = 3;
    }
    else if ( has_combined_ammo( var_1 ) )
    {
        var_2 = "combined";
        var_4 = 5;
    }

    if ( isdefined( var_2 ) )
    {
        if ( isdefined( var_3 ) )
            maps\mp\_utility::giveperk( var_3, 0 );

        if ( var_2 == "combined" )
        {
            self.has_incendiary_ammo = 1;
            maps\mp\_utility::giveperk( "specialty_bulletdamage", 0 );
            maps\mp\_utility::giveperk( "specialty_armorpiercing", 0 );
            maps\mp\_utility::giveperk( "specialty_explosivebullets", 0 );
        }

        if ( var_2 == "incendiary" )
            self.has_incendiary_ammo = 1;

        self setclientomnvar( "ui_alien_specialammo", var_4 );
    }
}

show_turret_icon( var_0 )
{
    self setclientomnvar( "ui_alien_turret", var_0 );
}

hide_turret_icon()
{
    self setclientomnvar( "ui_alien_turret", -1 );
    self setclientomnvar( "ui_alien_turret_ammo", -1 );
}

set_turret_ammocount( var_0 )
{
    self setclientomnvar( "ui_alien_turret_ammo", var_0 );
}

add_hive_dependencies( var_0, var_1 )
{
    if ( !isdefined( level.hive_dependencies ) )
        level.hive_dependencies = [];

    level.hive_dependencies[var_0] = var_1;
}

should_snare( var_0 )
{
    if ( !is_alien_agent() || is_chaos_mode() )
        return 0;

    if ( var_0 maps\mp\alien\_persistence::is_upgrade_enabled( "no_snare_upgrade" ) )
        return 0;

    var_1 = get_alien_type();

    if ( var_1 == "brute" || var_1 == "minion" )
        return 1;
    else
        return 0;
}

buildalienweaponname( var_0, var_1, var_2, var_3, var_4, var_5, var_6 )
{
    if ( isdefined( var_6 ) && var_6 != 0 && maps\mp\_utility::getattachmenttype( var_1 ) != "rail" && maps\mp\_utility::getattachmenttype( var_2 ) != "rail" && maps\mp\_utility::getattachmenttype( var_3 ) != "rail" && maps\mp\_utility::getattachmenttype( var_4 ) != "rail" )
        var_6 = undefined;

    if ( var_1 == "alienvksscope" )
        var_1 = "scope";
    else if ( var_1 == "alienl115a3vzscope" )
        var_1 = "vzscope";

    if ( var_2 == "alienvksscope" )
        var_2 = "scope";
    else if ( var_2 == "alienl115a3vzscope" )
        var_2 = "vzscope";

    if ( var_3 == "alienvksscope" )
        var_3 = "scope";
    else if ( var_3 == "alienl115a3vzscope" )
        var_3 = "vzscope";

    if ( var_4 == "alienvksscope" )
        var_4 = "scope";
    else if ( var_4 == "alienl115a3vzscope" )
        var_4 = "vzscope";

    var_1 = maps\mp\_utility::attachmentmap_tounique( var_1, var_0 );
    var_2 = maps\mp\_utility::attachmentmap_tounique( var_2, var_0 );
    var_3 = maps\mp\_utility::attachmentmap_tounique( var_3, var_0 );
    var_4 = maps\mp\_utility::attachmentmap_tounique( var_4, var_0 );
    var_7 = "";

    if ( issubstr( var_0, "iw5" ) || issubstr( var_0, "iw6" ) )
    {
        var_8 = var_0 + "_mp";
        var_9 = var_0.size;
        var_7 = getsubstr( var_0, 4, var_9 );
    }
    else
        var_8 = var_0;

    var_10 = maps\mp\_utility::getweaponclass( var_0 );
    var_11 = var_10 == "weapon_sniper" || var_0 == "aliendlc23";
    var_12 = [];

    if ( var_1 != "none" )
        var_12[var_12.size] = var_1;

    if ( var_2 != "none" )
        var_12[var_12.size] = var_2;

    if ( var_3 != "none" )
        var_12[var_12.size] = var_3;

    if ( var_4 != "none" )
        var_12[var_12.size] = var_4;

    if ( var_11 )
    {
        var_13 = 0;

        foreach ( var_15 in var_12 )
        {
            if ( maps\mp\_utility::getattachmenttype( var_15 ) == "rail" )
            {
                var_13 = 1;
                break;
            }
        }

        if ( !var_13 )
            var_12[var_12.size] = var_7 + "scope";
    }

    if ( isdefined( var_12.size ) && var_12.size )
        var_12 = common_scripts\utility::alphabetize( var_12 );

    foreach ( var_15 in var_12 )
        var_8 = var_8 + ( "_" + var_15 );

    if ( issubstr( var_8, "iw5" ) || issubstr( var_8, "iw6" ) )
    {
        var_8 = buildalienweaponnamecamo( var_8, var_5 );
        var_8 = buildalienweaponnamereticle( var_8, var_6 );
    }
    else if ( !isvalidalienweapon( var_8 + "_mp" ) )
        var_8 = var_0 + "_mp";
    else
    {
        var_8 = buildalienweaponnamecamo( var_8, var_5 );
        var_8 = buildalienweaponnamereticle( var_8, var_6 );
        var_8 = var_8 + "_mp";
    }

    return var_8;
}

buildalienweaponnamecamo( var_0, var_1 )
{
    if ( !isdefined( var_1 ) )
        return var_0;

    if ( var_1 <= 0 )
        return var_0;

    if ( var_1 < 10 )
        var_0 = var_0 + "_camo0";
    else
        var_0 = var_0 + "_camo";

    var_0 = var_0 + var_1;
    return var_0;
}

buildalienweaponnamereticle( var_0, var_1 )
{
    if ( !isdefined( var_1 ) )
        return var_0;

    if ( var_1 <= 1 )
        return var_0;

    var_1--;
    var_0 = var_0 + "_scope";
    var_0 = var_0 + var_1;
    return var_0;
}

isvalidalienweapon( var_0 )
{
    if ( !isdefined( level.weaponrefs ) )
    {
        level.weaponrefs = [];

        foreach ( var_2 in level.weaponlist )
            level.weaponrefs[var_2] = 1;
    }

    if ( isdefined( level.weaponrefs[var_0] ) )
        return 1;

    return 0;
}

_detachall()
{
    if ( isdefined( self.hasriotshield ) && self.hasriotshield )
    {
        if ( self.hasriotshieldequipped )
        {
            self detachshieldmodel( "weapon_riot_shield_iw6", "tag_weapon_right" );
            self.hasriotshieldequipped = 0;
        }
        else
            self detachshieldmodel( "weapon_riot_shield_iw6", "tag_shield_back" );

        self.hasriotshield = 0;
    }

    self detachall();
}

hasriotshield()
{
    var_0 = 0;
    var_1 = self getweaponslistprimaries();

    foreach ( var_3 in var_1 )
    {
        if ( maps\mp\gametypes\_weapons::isriotshield( var_3 ) )
        {
            var_0 = 1;
            break;
        }
    }

    return var_0;
}

trackriotshield()
{
    self endon( "death" );
    self endon( "disconnect" );
    self endon( "faux_spawn" );
    self.hasriotshield = hasriotshield();
    var_0 = self getcurrentweapon();
    self.hasriotshieldequipped = maps\mp\gametypes\_weapons::isriotshield( var_0 );

    if ( self.hasriotshield )
    {
        if ( maps\mp\gametypes\_weapons::isriotshield( self.primaryweapon ) && maps\mp\gametypes\_weapons::isriotshield( self.secondaryweapon ) )
        {
            self attachshieldmodel( "weapon_riot_shield_iw6", "tag_weapon_right" );
            self attachshieldmodel( "weapon_riot_shield_iw6", "tag_shield_back" );
        }
        else if ( self.hasriotshieldequipped )
            self attachshieldmodel( "weapon_riot_shield_iw6", "tag_weapon_right" );
        else
            self attachshieldmodel( "weapon_riot_shield_iw6", "tag_shield_back" );
    }

    for (;;)
    {
        self waittill( "weapon_change", var_1 );

        if ( maps\mp\gametypes\_weapons::isriotshield( var_1 ) )
        {
            if ( self.hasriotshieldequipped )
                continue;

            if ( maps\mp\gametypes\_weapons::isriotshield( self.primaryweapon ) && maps\mp\gametypes\_weapons::isriotshield( self.secondaryweapon ) )
                continue;
            else if ( self.hasriotshield )
                self moveshieldmodel( "weapon_riot_shield_iw6", "tag_shield_back", "tag_weapon_right" );
            else
                self attachshieldmodel( "weapon_riot_shield_iw6", "tag_weapon_right" );

            self.hasriotshield = 1;
            self.hasriotshieldequipped = 1;
            continue;
        }

        if ( self ismantling() && var_1 == "none" )
            continue;

        if ( self.hasriotshieldequipped )
        {
            self.hasriotshield = hasriotshield();

            if ( self.hasriotshield )
                self moveshieldmodel( "weapon_riot_shield_iw6", "tag_weapon_right", "tag_shield_back" );
            else
                self detachshieldmodel( "weapon_riot_shield_iw6", "tag_weapon_right" );

            self.hasriotshieldequipped = 0;
            continue;
        }

        if ( self.hasriotshield && !hasriotshield() )
        {
            self detachshieldmodel( "weapon_riot_shield_iw6", "tag_shield_back" );
            self.hasriotshield = 0;
            continue;
        }

        if ( !self.hasriotshield && hasriotshield() )
        {
            self attachshieldmodel( "weapon_riot_shield_iw6", "tag_shield_back" );
            self.hasriotshield = 1;
        }
    }
}

tryattach( var_0 )
{
    if ( !isdefined( var_0 ) || var_0 != "back" )
        var_1 = "tag_inhand";
    else
        var_1 = "tag_shield_back";

    var_2 = self getattachsize();

    for ( var_3 = 0; var_3 < var_2; var_3++ )
    {
        var_4 = self getattachtagname( var_3 );

        if ( var_4 == var_1 && self getattachmodelname( var_3 ) == "weapon_riot_shield_iw6" )
            return;
    }

    self attachshieldmodel( "weapon_riot_shield_iw6", var_1 );
}

weapon_change_monitor()
{
    self endon( "disconnect" );
    self.has_special_weapon = 0;
    self.is_holding_deployable = 0;
    self.is_holding_crate_marker = 0;
    self.should_track_weapon_fired = 1;

    for (;;)
    {
        self waittill( "weapon_change", var_0 );

        switch ( var_0 )
        {
            case "iw5_alienriotshield4_mp":
            case "iw5_alienriotshield3_mp":
            case "iw5_alienriotshield2_mp":
            case "iw5_alienriotshield1_mp":
            case "aliendeployable_crate_marker_mp":
            case "switchblade_laptop_mp":
            case "mortar_detonator_mp":
            case "alienbomb_mp":
            case "iw5_alienriotshield_mp":
            case "none":
                self.should_track_weapon_fired = 0;
                break;
            default:
                self.should_track_weapon_fired = 1;
                break;
        }

        if ( var_0 == "none" )
            continue;

        self.has_special_weapon = 0;
        self.is_holding_deployable = 0;
        self.is_holding_crate_marker = 0;

        switch ( var_0 )
        {
            case "iw6_alienmaaws_mp":
            case "iw6_alienmk324_mp":
            case "iw6_alienmk323_mp":
            case "iw6_alienmk322_mp":
            case "iw6_alienmk321_mp":
            case "iw6_alienmk32_mp":
            case "iw6_alienminigun4_mp":
            case "iw6_alienminigun3_mp":
            case "iw6_alienminigun2_mp":
            case "iw6_alienminigun1_mp":
            case "iw6_alienminigun_mp":
                self.has_special_weapon = 1;
                break;
            case "alien_turret_marker_mp":
            case "alienpropanetank_mp":
            case "switchblade_laptop_mp":
            case "mortar_detonator_mp":
            case "alienbomb_mp":
            case "alienclaymore_mp":
            case "alientrophy_mp":
            case "deployable_vest_marker_mp":
            case "bouncingbetty_mp":
                self.is_holding_deployable = 1;
                break;
            case "aliendeployable_crate_marker_mp":
                self.is_holding_deployable = 1;
                self.is_holding_crate_marker = 1;
                break;
        }

        if ( !self.has_special_weapon )
        {
            var_1 = self getweaponslistprimaries();

            foreach ( var_3 in var_1 )
            {
                switch ( var_3 )
                {
                    case "iw6_alienmaaws_mp":
                    case "iw6_alienmk324_mp":
                    case "iw6_alienmk323_mp":
                    case "iw6_alienmk322_mp":
                    case "iw6_alienmk321_mp":
                    case "iw6_alienmk32_mp":
                    case "iw6_alienminigun4_mp":
                    case "iw6_alienminigun3_mp":
                    case "iw6_alienminigun2_mp":
                    case "iw6_alienminigun1_mp":
                    case "iw6_alienminigun_mp":
                        self.has_special_weapon = 1;
                }

                if ( self.has_special_weapon )
                    break;
            }
        }
    }
}

is_trap( var_0 )
{
    if ( !isdefined( var_0 ) )
        return 0;

    if ( isdefined( var_0.tesla_type ) )
        return 1;

    if ( !isdefined( var_0.script_noteworthy ) && !isdefined( var_0.targetname ) )
        return 0;

    if ( isdefined( var_0.targetname ) && ( var_0.targetname == "fence_generator" || var_0.targetname == "puddle_generator" ) )
        return 1;

    if ( isdefined( var_0.script_noteworthy ) && var_0.script_noteworthy == "fire_trap" )
        return 1;

    return 0;
}

zero_out_specialammo_clip( var_0 )
{
    if ( is_akimbo_weapon( var_0 ) )
    {
        self setweaponammoclip( var_0, 0, "left" );
        self setweaponammoclip( var_0, 0, "right" );
    }
    else
        self setweaponammoclip( var_0, 0 );
}

handle_existing_ammo( var_0, var_1, var_2 )
{
    if ( !isdefined( self.stored_ammo ) )
        self.stored_ammo = [];

    if ( !isdefined( self.stored_ammo[var_0] ) )
        self.stored_ammo[var_0] = spawnstruct();

    var_3 = should_store_ammo_check( var_2, var_0 );

    if ( var_3 && !is_ammo_already_stored( var_0 ) )
    {
        var_4 = self getweaponammoclip( var_1 );
        var_5 = self getweaponammostock( var_1 );

        if ( is_akimbo_weapon( var_1 ) )
        {
            var_6 = self getweaponammoclip( var_1, "left" );
            var_7 = self getweaponammoclip( var_1, "right" );
            var_4 = var_6 + var_7;
        }

        self.stored_ammo[var_0].clipammo = var_4;
        self.stored_ammo[var_0].ammostock = var_5;
    }
}

wait_for_player_to_dismount_turret()
{
    self endon( "death" );
    self endon( "disconnect" );
    maps\mp\_utility::setlowermessage( "disengage_turret", &"ALIEN_COLLECTIBLES_DISENGAGE_TURRET", 0 );

    while ( self isusingturret() )
        wait 0.5;

    maps\mp\_utility::clearlowermessage( "disengage_turret" );
}

disable_weapon_timeout( var_0, var_1 )
{
    thread enable_weapon_after_timeout( var_0, var_1 );
    common_scripts\utility::_disableweapon();
}

enable_weapon_after_timeout( var_0, var_1 )
{
    self endon( "death" );
    self endon( var_1 );
    wait( var_0 );
    common_scripts\utility::_enableweapon();
}

enable_weapon_wrapper( var_0 )
{
    self notify( var_0 );
    common_scripts\utility::_enableweapon();
}

getmultiplerandomindex( var_0, var_1 )
{
    var_2 = [];

    for ( var_3 = 0; var_3 < var_1; var_3++ )
    {
        var_4 = getrandomindex( var_0 );
        var_2[var_2.size] = var_4;
        var_0 = array_remove_index( var_0, var_4, 1 );
    }

    return var_2;
}

array_remove_index( var_0, var_1, var_2 )
{
    var_3 = [];

    foreach ( var_7, var_5 in var_0 )
    {
        if ( var_7 == var_1 )
            continue;

        if ( is_true( var_2 ) )
            var_6 = var_7;
        else
            var_6 = var_3.size;

        var_3[var_6] = var_5;
    }

    return var_3;
}

getrandomindex( var_0 )
{
    var_1 = 0;

    foreach ( var_3 in var_0 )
        var_1 = var_1 + var_3;

    var_5 = randomintrange( 0, var_1 );
    var_1 = 0;

    foreach ( var_7, var_3 in var_0 )
    {
        var_1 = var_1 + var_3;

        if ( var_5 <= var_1 )
            return var_7;
    }

    return 0;
}

_enableadditionalprimaryweapon()
{
    if ( !isdefined( self.numadditionalprimaries ) )
        self.numadditionalprimaries = 0;

    self.numadditionalprimaries++;
}

is_incompatible_weapon( var_0 )
{
    if ( isdefined( level.ammoincompatibleweaponslist ) )
    {
        if ( common_scripts\utility::array_contains( level.ammoincompatibleweaponslist, var_0 ) )
            return 1;
    }

    return 0;
}

is_door()
{
    return self.targetname == "stronghold_door_loc";
}

is_door_hive()
{
    return is_true( level.hive_is_really_a_door );
}

has_tag( var_0, var_1 )
{
    var_2 = getnumparts( var_0 );

    for ( var_3 = 0; var_3 < var_2; var_3++ )
    {
        if ( tolower( getpartname( var_0, var_3 ) ) == tolower( var_1 ) )
            return 1;
    }

    return 0;
}

level_uses_maaws()
{
    switch ( level.script )
    {
        case "mp_alien_beacon":
            return 1;
        default:
            break;
    }

    return 0;
}

is_flaming_stowed_riotshield_damage( var_0, var_1, var_2 )
{
    if ( isdefined( var_2 ) && is_trap( var_2 ) )
        return 0;

    if ( var_0 == "MOD_UNKNOWN" && var_1 != "none" )
        return 1;
    else
        return 0;
}

ark_attachment_transfer_to_locker_weapon( var_0, var_1, var_2 )
{
    var_3 = undefined;
    var_4 = maps\mp\_utility::getweaponattachmentsbasenames( var_0 );

    if ( isdefined( var_4[0] ) )
        var_5 = var_4[0];
    else
        var_5 = "none";

    if ( isdefined( var_4[1] ) )
        var_6 = var_4[1];
    else
        var_6 = "none";

    if ( isdefined( var_4[2] ) )
        var_7 = var_4[2];
    else
        var_7 = "none";

    if ( isdefined( var_4[3] ) )
        var_8 = var_4[3];
    else
        var_8 = "none";

    if ( is_true( var_2 ) )
    {
        foreach ( var_10 in var_1 )
        {
            var_10 = maps\mp\_utility::attachmentmap_tobase( var_10 );

            if ( var_10 == "alienmuzzlebrake" )
            {
                var_3 = 1;
                break;
            }
        }

        if ( is_true( var_3 ) )
        {
            var_12 = getweaponattachments( var_0 );

            for ( var_13 = 0; var_13 < var_12.size; var_13++ )
            {
                var_12[var_13] = replace_barrelrange_with_ark( var_12[var_13] );

                if ( var_13 == 0 )
                    var_5 = maps\mp\_utility::attachmentmap_tobase( var_12[var_13] );

                if ( var_13 == 1 )
                    var_6 = maps\mp\_utility::attachmentmap_tobase( var_12[var_13] );

                if ( var_13 == 2 )
                    var_7 = maps\mp\_utility::attachmentmap_tobase( var_12[var_13] );

                if ( var_13 == 3 )
                    var_8 = maps\mp\_utility::attachmentmap_tobase( var_12[var_13] );
            }
        }
    }

    var_14 = getweaponbasename( var_0 );
    var_15 = maps\mp\_utility::strip_suffix( var_14, "_mp" );
    var_16 = randomintrange( 1, 10 );

    if ( issubstr( var_14, "alienfp6" ) || issubstr( var_14, "alienmts255" ) || issubstr( var_14, "aliendlc12" ) || issubstr( var_14, "aliendlc13" ) || issubstr( var_14, "aliendlc14" ) || issubstr( var_14, "aliendlc15" ) || issubstr( var_14, "aliendlc23" ) || issubstr( var_14, "altalienlsat" ) || issubstr( var_14, "altaliensvu" ) || issubstr( var_14, "altalienarx" ) || issubstr( var_14, "arkalienr5rgp" ) || issubstr( var_14, "arkaliendlc15" ) || issubstr( var_14, "arkaliendlc23" ) || issubstr( var_14, "arkalienk7" ) || issubstr( var_14, "arkalienuts15" ) || issubstr( var_14, "arkalienmaul" ) || issubstr( var_14, "arkalienmk14" ) || issubstr( var_14, "arkalienimbel" ) || issubstr( var_14, "arkalienkac" ) || issubstr( var_14, "arkalienameli" ) )
        var_16 = 0;

    var_17 = randomintrange( 1, 7 );
    var_18 = undefined;

    if ( var_5 != "thermal" && var_5 != "thermalsmg" && var_6 != "thermal" && var_6 != "thermalsmg" && var_7 != "thermal" && var_7 != "thermalsmg" && var_8 != "thermal" && var_8 != "thermalsmg" && var_14 != "iw6_aliendlc23_mp" )
        var_0 = buildalienweaponname( var_15, var_5, var_6, var_7, var_8, var_16, var_17 );
    else
        var_0 = buildalienweaponname( var_15, var_5, var_6, var_7, var_8, var_16 );

    self.locker_weapon = var_0;
    return var_0;
}

replace_barrelrange_with_ark( var_0 )
{
    if ( isdefined( var_0 ) && common_scripts\utility::string_starts_with( var_0, "barrelrange" ) )
        return "alienmuzzlebrake";
    else
        return var_0;
}

return_weapon_with_like_attachments( var_0, var_1 )
{
    var_2 = getweaponbasename( var_0 );
    var_3 = self;
    var_4 = "none";
    var_5 = "none";
    var_6 = "none";
    var_7 = "none";
    var_8 = maps\mp\_utility::getweaponclass( var_2 );
    var_9 = maps\mp\alien\_pillage::get_possible_attachments_by_weaponclass( var_8, var_2 );
    var_10 = [];

    foreach ( var_12 in var_1 )
    {
        var_12 = maps\mp\_utility::attachmentmap_tobase( var_12 );

        if ( common_scripts\utility::array_contains( var_9, var_12 ) )
        {
            if ( var_3 maps\mp\alien\_persistence::is_upgrade_enabled( "keep_attachments_upgrade" ) )
            {
                var_10 = common_scripts\utility::array_add( var_10, var_12 );
                continue;
            }

            if ( var_12 == "alienmuzzlebrake" )
                var_10 = common_scripts\utility::array_add( var_10, var_12 );
        }
    }

    if ( var_10.size > 0 && var_10.size < 5 )
    {
        for ( var_14 = 0; var_14 < var_10.size; var_14++ )
        {
            if ( var_14 == 0 )
                var_4 = var_10[var_14];

            if ( var_14 == 1 )
                var_5 = var_10[var_14];

            if ( var_14 == 2 )
                var_6 = var_10[var_14];

            if ( var_14 == 3 )
                var_7 = var_10[var_14];
        }
    }

    var_15 = maps\mp\_utility::strip_suffix( var_2, "_mp" );
    var_16 = base_scope_weapon_attachment( var_15 );

    if ( isdefined( var_16 ) )
    {
        switch ( var_10.size + 1 )
        {
            case 1:
                var_4 = var_16;
                break;
            case 2:
                var_5 = var_16;
                break;
            case 3:
                var_6 = var_16;
                break;
            case 4:
                var_7 = var_16;
                break;
        }
    }

    var_17 = buildalienweaponname( var_15, var_4, var_5, var_6, var_7 );
    return var_17;
}

base_scope_weapon_attachment( var_0 )
{
    switch ( var_0 )
    {
        case "iw6_alienvks":
        case "iw6_arkalienvks":
            return "alienvksscope";
        case "iw6_alienusr":
        case "iw6_arkalienusr":
            return "usrvzscope";
        case "iw6_aliendlc23":
        case "iw6_arkaliendlc23":
            return "dlcweap02scope";
        case "iw6_alienl115a3":
            return "alienl115a3scope";
        default:
            break;
    }
}

can_hypno( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9 )
{
    if ( isdefined( self.cannothypno ) && self.cannothypno )
        return 0;

    switch ( self.alien_type )
    {
        case "seeder":
        case "locust":
        case "brute":
        case "spitter":
        case "goon":
            return 1;
        case "elite":
            if ( var_0 maps\mp\alien\_persistence::is_upgrade_enabled( "hypno_rhino_upgrade" ) || var_1 )
                return 1;
        default:
            return 0;
    }
}

has_fragile_relic_and_is_sprinting()
{
    if ( maps\mp\alien\_prestige::prestige_getslowhealthregenscalar() != 1.0 && self issprinting() )
        return 1;
    else
        return 0;
}

update_player_initial_spawn_info( var_0, var_1 )
{
    level.playerinitialspawnoriginoverride = var_0;
    level.playerinitialspawnanglesoverride = var_1;
}

get_player_initial_spawn_origin()
{
    return level.playerinitialspawnoriginoverride;
}

get_player_initial_spawn_angles()
{
    return level.playerinitialspawnanglesoverride;
}

has_pistols_only_relic_and_no_deployables()
{
    if ( maps\mp\alien\_prestige::prestige_getpistolsonly() == 1 && maps\mp\alien\_prestige::prestige_getnodeployables() == 1 )
        return 1;
    else
        return 0;
}

get_current_pistol()
{
    var_0 = self getweaponslistprimaries();

    foreach ( var_2 in var_0 )
    {
        var_3 = maps\mp\_utility::getweaponclass( var_2 );

        if ( var_3 == "weapon_pistol" )
            return var_2;
    }
}

is_idle_state_locked()
{
    return self.currentanimstate == "idle" && isdefined( self.idle_state_locked ) && self.idle_state_locked;
}

return_nerf_scaled_ammo( var_0 )
{
    var_1 = maps\mp\alien\_deployablebox_functions::check_for_nerf_min_ammo();
    var_2 = weaponmaxammo( var_0 );
    return int( var_2 * var_1 );
}

weapon_has_alien_attachment( var_0, var_1, var_2 )
{
    if ( !isdefined( var_0 ) || var_0 == "none" || weaponinventorytype( var_0 ) != "primary" || weaponclass( var_0 ) == "item" || weaponclass( var_0 ) == "rocketlauncher" || weaponclass( var_0 ) == "none" )
        return 0;

    if ( is_true( var_1 ) && is_holding_pistol( var_2 ) )
        return 0;

    var_3 = maps\mp\_utility::getweaponattachmentsbasenames( var_0 );

    foreach ( var_5 in var_3 )
    {
        if ( var_5 == "alienmuzzlebrake" || var_5 == "alienmuzzlebrakesg" || var_5 == "alienmuzzlebrakesn" )
            return 1;
    }

    return 0;
}

is_holding_pistol( var_0 )
{
    var_1 = var_0 getcurrentprimaryweapon();

    if ( maps\mp\_utility::getweaponclass( var_1 ) == "weapon_pistol" )
        return 1;
    else
        return 0;
}

setup_class_nameplates()
{
    var_0 = maps\mp\alien\_persistence::get_selected_perk_0();
    var_1 = undefined;

    switch ( var_0 )
    {
        case "perk_bullet_damage":
            var_1 = "player_name_bg_weapon_specialist";
            break;
        case "perk_health":
            var_1 = "player_name_bg_tank";
            break;
        case "perk_rigger":
            var_1 = "player_name_bg_engineer";
            break;
        case "perk_medic":
            var_1 = "player_name_bg_medic";
            break;
        case "perk_none":
            var_1 = "player_name_bg_mortal";
            break;
    }

    if ( isdefined( var_1 ) )
        self setnameplatematerial( var_1, var_1 );
}
