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

initkillstreakdata()
{
    var_0 = 1;

    for (;;)
    {
        var_1 = tablelookup( level.global_tables["killstreakTable"].path, level.global_tables["killstreakTable"].index_col, var_0, level.global_tables["killstreakTable"].ref_col );

        if ( !isdefined( var_1 ) || var_1 == "" )
            break;

        var_2 = tablelookup( level.global_tables["killstreakTable"].path, level.global_tables["killstreakTable"].index_col, var_0, level.global_tables["killstreakTable"].ref_col );
        var_3 = tablelookupistring( level.global_tables["killstreakTable"].path, level.global_tables["killstreakTable"].index_col, var_0, level.global_tables["killstreakTable"].earned_hint_col );
        var_4 = tablelookup( level.global_tables["killstreakTable"].path, level.global_tables["killstreakTable"].index_col, var_0, level.global_tables["killstreakTable"].earned_dialog_col );
        game["dialog"][var_2] = var_4;
        var_5 = tablelookup( level.global_tables["killstreakTable"].path, level.global_tables["killstreakTable"].index_col, var_0, level.global_tables["killstreakTable"].allies_dialog_col );
        game["dialog"]["allies_friendly_" + var_2 + "_inbound"] = "friendly_" + var_5;
        game["dialog"]["allies_enemy_" + var_2 + "_inbound"] = "enemy_" + var_5;
        var_6 = tablelookup( level.global_tables["killstreakTable"].path, level.global_tables["killstreakTable"].index_col, var_0, level.global_tables["killstreakTable"].enemy_dialog_col );
        game["dialog"]["axis_friendly_" + var_2 + "_inbound"] = "friendly_" + var_6;
        game["dialog"]["axis_enemy_" + var_2 + "_inbound"] = "enemy_" + var_6;
        var_7 = int( tablelookup( level.global_tables["killstreakTable"].path, level.global_tables["killstreakTable"].index_col, var_0, level.global_tables["killstreakTable"].score_col ) );
        maps\mp\gametypes\_rank::registerscoreinfo( "killstreak_" + var_2, var_7 );
        var_0++;
    }
}

onplayerconnect()
{
    for (;;)
    {
        level waittill( "connected", var_0 );

        if ( !isdefined( var_0.pers["killstreaks"] ) )
            var_0.pers["killstreaks"] = [];

        if ( !isdefined( var_0.pers["kID"] ) )
            var_0.pers["kID"] = 10;

        var_0.lifeid = 0;
        var_0.curdefvalue = 0;

        if ( isdefined( var_0.pers["deaths"] ) )
            var_0.lifeid = var_0.pers["deaths"];

        var_0 visionsetmissilecamforplayer( game["thermal_vision"] );
        var_0 thread onplayerspawned();
        var_0 thread monitordisownkillstreaks();
        var_0.spupdatetotal = 0;
    }
}

onplayerspawned()
{
    self endon( "disconnect" );

    if ( maps\mp\_utility::is_aliens() )
        return;

    for (;;)
    {
        self waittill( "spawned_player" );
        thread killstreakusewaiter();
        thread waitforchangeteam();
        thread streakselectuptracker();
        thread streakselectdowntracker();

        if ( level.console )
            thread streakusetimetracker();
        else
        {
            thread pc_watchstreakuse();
            thread pc_watchgamepad();
        }

        thread streaknotifytracker();

        if ( !isdefined( self.pers["killstreaks"][0] ) )
            initplayerkillstreaks();

        if ( !isdefined( self.earnedstreaklevel ) )
            self.earnedstreaklevel = 0;

        if ( game["roundsPlayed"] > 0 && self.adrenaline == 0 )
            self.adrenaline = self getcommonplayerdata( "killstreaksState", "count" );

        setstreakcounttonext();
        updatestreakslots();

        if ( self.streaktype == "specialist" )
        {
            updatespecialistkillstreaks();
            continue;
        }

        giveownedkillstreakitem();
    }
}

initplayerkillstreaks()
{
    if ( !isdefined( self.streaktype ) )
        return;

    if ( self.streaktype == "specialist" )
        self setcommonplayerdata( "killstreaksState", "isSpecialist", 1 );
    else
        self setcommonplayerdata( "killstreaksState", "isSpecialist", 0 );

    var_0 = spawnstruct();
    var_0.available = 0;
    var_0.streakname = undefined;
    var_0.earned = 0;
    var_0.awardxp = undefined;
    var_0.owner = undefined;
    var_0.kid = undefined;
    var_0.lifeid = undefined;
    var_0.isgimme = 1;
    var_0.isspecialist = 0;
    var_0.nextslot = undefined;
    self.pers["killstreaks"][0] = var_0;

    for ( var_1 = 1; var_1 < 4; var_1++ )
    {
        var_2 = spawnstruct();
        var_2.available = 0;
        var_2.streakname = undefined;
        var_2.earned = 1;
        var_2.awardxp = 1;
        var_2.owner = undefined;
        var_2.kid = undefined;
        var_2.lifeid = -1;
        var_2.isgimme = 0;
        var_2.isspecialist = 0;
        self.pers["killstreaks"][var_1] = var_2;
    }

    var_3 = spawnstruct();
    var_3.available = 0;
    var_3.streakname = "all_perks_bonus";
    var_3.earned = 1;
    var_3.awardxp = 0;
    var_3.owner = undefined;
    var_3.kid = undefined;
    var_3.lifeid = -1;
    var_3.isgimme = 0;
    var_3.isspecialist = 1;
    self.pers["killstreaks"][4] = var_3;

    for ( var_1 = 0; var_1 < 4; var_1++ )
    {
        self setcommonplayerdata( "killstreaksState", "icons", var_1, 0 );
        self setcommonplayerdata( "killstreaksState", "hasStreak", var_1, 0 );
    }

    self setcommonplayerdata( "killstreaksState", "hasStreak", 0, 0 );
    var_4 = 1;

    foreach ( var_6 in self.killstreaks )
    {
        var_7 = self.pers["killstreaks"][var_4];
        var_7.streakname = var_6;
        var_7.isspecialist = self.streaktype == "specialist";
        var_8 = var_7.streakname;

        if ( self.streaktype == "specialist" )
        {
            var_9 = strtok( var_7.streakname, "_" );

            if ( var_9[var_9.size - 1] == "ks" )
            {
                var_10 = undefined;

                foreach ( var_12 in var_9 )
                {
                    if ( var_12 != "ks" )
                    {
                        if ( !isdefined( var_10 ) )
                        {
                            var_10 = var_12;
                            continue;
                        }

                        var_10 = var_10 + ( "_" + var_12 );
                    }
                }

                if ( maps\mp\_utility::isstrstart( var_7.streakname, "_" ) )
                    var_10 = "_" + var_10;

                if ( isdefined( var_10 ) && maps\mp\gametypes\_class::getperkupgrade( var_10 ) != "specialty_null" )
                    var_8 = var_7.streakname + "_pro";
            }
        }

        self setcommonplayerdata( "killstreaksState", "icons", var_4, maps\mp\_utility::getkillstreakindex( var_8 ) );
        self setcommonplayerdata( "killstreaksState", "hasStreak", var_4, 0 );
        var_4++;
    }

    self setcommonplayerdata( "killstreaksState", "nextIndex", 1 );
    self setcommonplayerdata( "killstreaksState", "selectedIndex", -1 );
    self setcommonplayerdata( "killstreaksState", "numAvailable", 0 );
    self setcommonplayerdata( "killstreaksState", "hasStreak", 4, 0 );
}

updatestreakcount()
{
    if ( !isdefined( self.pers["killstreaks"] ) )
        return;

    if ( self.adrenaline == self.previousadrenaline )
        return;

    var_0 = self.adrenaline;
    self setcommonplayerdata( "killstreaksState", "count", self.adrenaline );

    if ( self.adrenaline >= self getcommonplayerdata( "killstreaksState", "countToNext" ) )
        setstreakcounttonext();
}

resetstreakcount()
{
    self setcommonplayerdata( "killstreaksState", "count", 0 );
    setstreakcounttonext();
}

setstreakcounttonext()
{
    if ( !isdefined( self.streaktype ) )
    {
        self setcommonplayerdata( "killstreaksState", "countToNext", 0 );
        return;
    }

    if ( getmaxstreakcost() == 0 )
    {
        self setcommonplayerdata( "killstreaksState", "countToNext", 0 );
        return;
    }

    if ( self.streaktype == "specialist" )
    {
        if ( self.adrenaline >= getmaxstreakcost() )
            return;
    }

    var_0 = getnextstreakname();

    if ( !isdefined( var_0 ) )
        return;

    var_1 = getstreakcost( var_0 );
    self setcommonplayerdata( "killstreaksState", "countToNext", var_1 );
}

getnextstreakname()
{
    if ( self.adrenaline == getmaxstreakcost() && self.streaktype != "specialist" )
        var_0 = 0;
    else
        var_0 = self.adrenaline;

    foreach ( var_2 in self.killstreaks )
    {
        var_3 = getstreakcost( var_2 );

        if ( var_3 > var_0 )
            return var_2;
    }

    return undefined;
}

getmaxstreakcost()
{
    var_0 = 0;

    foreach ( var_2 in self.killstreaks )
    {
        var_3 = getstreakcost( var_2 );

        if ( var_3 > var_0 )
            var_0 = var_3;
    }

    return var_0;
}

updatestreakslots()
{
    if ( !isdefined( self.streaktype ) )
        return;

    if ( !maps\mp\_utility::isreallyalive( self ) )
        return;

    var_0 = self.pers["killstreaks"];
    var_1 = 0;

    for ( var_2 = 0; var_2 < 4; var_2++ )
    {
        if ( isdefined( var_0[var_2] ) && isdefined( var_0[var_2].streakname ) )
        {
            self setcommonplayerdata( "killstreaksState", "hasStreak", var_2, var_0[var_2].available );

            if ( var_0[var_2].available == 1 )
                var_1++;

            if ( isdefined( level.removekillstreakicons ) && level.removekillstreakicons && !var_0[var_2].available )
                self setcommonplayerdata( "killstreaksState", "icons", var_2, 0 );
        }
    }

    if ( self.streaktype != "specialist" )
        self setcommonplayerdata( "killstreaksState", "numAvailable", var_1 );

    var_3 = self.earnedstreaklevel;
    var_4 = getmaxstreakcost();

    if ( self.earnedstreaklevel == var_4 && self.streaktype != "specialist" )
        var_3 = 0;

    var_5 = 1;

    foreach ( var_7 in self.killstreaks )
    {
        var_8 = getstreakcost( var_7 );

        if ( var_8 > var_3 )
        {
            var_9 = var_7;
            break;
        }

        if ( self.streaktype == "specialist" )
        {
            if ( self.earnedstreaklevel == var_4 )
                break;
        }

        var_5++;
    }

    self setcommonplayerdata( "killstreaksState", "nextIndex", var_5 );

    if ( isdefined( self.killstreakindexweapon ) && self.streaktype != "specialist" )
        self setcommonplayerdata( "killstreaksState", "selectedIndex", self.killstreakindexweapon );
    else if ( self.streaktype == "specialist" && var_0[0].available )
        self setcommonplayerdata( "killstreaksState", "selectedIndex", 0 );
    else
        self setcommonplayerdata( "killstreaksState", "selectedIndex", -1 );
}

waitforchangeteam()
{
    self endon( "disconnect" );
    self endon( "faux_spawn" );
    self notify( "waitForChangeTeam" );
    self endon( "waitForChangeTeam" );

    for (;;)
    {
        self waittill( "joined_team" );
        clearkillstreaks();
    }
}

killstreakusepressed()
{
    var_0 = self.pers["killstreaks"];
    var_1 = var_0[self.killstreakindexweapon].streakname;
    var_2 = var_0[self.killstreakindexweapon].lifeid;
    var_3 = var_0[self.killstreakindexweapon].earned;
    var_4 = var_0[self.killstreakindexweapon].awardxp;
    var_5 = var_0[self.killstreakindexweapon].kid;
    var_6 = var_0[self.killstreakindexweapon].isgimme;

    if ( !maps\mp\_utility::validateusestreak() )
        return 0;

    if ( !self [[ level.killstreakfuncs[var_1] ]]( var_2, var_1 ) )
        return 0;

    thread updatekillstreaks();
    usedkillstreak( var_1, var_4 );
    return 1;
}

usedkillstreak( var_0, var_1 )
{
    if ( var_1 )
    {
        self thread [[ level.onxpevent ]]( "killstreak_" + var_0 );
        thread maps\mp\gametypes\_missions::usehardpoint( var_0 );
    }

    var_2 = maps\mp\_awards::getkillstreakawardref( var_0 );

    if ( isdefined( var_2 ) )
        thread maps\mp\_utility::incplayerstat( var_2, 1 );

    if ( maps\mp\_utility::isassaultkillstreak( var_0 ) )
        thread maps\mp\_utility::incplayerstat( "assaultkillstreaksused", 1 );
    else if ( maps\mp\_utility::issupportkillstreak( var_0 ) )
        thread maps\mp\_utility::incplayerstat( "supportkillstreaksused", 1 );
    else if ( maps\mp\_utility::isspecialistkillstreak( var_0 ) )
    {
        thread maps\mp\_utility::incplayerstat( "specialistkillstreaksearned", 1 );
        return;
    }

    var_3 = self.team;

    if ( level.teambased )
    {
        thread maps\mp\_utility::leaderdialog( var_3 + "_friendly_" + var_0 + "_inbound", var_3 );

        if ( maps\mp\_utility::getkillstreakenemyusedialog( var_0 ) )
        {
            if ( playenemydialog( var_0 ) )
                thread maps\mp\_utility::leaderdialog( var_3 + "_enemy_" + var_0 + "_inbound", level.otherteam[var_3] );
        }
    }
    else
    {
        thread maps\mp\_utility::leaderdialogonplayer( var_3 + "_friendly_" + var_0 + "_inbound" );

        if ( maps\mp\_utility::getkillstreakenemyusedialog( var_0 ) )
        {
            var_4[0] = self;

            if ( playenemydialog( var_0 ) )
                thread maps\mp\_utility::leaderdialog( var_3 + "_enemy_" + var_0 + "_inbound", undefined, undefined, var_4 );
        }
    }
}

playenemydialog( var_0 )
{
    if ( !maps\mp\_utility::is_aliens() )
    {
        if ( level.teambased && var_0 == "uplink" && [[ level.comexpfuncs["getRadarStrengthForTeam"] ]]( self.team ) != 1 )
            return 0;
        else if ( !level.teambased && var_0 == "uplink" && [[ level.comexpfuncs["getRadarStrengthForPlayer"] ]]( self ) != 2 )
            return 0;
    }

    return 1;
}

updatekillstreaks( var_0 )
{
    if ( isai( self ) && !isdefined( self.killstreakindexweapon ) )
        return;

    if ( !isdefined( var_0 ) )
    {
        self.pers["killstreaks"][self.killstreakindexweapon].available = 0;

        if ( self.killstreakindexweapon == 0 )
        {
            self.pers["killstreaks"][self.pers["killstreaks"][0].nextslot] = undefined;
            var_1 = undefined;
            var_2 = undefined;
            var_3 = self.pers["killstreaks"];

            for ( var_4 = 5; var_4 < var_3.size; var_4++ )
            {
                if ( !isdefined( var_3[var_4] ) || !isdefined( var_3[var_4].streakname ) )
                    continue;

                var_1 = var_3[var_4].streakname;
                var_2 = var_3[var_4].kid;
                var_3[0].nextslot = var_4;
            }

            if ( isdefined( var_1 ) )
            {
                var_3[0].available = 1;
                var_3[0].streakname = var_1;
                var_3[0].kid = var_2;
                var_5 = maps\mp\_utility::getkillstreakindex( var_1 );
                self setcommonplayerdata( "killstreaksState", "icons", 0, var_5 );

                if ( !level.console && !common_scripts\utility::is_player_gamepad_enabled() )
                {
                    var_6 = maps\mp\_utility::getkillstreakweapon( var_1 );
                    maps\mp\_utility::_setactionslot( 4, "weapon", var_6 );
                }
            }
        }
    }

    var_7 = undefined;

    if ( self.streaktype == "specialist" )
    {
        if ( self.pers["killstreaks"][0].available )
            var_7 = 0;
    }
    else
    {
        for ( var_4 = 0; var_4 < 4; var_4++ )
        {
            var_8 = self.pers["killstreaks"][var_4];

            if ( isdefined( var_8 ) && isdefined( var_8.streakname ) && var_8.available )
                var_7 = var_4;
        }
    }

    if ( isdefined( var_7 ) )
    {
        if ( level.console || common_scripts\utility::is_player_gamepad_enabled() )
        {
            self.killstreakindexweapon = var_7;
            self.pers["lastEarnedStreak"] = self.pers["killstreaks"][var_7].streakname;
            giveselectedkillstreakitem();
        }
        else
        {
            for ( var_4 = 0; var_4 < 4; var_4++ )
            {
                var_8 = self.pers["killstreaks"][var_4];

                if ( isdefined( var_8 ) && isdefined( var_8.streakname ) && var_8.available )
                {
                    var_6 = maps\mp\_utility::getkillstreakweapon( var_8.streakname );
                    var_9 = self getweaponslistitems();
                    var_10 = 0;

                    for ( var_11 = 0; var_11 < var_9.size; var_11++ )
                    {
                        if ( var_6 == var_9[var_11] )
                        {
                            var_10 = 1;
                            break;
                        }
                    }

                    if ( !var_10 )
                        maps\mp\_utility::_giveweapon( var_6 );
                    else if ( issubstr( var_6, "airdrop_" ) )
                        self setweaponammoclip( var_6, 1 );

                    maps\mp\_utility::_setactionslot( var_4 + 4, "weapon", var_6 );
                }
            }

            self.killstreakindexweapon = undefined;
            self.pers["lastEarnedStreak"] = self.pers["killstreaks"][var_7].streakname;
            updatestreakslots();
        }
    }
    else
    {
        self.killstreakindexweapon = undefined;
        self.pers["lastEarnedStreak"] = undefined;
        updatestreakslots();
    }
}

clearkillstreaks()
{
    var_0 = self.pers["killstreaks"];

    if ( !isdefined( var_0 ) )
        return;

    for ( var_1 = var_0.size - 1; var_1 > -1; var_1-- )
        self.pers["killstreaks"][var_1] = undefined;

    initplayerkillstreaks();
    resetadrenaline();
    self.killstreakindexweapon = undefined;
    updatestreakslots();
}

updatespecialistkillstreaks()
{
    if ( self.adrenaline == 0 )
    {
        for ( var_0 = 1; var_0 < 4; var_0++ )
        {
            if ( isdefined( self.pers["killstreaks"][var_0] ) )
            {
                self.pers["killstreaks"][var_0].available = 0;
                self setcommonplayerdata( "killstreaksState", "hasStreak", var_0, 0 );
            }
        }

        self setcommonplayerdata( "killstreaksState", "nextIndex", 1 );
        self setcommonplayerdata( "killstreaksState", "hasStreak", 4, 0 );
    }
    else
    {
        for ( var_0 = 1; var_0 < 4; var_0++ )
        {
            var_1 = self.pers["killstreaks"][var_0];

            if ( isdefined( var_1 ) && isdefined( var_1.streakname ) && var_1.available )
            {
                var_2 = getstreakcost( var_1.streakname );

                if ( var_2 > self.adrenaline )
                {
                    self.pers["killstreaks"][var_0].available = 0;
                    self setcommonplayerdata( "killstreaksState", "hasStreak", var_0, 0 );
                    continue;
                }

                if ( self.adrenaline >= var_2 )
                {
                    if ( self getcommonplayerdata( "killstreaksState", "hasStreak", var_0 ) )
                    {
                        self [[ level.killstreakfuncs[var_1.streakname] ]]( undefined, var_1.streakname );
                        continue;
                    }

                    givekillstreak( var_1.streakname, var_1.earned, 0, self );
                }
            }
        }

        var_3 = getmaxstreakcost();

        if ( isai( self ) )
            var_3 = self.pers["specialistStreakKills"][2];

        var_4 = int( max( 8, var_3 + 2 ) );

        if ( maps\mp\_utility::_hasperk( "specialty_hardline" ) )
            var_4--;

        if ( self.adrenaline >= var_4 )
        {
            self setcommonplayerdata( "killstreaksState", "hasStreak", 4, 1 );
            givebonusperks();
        }
        else
            self setcommonplayerdata( "killstreaksState", "hasStreak", 4, 0 );
    }

    if ( self.pers["killstreaks"][0].available )
    {
        var_5 = self.pers["killstreaks"][0].streakname;
        var_6 = maps\mp\_utility::getkillstreakweapon( var_5 );

        if ( level.console || common_scripts\utility::is_player_gamepad_enabled() )
        {
            givekillstreakweapon( var_6 );
            self.killstreakindexweapon = 0;
        }
        else
        {
            maps\mp\_utility::_giveweapon( var_6 );
            maps\mp\_utility::_setactionslot( 4, "weapon", var_6 );
            self.killstreakindexweapon = undefined;
        }
    }
}

getfirstprimaryweapon()
{
    var_0 = self getweaponslistprimaries();
    return var_0[0];
}

istryingtousekillstreakingimmeslot()
{
    return isdefined( self.tryingtouseks ) && self.tryingtouseks && isdefined( self.killstreakindexweapon ) && self.killstreakindexweapon == 0;
}

istryingtousekillstreakslot()
{
    return isdefined( self.tryingtouseks ) && self.tryingtouseks && isdefined( self.killstreakindexweapon );
}

waitforkillstreakweaponswitchstarted()
{
    self endon( "weapon_switch_invalid" );
    self waittill( "weapon_switch_started", var_0 );
    self notify( "killstreak_weapon_change", "switch_started", var_0 );
}

waitforkillstreakweaponswitchinvalid()
{
    self endon( "weapon_switch_started" );
    self waittill( "weapon_switch_invalid", var_0 );
    self notify( "killstreak_weapon_change", "switch_invalid", var_0 );
}

waitforkillstreakweaponchange()
{
    childthread waitforkillstreakweaponswitchstarted();
    childthread waitforkillstreakweaponswitchinvalid();
    self waittill( "killstreak_weapon_change", var_0, var_1 );

    if ( var_0 == "switch_started" )
        return var_1;

    var_2 = maps\mp\_utility::getkillstreakweapon( self.pers["killstreaks"][self.killstreakindexweapon].streakname );
    self switchtoweapon( var_2 );
    waittillframeend;
    var_3 = undefined;

    if ( isdefined( self.changingweapon ) )
        var_3 = self.changingweapon;
    else
        self waittill( "weapon_switch_started", var_3 );

    if ( var_3 != var_2 )
        return undefined;

    return var_2;
}

killstreakusewaiter()
{
    self endon( "disconnect" );
    self endon( "finish_death" );
    self endon( "joined_team" );
    self endon( "faux_spawn" );
    self endon( "spawned" );
    level endon( "game_ended" );
    self notify( "killstreakUseWaiter" );
    self endon( "killstreakUseWaiter" );
    self.lastkillstreak = 0;

    if ( !isdefined( self.pers["lastEarnedStreak"] ) )
        self.pers["lastEarnedStreak"] = undefined;

    thread finishdeathwaiter();
    var_0 = [ "streakUsed", "streakUsed1", "streakUsed2", "streakUsed3", "streakUsed4" ];

    for (;;)
    {
        self.tryingtouseks = undefined;
        var_1 = common_scripts\utility::waittill_any_in_array_return_no_endon_death( var_0 );
        self.tryingtouseks = 1;
        waittillframeend;

        if ( !isdefined( self.killstreakindexweapon ) || !isdefined( self.pers["killstreaks"][self.killstreakindexweapon] ) || !isdefined( self.pers["killstreaks"][self.killstreakindexweapon].streakname ) )
            continue;

        if ( !maps\mp\_utility::cancustomjuggusekillstreak( self.pers["killstreaks"][self.killstreakindexweapon].streakname ) )
        {
            maps\mp\_utility::printcustomjuggkillstreakerrormsg();

            if ( var_1 != "streakUsed" )
            {
                var_2 = self getcurrentweapon();
                maps\mp\_utility::switch_to_last_weapon( var_2 );
            }

            continue;
        }

        if ( self isoffhandweaponreadytothrow() )
            continue;

        if ( isdefined( self.changingweapon ) )
            var_3 = self.changingweapon;
        else
            self waittill( "weapon_switch_started", var_3 );

        var_4 = maps\mp\_utility::getkillstreakweapon( self.pers["killstreaks"][self.killstreakindexweapon].streakname );

        if ( var_3 != var_4 )
        {
            thread removeunitializedkillstreakweapon();
            continue;
        }

        beginkillstreakweaponswitch();

        if ( var_3 != self getcurrentweapon() )
        {
            thread killstreakwaitforweaponchange();
            var_5 = common_scripts\utility::waittill_any_timeout_no_endon_death( 1.5, "ks_weapon_change", "ks_alt_weapon_change" );

            if ( var_5 == "ks_alt_weapon_change" )
                self waittill( "weapon_change", var_3, var_6 );
            else
                var_3 = self getcurrentweapon();
        }

        if ( !isalive( self ) )
        {
            endkillstreakweaponswitch();
            continue;
        }

        if ( var_3 != var_4 )
        {
            var_7 = self.lastdroppableweapon;

            if ( maps\mp\_utility::iskillstreakweapon( var_3 ) )
            {
                if ( maps\mp\_utility::isjuggernaut() && maps\mp\_utility::isjuggernautweapon( var_3 ) )
                    var_7 = var_3;
                else if ( var_3 == "iw6_gm6helisnipe_mp_gm6scope" )
                    var_7 = var_3;
                else
                    self takeweapon( var_3 );
            }

            self switchtoweapon( var_7 );
            endkillstreakweaponswitch();
            continue;
        }

        self.ks_abouttouse = 1;
        waittillframeend;
        self.ks_abouttouse = undefined;
        var_8 = self.pers["killstreaks"][self.killstreakindexweapon].streakname;
        var_9 = self.pers["killstreaks"][self.killstreakindexweapon].isgimme;
        endkillstreakweaponswitch();
        var_5 = killstreakusepressed();
        beginkillstreakweaponswitch();
        var_2 = common_scripts\utility::getlastweapon();

        if ( !self hasweapon( var_2 ) )
        {
            if ( maps\mp\_utility::isreallyalive( self ) )
                var_2 = getfirstprimaryweapon();
            else
                maps\mp\_utility::_giveweapon( var_2 );
        }

        if ( var_5 )
            thread waittakekillstreakweapon( var_4, var_2 );

        if ( shouldswitchweaponpostkillstreak( var_5, var_8 ) )
            maps\mp\_utility::switch_to_last_weapon( var_2 );

        var_10 = self getcurrentweapon();

        while ( var_10 != var_2 )
            self waittill( "weapon_change", var_10 );

        endkillstreakweaponswitch();
    }
}

removeunitializedkillstreakweapon()
{
    self notify( "removeUnitializedKillstreakWeapon" );
    self endon( "removeUnitializedKillstreakWeapon" );
    self endon( "death" );
    self endon( "disconnect" );
    self waittill( "weapon_change", var_0 );
    var_1 = isdefined( self.killstreakindexweapon ) && isdefined( self.pers["killstreaks"] ) && isdefined( self.pers["killstreaks"][self.killstreakindexweapon] ) && isdefined( self.pers["killstreaks"][self.killstreakindexweapon].streakname ) && var_0 == maps\mp\_utility::getkillstreakweapon( self.pers["killstreaks"][self.killstreakindexweapon].streakname );

    if ( var_1 && !isdefined( self.ks_abouttouse ) )
    {
        self takeweapon( var_0 );
        maps\mp\_utility::_giveweapon( var_0, 0 );
        maps\mp\_utility::_setactionslot( 4, "weapon", var_0 );
        var_2 = common_scripts\utility::getlastweapon();

        if ( !self hasweapon( var_2 ) )
            var_2 = getfirstprimaryweapon();

        if ( isdefined( var_2 ) )
            maps\mp\_utility::switch_to_last_weapon( var_2 );
    }
}

beginkillstreakweaponswitch()
{
    common_scripts\utility::_disableweaponswitch();
    common_scripts\utility::_disableusability();
    thread killstreakweaponswitchwatchhostmigration();
}

endkillstreakweaponswitch()
{
    self notify( "endKillstreakWeaponSwitch" );
    common_scripts\utility::_enableweaponswitch();
    common_scripts\utility::_enableusability();
}

killstreakwaitforweaponchange()
{
    self waittill( "weapon_change", var_0, var_1 );

    if ( !var_1 )
        self notify( "ks_weapon_change" );
    else
        self notify( "ks_alt_weapon_change" );
}

killstreakweaponswitchwatchhostmigration()
{
    self endon( "death" );
    level endon( "game_ended" );
    self endon( "endKillstreakWeaponSwitch" );
    level waittill( "host_migration_end" );

    if ( isdefined( self ) )
        self enableweaponswitch();
}

waittakekillstreakweapon( var_0, var_1 )
{
    self endon( "disconnect" );
    self endon( "finish_death" );
    self endon( "joined_team" );
    level endon( "game_ended" );
    self notify( "waitTakeKillstreakWeapon" );
    self endon( "waitTakeKillstreakWeapon" );
    var_2 = self getcurrentweapon() == "none";
    self waittill( "weapon_change", var_3 );

    if ( var_3 == var_1 )
    {
        takekillstreakweaponifnodupe( var_0 );

        if ( !level.console && !common_scripts\utility::is_player_gamepad_enabled() )
            self.killstreakindexweapon = undefined;
    }
    else if ( var_3 != var_0 )
        thread waittakekillstreakweapon( var_0, var_1 );
    else if ( var_2 && self getcurrentweapon() == var_0 )
        thread waittakekillstreakweapon( var_0, var_1 );
}

takekillstreakweaponifnodupe( var_0 )
{
    var_1 = 0;
    var_2 = self.pers["killstreaks"];

    for ( var_3 = 0; var_3 < var_2.size; var_3++ )
    {
        if ( isdefined( var_2[var_3] ) && isdefined( var_2[var_3].streakname ) && var_2[var_3].available )
        {
            if ( !maps\mp\_utility::isspecialistkillstreak( var_2[var_3].streakname ) && var_0 == maps\mp\_utility::getkillstreakweapon( var_2[var_3].streakname ) )
            {
                var_1 = 1;
                break;
            }
        }
    }

    if ( var_1 )
    {
        if ( level.console || common_scripts\utility::is_player_gamepad_enabled() )
        {
            if ( isdefined( self.killstreakindexweapon ) && var_0 != maps\mp\_utility::getkillstreakweapon( var_2[self.killstreakindexweapon].streakname ) )
                self takeweapon( var_0 );
            else if ( isdefined( self.killstreakindexweapon ) && var_0 == maps\mp\_utility::getkillstreakweapon( var_2[self.killstreakindexweapon].streakname ) )
            {
                self takeweapon( var_0 );
                maps\mp\_utility::_giveweapon( var_0, 0 );
                maps\mp\_utility::_setactionslot( 4, "weapon", var_0 );
            }
        }
        else
        {
            self takeweapon( var_0 );
            maps\mp\_utility::_giveweapon( var_0, 0 );
        }
    }
    else
    {
        if ( var_0 == "" )
            return;

        self takeweapon( var_0 );
    }
}

shouldswitchweaponpostkillstreak( var_0, var_1 )
{
    if ( !var_0 )
        return 1;

    if ( maps\mp\_utility::isridekillstreak( var_1 ) )
        return 0;

    return 1;
}

finishdeathwaiter()
{
    self endon( "disconnect" );
    level endon( "game_ended" );
    self notify( "finishDeathWaiter" );
    self endon( "finishDeathWaiter" );
    self waittill( "death" );
    wait 0.05;
    self notify( "finish_death" );
    self.pers["lastEarnedStreak"] = undefined;
}

checkstreakreward()
{
    foreach ( var_1 in self.killstreaks )
    {
        var_2 = getstreakcost( var_1 );

        if ( var_2 > self.adrenaline )
            break;

        if ( self.previousadrenaline < var_2 && self.adrenaline >= var_2 )
        {
            earnkillstreak( var_1, var_2 );
            break;
        }
    }
}

killstreakearned( var_0 )
{
    var_1 = "assault";

    switch ( self.streaktype )
    {
        case "assault":
            var_1 = "assaultStreaks";
            break;
        case "support":
            var_1 = "supportStreaks";
            break;
        case "specialist":
            var_1 = "specialistStreaks";
            break;
    }

    if ( isdefined( self.class_num ) )
    {
        if ( self getcacplayerdata( "loadouts", self.class_num, var_1, 0 ) == var_0 )
            self.firstkillstreakearned = gettime();
        else if ( self getcacplayerdata( "loadouts", self.class_num, var_1, 2 ) == var_0 && isdefined( self.firstkillstreakearned ) )
        {
            if ( gettime() - self.firstkillstreakearned < 20000 )
                thread maps\mp\gametypes\_missions::genericchallenge( "wargasm" );
        }
    }
}

earnkillstreak( var_0, var_1 )
{
    level notify( "gave_killstreak", var_0 );
    self.earnedstreaklevel = var_1;

    if ( !level.gameended )
    {
        var_2 = undefined;

        if ( self.streaktype == "specialist" )
        {
            var_3 = getsubstr( var_0, 0, var_0.size - 3 );

            if ( maps\mp\gametypes\_class::isperkupgraded( var_3 ) )
                var_2 = "pro";
        }

        thread maps\mp\gametypes\_hud_message::killstreaksplashnotify( var_0, var_1, var_2 );

        if ( maps\mp\_utility::bot_is_fireteam_mode() )
        {
            if ( isdefined( var_2 ) )
                self notify( "bot_killstreak_earned", var_0 + "_" + var_2, var_1 );
            else
                self notify( "bot_killstreak_earned", var_0, var_1 );
        }
    }

    thread killstreakearned( var_0 );
    self.pers["lastEarnedStreak"] = var_0;
    setstreakcounttonext();
    givekillstreak( var_0, 1, 1 );
}

givekillstreak( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    self endon( "joined_team" );
    self endon( "givingLoadout" );
    self endon( "disconnect" );

    if ( !isdefined( var_5 ) )
    {
        var_5 = self.pers["kID"];
        self.pers["kID"]++;
    }

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

    if ( self.team == "spectator" )
        return;

    var_6 = undefined;

    if ( !isdefined( var_1 ) || var_1 == 0 )
    {
        if ( isdefined( var_4 ) )
            var_7 = var_4;
        else
            var_7 = self.pers["killstreaks"].size;

        if ( !isdefined( self.pers["killstreaks"][var_7] ) )
            self.pers["killstreaks"][var_7] = spawnstruct();

        var_8 = 1;

        if ( var_7 > 5 && istryingtousekillstreakingimmeslot() )
        {
            var_8 = 0;
            var_9 = var_7;
            var_10 = var_7 - 1;
            var_11 = self.pers["killstreaks"][var_10];
            var_12 = self.pers["killstreaks"][var_9];
            var_12.available = var_11.available;
            var_12.streakname = var_11.streakname;
            var_12.earned = var_11.earned;
            var_12.awardxp = var_11.awardxp;
            var_12.owner = var_11.owner;
            var_12.kid = var_11.kid;
            var_12.lifeid = var_11.lifeid;
            var_12.isgimme = var_11.isgimme;
            var_12.isspecialist = var_11.isspecialist;
            var_7 = var_10;
        }

        var_13 = self.pers["killstreaks"][var_7];
        var_13.available = 0;
        var_13.streakname = var_0;
        var_13.earned = 0;
        var_13.awardxp = isdefined( var_2 ) && var_2;
        var_13.owner = var_3;
        var_13.kid = var_5;
        var_13.lifeid = -1;
        var_13.isgimme = 1;
        var_13.isspecialist = 0;

        if ( !var_8 )
        {
            self.pers["killstreaks"][0].nextslot = var_7 + 1;
            return;
        }

        if ( !isdefined( var_4 ) )
            var_4 = 0;

        self.pers["killstreaks"][var_4].nextslot = var_7;
        self.pers["killstreaks"][var_4].streakname = var_0;
        var_6 = var_4;
        var_14 = maps\mp\_utility::getkillstreakindex( var_0 );
        self setcommonplayerdata( "killstreaksState", "icons", var_4, var_14 );
    }
    else
    {
        for ( var_15 = 1; var_15 < 4; var_15++ )
        {
            var_16 = self.pers["killstreaks"][var_15];

            if ( isdefined( var_16 ) && isdefined( var_16.streakname ) && var_0 == var_16.streakname )
            {
                var_6 = var_15;
                break;
            }
        }

        if ( !isdefined( var_6 ) )
            return;
    }

    var_17 = self.pers["killstreaks"][var_6];
    var_17.available = 1;
    var_17.earned = isdefined( var_1 ) && var_1;
    var_17.awardxp = isdefined( var_2 ) && var_2;
    var_17.owner = var_3;
    var_17.kid = var_5;

    if ( !var_17.earned )
        var_17.lifeid = -1;
    else
        var_17.lifeid = self.pers["deaths"];

    if ( self.streaktype == "specialist" && var_6 != 0 )
    {
        var_17.isspecialist = 1;

        if ( isdefined( level.killstreakfuncs[var_0] ) )
            self [[ level.killstreakfuncs[var_0] ]]( -1, var_0 );

        usedkillstreak( var_0, var_2 );
    }
    else if ( level.console || common_scripts\utility::is_player_gamepad_enabled() )
    {
        var_18 = maps\mp\_utility::getkillstreakweapon( var_0 );
        givekillstreakweapon( var_18 );

        if ( isdefined( self.killstreakindexweapon ) )
        {
            var_0 = self.pers["killstreaks"][self.killstreakindexweapon].streakname;
            var_19 = maps\mp\_utility::getkillstreakweapon( var_0 );

            if ( !isholdingweapon( var_19 ) )
                self.killstreakindexweapon = var_6;
        }
        else
            self.killstreakindexweapon = var_6;
    }
    else
    {
        if ( 0 == var_6 && self.pers["killstreaks"][0].nextslot > 5 )
        {
            var_20 = self.pers["killstreaks"][0].nextslot - 1;
            var_21 = maps\mp\_utility::getkillstreakweapon( self.pers["killstreaks"][var_20].streakname );
            self takeweapon( var_21 );
        }

        var_19 = maps\mp\_utility::getkillstreakweapon( var_0 );
        maps\mp\_utility::_giveweapon( var_19, 0 );
        var_22 = 1;

        if ( isdefined( self.killstreakindexweapon ) )
        {
            var_0 = self.pers["killstreaks"][self.killstreakindexweapon].streakname;
            var_19 = maps\mp\_utility::getkillstreakweapon( var_0 );
            var_22 = !isholdingweapon( var_19 ) && self getcurrentweapon() != "none";
        }

        if ( var_22 )
            maps\mp\_utility::_setactionslot( var_6 + 4, "weapon", var_19 );
        else
        {
            maps\mp\_utility::_setactionslot( var_6 + 4, "" );
            self.actionslotenabled[var_6] = 0;
        }
    }

    updatestreakslots();

    if ( isdefined( level.killstreaksetupfuncs[var_0] ) )
        self [[ level.killstreaksetupfuncs[var_0] ]]();

    if ( isdefined( var_1 ) && var_1 && isdefined( var_2 ) && var_2 )
        self notify( "received_earned_killstreak" );
}

givekillstreakweapon( var_0 )
{
    self endon( "disconnect" );

    if ( !level.console && !common_scripts\utility::is_player_gamepad_enabled() )
        return;

    var_1 = maps\mp\_utility::getkillstreakreferencebyweapon( var_0 );

    if ( !maps\mp\_utility::cancustomjuggusekillstreak( var_1 ) )
        maps\mp\_utility::_setactionslot( 4, "" );
    else
    {
        var_2 = self getweaponslistitems();

        foreach ( var_4 in var_2 )
        {
            if ( !maps\mp\_utility::isstrstart( var_4, "killstreak_" ) && !maps\mp\_utility::isstrstart( var_4, "airdrop_" ) && !maps\mp\_utility::isstrstart( var_4, "deployable_" ) )
                continue;

            if ( isholdingweapon( var_4 ) )
                continue;

            while ( maps\mp\_utility::ischangingweapon() )
                wait 0.05;

            self takeweapon( var_4 );
        }

        if ( isdefined( self.killstreakindexweapon ) )
        {
            var_1 = self.pers["killstreaks"][self.killstreakindexweapon].streakname;
            var_6 = maps\mp\_utility::getkillstreakweapon( var_1 );

            if ( !isholdingweapon( var_6 ) )
            {
                if ( var_0 != "" )
                {
                    maps\mp\_utility::_giveweapon( var_0, 0 );
                    maps\mp\_utility::_setactionslot( 4, "weapon", var_0 );
                    return;
                }

                return;
            }

            return;
        }

        maps\mp\_utility::_giveweapon( var_0, 0 );
        maps\mp\_utility::_setactionslot( 4, "weapon", var_0 );
    }
}

isholdingweapon( var_0 )
{
    return self getcurrentweapon() == var_0 || isdefined( self.changingweapon ) && self.changingweapon == var_0;
}

getstreakcost( var_0 )
{
    var_1 = int( maps\mp\_utility::getkillstreakkills( var_0 ) );

    if ( isdefined( self ) && isplayer( self ) )
    {
        if ( maps\mp\_utility::isspecialistkillstreak( var_0 ) )
        {
            if ( isdefined( self.pers["gamemodeLoadout"] ) )
            {
                if ( isdefined( self.pers["gamemodeLoadout"]["loadoutKillstreak1"] ) && self.pers["gamemodeLoadout"]["loadoutKillstreak1"] == var_0 )
                    var_1 = 2;
                else if ( isdefined( self.pers["gamemodeLoadout"]["loadoutKillstreak2"] ) && self.pers["gamemodeLoadout"]["loadoutKillstreak2"] == var_0 )
                    var_1 = 4;
                else if ( isdefined( self.pers["gamemodeLoadout"]["loadoutKillstreak3"] ) && self.pers["gamemodeLoadout"]["loadoutKillstreak3"] == var_0 )
                    var_1 = 6;
                else
                {

                }
            }
            else if ( issubstr( self.curclass, "custom" ) )
            {
                for ( var_2 = 0; var_2 < 3; var_2++ )
                {
                    var_3 = self getcacplayerdata( "loadouts", self.class_num, "specialistStreaks", var_2 );

                    if ( var_3 == var_0 )
                        break;
                }

                var_1 = self getcacplayerdata( "loadouts", self.class_num, "specialistStreakKills", var_2 );
            }
            else if ( issubstr( self.curclass, "callback" ) )
            {
                var_2 = 0;

                foreach ( var_2, var_5 in self.pers["specialistStreaks"] )
                {
                    if ( var_5 == var_0 )
                        break;
                }

                var_1 = self.pers["specialistStreakKills"][var_2];
            }
            else if ( issubstr( self.curclass, "axis" ) || issubstr( self.curclass, "allies" ) )
            {
                var_2 = 0;
                var_6 = "none";

                if ( issubstr( self.curclass, "axis" ) )
                    var_6 = "axis";
                else if ( issubstr( self.curclass, "allies" ) )
                    var_6 = "allies";

                for ( var_7 = maps\mp\_utility::getclassindex( self.curclass ); var_2 < 3; var_2++ )
                {
                    var_3 = getmatchrulesdata( "defaultClasses", var_6, var_7, "class", "specialistStreaks", var_2 );

                    if ( var_3 == var_0 )
                        break;
                }

                var_1 = getmatchrulesdata( "defaultClasses", var_6, var_7, "class", "specialistStreakKills", var_2 );
            }
        }

        if ( maps\mp\_utility::_hasperk( "specialty_hardline" ) && var_1 > 0 )
            var_1--;
    }

    var_1 = int( clamp( var_1, 0, 30 ) );
    return var_1;
}

streaktyperesetsondeath( var_0 )
{
    switch ( var_0 )
    {
        case "assault":
        case "specialist":
            return 1;
        case "support":
            return 0;
    }
}

giveownedkillstreakitem( var_0 )
{
    var_1 = self.pers["killstreaks"];

    if ( level.console || common_scripts\utility::is_player_gamepad_enabled() )
    {
        var_2 = -1;
        var_3 = -1;

        for ( var_4 = 0; var_4 < 4; var_4++ )
        {
            if ( isdefined( var_1[var_4] ) && isdefined( var_1[var_4].streakname ) && var_1[var_4].available && getstreakcost( var_1[var_4].streakname ) > var_3 )
            {
                var_3 = 0;

                if ( !var_1[var_4].isgimme )
                    var_3 = getstreakcost( var_1[var_4].streakname );

                var_2 = var_4;
            }
        }

        if ( var_2 != -1 )
        {
            self.killstreakindexweapon = var_2;
            var_5 = var_1[self.killstreakindexweapon].streakname;
            var_6 = maps\mp\_utility::getkillstreakweapon( var_5 );
            givekillstreakweapon( var_6 );
        }
        else
            self.killstreakindexweapon = undefined;
    }
    else
    {
        var_2 = -1;
        var_3 = -1;

        for ( var_4 = 0; var_4 < 4; var_4++ )
        {
            if ( isdefined( var_1[var_4] ) && isdefined( var_1[var_4].streakname ) && var_1[var_4].available )
            {
                var_7 = maps\mp\_utility::getkillstreakweapon( var_1[var_4].streakname );
                var_8 = self getweaponslistitems();
                var_9 = 0;

                for ( var_10 = 0; var_10 < var_8.size; var_10++ )
                {
                    if ( var_7 == var_8[var_10] )
                    {
                        var_9 = 1;
                        break;
                    }
                }

                if ( !var_9 )
                    maps\mp\_utility::_giveweapon( var_7 );
                else if ( issubstr( var_7, "airdrop_" ) )
                    self setweaponammoclip( var_7, 1 );

                maps\mp\_utility::_setactionslot( var_4 + 4, "weapon", var_7 );

                if ( getstreakcost( var_1[var_4].streakname ) > var_3 )
                {
                    var_3 = 0;

                    if ( !var_1[var_4].isgimme )
                        var_3 = getstreakcost( var_1[var_4].streakname );

                    var_2 = var_4;
                }
            }
        }

        if ( var_2 != -1 )
            var_5 = var_1[var_2].streakname;

        self.killstreakindexweapon = undefined;
    }

    updatestreakslots();
}

initridekillstreak( var_0 )
{
    common_scripts\utility::_disableusability();
    var_1 = initridekillstreak_internal( var_0 );

    if ( isdefined( self ) )
        common_scripts\utility::_enableusability();

    return var_1;
}

initridekillstreak_internal( var_0 )
{
    if ( isdefined( var_0 ) && islaptoptimeoutkillstreak( var_0 ) )
        var_1 = "timeout";
    else
        var_1 = common_scripts\utility::waittill_any_timeout( 1.0, "disconnect", "death", "weapon_switch_started" );

    maps\mp\gametypes\_hostmigration::waittillhostmigrationdone();

    if ( var_1 == "weapon_switch_started" )
        return "fail";

    if ( !isalive( self ) )
        return "fail";

    if ( var_1 == "disconnect" || var_1 == "death" )
    {
        if ( var_1 == "disconnect" )
            return "disconnect";

        if ( self.team == "spectator" )
            return "fail";

        return "success";
    }

    if ( maps\mp\_utility::iskillstreakdenied() )
        return "fail";

    if ( !isdefined( var_0 ) || !issubstr( var_0, "odin" ) )
    {
        self visionsetnakedforplayer( "black_bw", 0.75 );
        thread maps\mp\_utility::set_visionset_for_watching_players( "black_bw", 0.75, 1.0, undefined, 1 );
        var_2 = common_scripts\utility::waittill_any_timeout( 0.8, "disconnect", "death" );
    }
    else
        var_2 = common_scripts\utility::waittill_any_timeout( 1.0, "disconnect", "death" );

    self notify( "black_out_done" );
    maps\mp\gametypes\_hostmigration::waittillhostmigrationdone();

    if ( var_2 != "disconnect" )
    {
        if ( !isdefined( var_0 ) || !issubstr( var_0, "odin" ) )
            thread clearrideintro( 1.0 );
        else
            self notify( "intro_cleared" );

        if ( self.team == "spectator" )
            return "fail";
    }

    if ( self isonladder() )
        return "fail";

    if ( !isalive( self ) )
        return "fail";

    if ( maps\mp\_utility::iskillstreakdenied() )
        return "fail";

    if ( var_2 == "disconnect" )
        return "disconnect";
    else
        return "success";
}

islaptoptimeoutkillstreak( var_0 )
{
    switch ( var_0 )
    {
        case "remote_tank":
        case "remote_uav":
        case "osprey_gunner":
        case "ac130":
        case "ca_a10_strafe":
        case "odin_assault":
        case "odin_support":
        case "drone_hive":
        case "heli_pilot":
        case "vanguard":
            return 1;
    }

    return 0;
}

clearrideintro( var_0, var_1 )
{
    self endon( "disconnect" );

    if ( isdefined( var_0 ) )
        wait( var_0 );

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

    self visionsetnakedforplayer( "", var_1 );
    maps\mp\_utility::set_visionset_for_watching_players( "", var_1 );
    self notify( "intro_cleared" );
}

allowridekillstreakplayerexit( var_0 )
{
    if ( isdefined( var_0 ) )
        self endon( var_0 );

    if ( !isdefined( self.owner ) )
        return;

    var_1 = self.owner;
    level endon( "game_ended" );
    var_1 endon( "disconnect" );
    var_1 endon( "end_remote" );
    self endon( "death" );

    for (;;)
    {
        var_2 = 0;

        while ( var_1 usebuttonpressed() )
        {
            var_2 = var_2 + 0.05;

            if ( var_2 > 0.75 )
            {
                self notify( "killstreakExit" );
                return;
            }

            wait 0.05;
        }

        wait 0.05;
    }
}

giveselectedkillstreakitem()
{
    var_0 = self.pers["killstreaks"][self.killstreakindexweapon].streakname;
    var_1 = maps\mp\_utility::getkillstreakweapon( var_0 );
    givekillstreakweapon( var_1 );
    updatestreakslots();
}

getkillstreakcount()
{
    var_0 = 0;

    for ( var_1 = 0; var_1 < 4; var_1++ )
    {
        if ( isdefined( self.pers["killstreaks"][var_1] ) && isdefined( self.pers["killstreaks"][var_1].streakname ) && self.pers["killstreaks"][var_1].available )
            var_0++;
    }

    return var_0;
}

shufflekillstreaksup()
{
    if ( getkillstreakcount() > 1 )
    {
        for (;;)
        {
            self.killstreakindexweapon++;

            if ( self.killstreakindexweapon > 3 )
                self.killstreakindexweapon = 0;

            if ( self.pers["killstreaks"][self.killstreakindexweapon].available == 1 )
                break;
        }

        giveselectedkillstreakitem();
    }
}

shufflekillstreaksdown()
{
    if ( getkillstreakcount() > 1 )
    {
        for (;;)
        {
            self.killstreakindexweapon--;

            if ( self.killstreakindexweapon < 0 )
                self.killstreakindexweapon = 3;

            if ( self.pers["killstreaks"][self.killstreakindexweapon].available == 1 )
                break;
        }

        giveselectedkillstreakitem();
    }
}

streakselectuptracker()
{
    self endon( "death" );
    self endon( "disconnect" );
    self endon( "faux_spawn" );
    level endon( "game_ended" );

    for (;;)
    {
        self waittill( "toggled_up" );

        if ( !level.console && !common_scripts\utility::is_player_gamepad_enabled() )
            continue;

        if ( isdefined( self.showingtacticalselections ) && self.showingtacticalselections )
            continue;

        if ( !self ismantling() && ( !isdefined( self.changingweapon ) || isdefined( self.changingweapon ) && self.changingweapon == "none" ) && ( !maps\mp\_utility::iskillstreakweapon( self getcurrentweapon() ) || isminigun( self getcurrentweapon() ) || self getcurrentweapon() == "venomxgun_mp" || maps\mp\_utility::iskillstreakweapon( self getcurrentweapon() ) && maps\mp\_utility::isjuggernaut() ) && self.streaktype != "specialist" && ( !isdefined( self.iscarrying ) || isdefined( self.iscarrying ) && self.iscarrying == 0 ) && ( !isdefined( self.laststreakused ) || isdefined( self.laststreakused ) && gettime() - self.laststreakused > 100 ) )
        {
            shufflekillstreaksup();
            self setclientomnvar( "ui_killstreak_scroll", 1 );
        }

        wait 0.12;
    }
}

isminigun( var_0 )
{
    return var_0 == "iw6_minigunjugg_mp";
}

streakselectdowntracker()
{
    self endon( "death" );
    self endon( "disconnect" );
    self endon( "faux_spawn" );
    level endon( "game_ended" );

    for (;;)
    {
        self waittill( "toggled_down" );

        if ( !level.console && !common_scripts\utility::is_player_gamepad_enabled() )
            continue;

        if ( isdefined( self.showingtacticalselections ) && self.showingtacticalselections )
            continue;

        if ( !self ismantling() && ( !isdefined( self.changingweapon ) || isdefined( self.changingweapon ) && self.changingweapon == "none" ) && ( !maps\mp\_utility::iskillstreakweapon( self getcurrentweapon() ) || isminigun( self getcurrentweapon() ) || self getcurrentweapon() == "venomxgun_mp" || maps\mp\_utility::iskillstreakweapon( self getcurrentweapon() ) && maps\mp\_utility::isjuggernaut() ) && self.streaktype != "specialist" && ( !isdefined( self.iscarrying ) || isdefined( self.iscarrying ) && self.iscarrying == 0 ) && ( !isdefined( self.laststreakused ) || isdefined( self.laststreakused ) && gettime() - self.laststreakused > 100 ) )
        {
            shufflekillstreaksdown();
            self setclientomnvar( "ui_killstreak_scroll", 1 );
        }

        wait 0.12;
    }
}

streakusetimetracker()
{
    self endon( "death" );
    self endon( "disconnect" );
    self endon( "faux_spawn" );
    level endon( "game_ended" );

    for (;;)
    {
        self waittill( "streakUsed" );
        self.laststreakused = gettime();
    }
}

streaknotifytracker()
{
    self endon( "death" );
    self endon( "disconnect" );
    level endon( "game_ended" );

    if ( isbot( self ) )
        return;

    maps\mp\_utility::gameflagwait( "prematch_done" );

    if ( level.console || common_scripts\utility::is_player_gamepad_enabled() )
    {
        self notifyonplayercommand( "toggled_up", "+actionslot 1" );
        self notifyonplayercommand( "toggled_down", "+actionslot 2" );
        self notifyonplayercommand( "streakUsed", "+actionslot 4" );
        self notifyonplayercommand( "streakUsed", "+actionslot 5" );
        self notifyonplayercommand( "streakUsed", "+actionslot 6" );
        self notifyonplayercommand( "streakUsed", "+actionslot 7" );
    }

    if ( !level.console )
    {
        self notifyonplayercommand( "streakUsed1", "+actionslot 4" );
        self notifyonplayercommand( "streakUsed2", "+actionslot 5" );
        self notifyonplayercommand( "streakUsed3", "+actionslot 6" );
        self notifyonplayercommand( "streakUsed4", "+actionslot 7" );
    }
}

registeradrenalineinfo( var_0, var_1 )
{
    if ( !isdefined( level.adrenalineinfo ) )
        level.adrenalineinfo = [];

    level.adrenalineinfo[var_0] = var_1;
}

giveadrenaline( var_0 )
{
    if ( level.adrenalineinfo[var_0] == 0 )
        return;

    if ( maps\mp\_utility::isjuggernaut() && self.streaktype == "specialist" )
        return;

    var_1 = self.adrenaline + level.adrenalineinfo[var_0];
    var_2 = var_1;
    var_3 = getmaxstreakcost();

    if ( var_2 > var_3 && self.streaktype != "specialist" )
        var_2 = var_2 - var_3;
    else if ( level.killstreakrewards && var_2 > var_3 && self.streaktype == "specialist" )
    {
        var_4 = var_3;

        if ( isai( self ) )
            var_4 = self.pers["specialistStreakKills"][2];

        var_5 = int( max( 8, var_4 + 2 ) );

        if ( maps\mp\_utility::_hasperk( "specialty_hardline" ) )
            var_5--;

        var_6 = var_2 >= var_5 && self getcommonplayerdata( "killstreaksState", "hasStreak", 4 ) == 0;

        if ( var_6 )
        {
            givebonusperks();
            usedkillstreak( "all_perks_bonus", 1 );
            thread maps\mp\gametypes\_hud_message::killstreaksplashnotify( "all_perks_bonus", var_5 );
            self setcommonplayerdata( "killstreaksState", "hasStreak", 4, 1 );
            self.pers["killstreaks"][4].available = 1;
        }

        if ( var_3 > 0 && !( ( var_2 - var_3 ) % 2 ) )
        {
            thread maps\mp\gametypes\_rank::xpeventpopup( "specialist_streaking_xp" );
            thread maps\mp\gametypes\_rank::giverankxp( "kill" );
        }
    }

    setadrenaline( var_2 );
    checkstreakreward();

    if ( var_1 == var_3 && self.streaktype != "specialist" )
        setadrenaline( 0 );
}

givebonusperks()
{
    if ( isai( self ) )
    {
        if ( isdefined( self.pers ) && isdefined( self.pers["specialistBonusStreaks"] ) )
        {
            foreach ( var_1 in self.pers["specialistBonusStreaks"] )
            {
                if ( !maps\mp\_utility::_hasperk( var_1 ) )
                    maps\mp\_utility::giveperk( var_1, 0 );
            }
        }
    }
    else
    {
        for ( var_3 = 0; var_3 < 7; var_3++ )
        {
            for ( var_4 = 0; var_4 < 5; var_4++ )
            {
                var_5 = 0;

                if ( isdefined( self.teamname ) )
                    var_5 = getmatchrulesdata( "defaultClasses", self.teamname, self.class_num, "class", "specialistBonusStreaks", var_3, var_4 );
                else
                    var_5 = self getcacplayerdata( "loadouts", self.class_num, "specialistBonusStreaks", var_3, var_4 );

                if ( isdefined( var_5 ) && var_5 )
                {
                    var_1 = tablelookup( "mp/cacAbilityTable.csv", 0, var_3 + 1, 4 + var_4 );

                    if ( !maps\mp\_utility::_hasperk( var_1 ) )
                        maps\mp\_utility::giveperk( var_1, 0 );
                }
            }
        }
    }
}

resetadrenaline()
{
    self.earnedstreaklevel = 0;
    setadrenaline( 0 );
    resetstreakcount();
    self.pers["lastEarnedStreak"] = undefined;
    self.pers["objectivePointStreak"] = 0;
    self setclientomnvar( "ui_half_tick", 0 );
}

setadrenaline( var_0 )
{
    if ( var_0 < 0 )
        var_0 = 0;

    if ( isdefined( self.adrenaline ) )
        self.previousadrenaline = self.adrenaline;
    else
        self.previousadrenaline = 0;

    self.adrenaline = var_0;
    self setclientdvar( "ui_adrenaline", self.adrenaline );
    updatestreakcount();
}

pc_watchgamepad()
{
    self endon( "death" );
    self endon( "disconnect" );
    level endon( "game_ended" );
    var_0 = common_scripts\utility::is_player_gamepad_enabled();

    for (;;)
    {
        if ( var_0 != common_scripts\utility::is_player_gamepad_enabled() )
        {
            var_0 = common_scripts\utility::is_player_gamepad_enabled();

            if ( !var_0 )
            {
                if ( isdefined( self.actionslotenabled ) )
                {
                    for ( var_1 = 0; var_1 < 4; var_1++ )
                        self.actionslotenabled[var_1] = 1;

                    self notifyonplayercommand( "streakUsed1", "+actionslot 4" );
                    self notifyonplayercommand( "streakUsed2", "+actionslot 5" );
                    self notifyonplayercommand( "streakUsed3", "+actionslot 6" );
                    self notifyonplayercommand( "streakUsed4", "+actionslot 7" );
                    giveownedkillstreakitem();
                }
            }
            else
            {
                var_2 = self getweaponslistitems();

                foreach ( var_4 in var_2 )
                {
                    if ( maps\mp\_utility::iskillstreakweapon( var_4 ) && var_4 == self getcurrentweapon() )
                    {
                        self switchtoweapon( common_scripts\utility::getlastweapon() );

                        while ( maps\mp\_utility::ischangingweapon() )
                            wait 0.05;
                    }

                    if ( maps\mp\_utility::iskillstreakweapon( var_4 ) )
                        self takeweapon( var_4 );
                }

                for ( var_1 = 0; var_1 < 4; var_1++ )
                {
                    maps\mp\_utility::_setactionslot( var_1 + 4, "" );
                    self.actionslotenabled[var_1] = 0;
                }

                self notifyonplayercommand( "toggled_up", "+actionslot 1" );
                self notifyonplayercommand( "toggled_down", "+actionslot 2" );
                self notifyonplayercommand( "streakUsed", "+actionslot 4" );
                self notifyonplayercommand( "streakUsed", "+actionslot 5" );
                self notifyonplayercommand( "streakUsed", "+actionslot 6" );
                self notifyonplayercommand( "streakUsed", "+actionslot 7" );
                giveownedkillstreakitem();
            }
        }

        wait 0.05;
    }
}

pc_watchstreakuse()
{
    self endon( "death" );
    self endon( "disconnect" );
    level endon( "game_ended" );
    self.actionslotenabled = [];
    self.actionslotenabled[0] = 1;
    self.actionslotenabled[1] = 1;
    self.actionslotenabled[2] = 1;
    self.actionslotenabled[3] = 1;

    for (;;)
    {
        var_0 = common_scripts\utility::waittill_any_return( "streakUsed1", "streakUsed2", "streakUsed3", "streakUsed4" );

        if ( common_scripts\utility::is_player_gamepad_enabled() )
            continue;

        if ( !isdefined( var_0 ) )
            continue;

        if ( self.streaktype == "specialist" && var_0 != "streakUsed1" )
            continue;

        if ( isdefined( self.changingweapon ) && self.changingweapon == "none" )
            continue;

        if ( self isoffhandweaponreadytothrow() )
            continue;

        switch ( var_0 )
        {
            case "streakUsed1":
                if ( self.pers["killstreaks"][0].available && self.actionslotenabled[0] )
                    self.killstreakindexweapon = 0;

                break;
            case "streakUsed2":
                if ( self.pers["killstreaks"][1].available && self.actionslotenabled[1] )
                    self.killstreakindexweapon = 1;

                break;
            case "streakUsed3":
                if ( self.pers["killstreaks"][2].available && self.actionslotenabled[2] )
                    self.killstreakindexweapon = 2;

                break;
            case "streakUsed4":
                if ( self.pers["killstreaks"][3].available && self.actionslotenabled[3] )
                    self.killstreakindexweapon = 3;

                break;
        }

        if ( isdefined( self.killstreakindexweapon ) && !self.pers["killstreaks"][self.killstreakindexweapon].available )
            self.killstreakindexweapon = undefined;

        if ( isdefined( self.killstreakindexweapon ) )
        {
            disablekillstreakactionslots();

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

                if ( isdefined( self.killstreakindexweapon ) )
                {
                    var_3 = maps\mp\_utility::getkillstreakweapon( self.pers["killstreaks"][self.killstreakindexweapon].streakname );

                    if ( var_1 == var_3 || var_1 == "none" || var_3 == "killstreak_uav_mp" && var_1 == "killstreak_remote_uav_mp" || var_3 == "killstreak_uav_mp" && var_1 == "uav_remote_mp" || var_2 )
                        continue;

                    break;
                }

                break;
            }

            enablekillstreakactionslots();
            self.killstreakindexweapon = undefined;
        }
    }
}

disablekillstreakactionslots()
{
    for ( var_0 = 0; var_0 < 4; var_0++ )
    {
        if ( !isdefined( self.killstreakindexweapon ) )
            break;

        if ( self.killstreakindexweapon == var_0 )
            continue;

        maps\mp\_utility::_setactionslot( var_0 + 4, "" );
        self.actionslotenabled[var_0] = 0;
    }
}

enablekillstreakactionslots()
{
    for ( var_0 = 0; var_0 < 4; var_0++ )
    {
        if ( self.pers["killstreaks"][var_0].available )
        {
            var_1 = maps\mp\_utility::getkillstreakweapon( self.pers["killstreaks"][var_0].streakname );
            maps\mp\_utility::_setactionslot( var_0 + 4, "weapon", var_1 );
        }
        else
            maps\mp\_utility::_setactionslot( var_0 + 4, "" );

        self.actionslotenabled[var_0] = 1;
    }
}

killstreakhit( var_0, var_1, var_2 )
{
    if ( isdefined( var_1 ) && isplayer( var_0 ) && isdefined( var_2.owner ) && isdefined( var_2.owner.team ) )
    {
        if ( ( level.teambased && var_2.owner.team != var_0.team || !level.teambased ) && var_0 != var_2.owner )
        {
            if ( maps\mp\_utility::iskillstreakweapon( var_1 ) )
                return;

            if ( !isdefined( var_0.lasthittime[var_1] ) )
                var_0.lasthittime[var_1] = 0;

            if ( var_0.lasthittime[var_1] == gettime() )
                return;

            var_0.lasthittime[var_1] = gettime();
            var_0 thread maps\mp\gametypes\_gamelogic::threadedsetweaponstatbyname( var_1, 1, "hits" );

            if ( !issquadsmode() )
            {
                var_3 = var_0 maps\mp\gametypes\_persistence::statgetbuffered( "totalShots" );
                var_4 = var_0 maps\mp\gametypes\_persistence::statgetbuffered( "hits" ) + 1;

                if ( var_4 <= var_3 )
                {
                    var_0 maps\mp\gametypes\_persistence::statsetbuffered( "hits", var_4 );
                    var_0 maps\mp\gametypes\_persistence::statsetbuffered( "misses", int( var_3 - var_4 ) );
                    var_0 maps\mp\gametypes\_persistence::statsetbuffered( "accuracy", int( var_4 * 10000 / var_3 ) );
                }
            }
        }
    }
}

copy_killstreak_status( var_0, var_1 )
{
    self.streaktype = var_0.streaktype;
    self.pers["cur_kill_streak"] = var_0.pers["cur_kill_streak"];
    maps\mp\gametypes\_persistence::statsetchild( "round", "killStreak", self.pers["cur_kill_streak"] );
    self.pers["killstreaks"] = var_0.pers["killstreaks"];
    self.killstreaks = var_0.killstreaks;

    if ( !isdefined( var_1 ) || var_1 == 0 )
    {
        var_2 = getentarray();

        foreach ( var_4 in var_2 )
        {
            if ( !isdefined( var_4 ) || isplayer( var_4 ) )
                continue;

            if ( isdefined( var_4.owner ) && var_4.owner == var_0 )
            {
                if ( var_4.classname == "misc_turret" )
                {
                    var_4 maps\mp\killstreaks\_autosentry::sentry_setowner( self );
                    continue;
                }

                var_4.owner = self;
            }
        }
    }

    self.adrenaline = undefined;
    setadrenaline( var_0.adrenaline );
    resetstreakcount();
    updatestreakcount();

    if ( isdefined( var_1 ) && var_1 == 1 && isdefined( self.killstreaks ) )
    {
        var_6 = 1;

        foreach ( var_8 in self.killstreaks )
        {
            var_9 = self.pers["killstreaks"][var_6].streakname;

            if ( self.streaktype == "specialist" )
            {
                var_10 = strtok( self.pers["killstreaks"][var_6].streakname, "_" );

                if ( var_10[var_10.size - 1] == "ks" )
                {
                    var_11 = undefined;

                    foreach ( var_13 in var_10 )
                    {
                        if ( var_13 != "ks" )
                        {
                            if ( !isdefined( var_11 ) )
                            {
                                var_11 = var_13;
                                continue;
                            }

                            var_11 = var_11 + ( "_" + var_13 );
                        }
                    }

                    if ( maps\mp\_utility::isstrstart( self.pers["killstreaks"][var_6].streakname, "_" ) )
                        var_11 = "_" + var_11;

                    if ( isdefined( var_11 ) && maps\mp\gametypes\_class::getperkupgrade( var_11 ) != "specialty_null" )
                        var_9 = self.pers["killstreaks"][var_6].streakname + "_pro";
                }
            }

            self setcommonplayerdata( "killstreaksState", "icons", var_6, maps\mp\_utility::getkillstreakindex( var_9 ) );
            var_6++;
        }
    }

    updatestreakslots();

    foreach ( var_11 in var_0.perksperkname )
    {
        if ( !maps\mp\_utility::_hasperk( var_11 ) )
        {
            var_17 = 0;

            if ( isdefined( self.perksuseslot[var_11] ) )
                var_17 = self.perksuseslot[var_11];

            maps\mp\_utility::giveperk( var_11, var_17 );
        }

        if ( !isdefined( var_1 ) || var_1 == 0 )
            var_0 maps\mp\_utility::_unsetperk( var_11 );
    }
}

copy_adrenaline( var_0 )
{
    self.adrenaline = undefined;
    setadrenaline( var_0.adrenaline );
    resetstreakcount();
    updatestreakcount();
    updatestreakslots();
}

is_using_killstreak()
{
    var_0 = self getcurrentweapon();
    var_1 = issubstr( var_0, "killstreak" ) || isdefined( self.selectinglocation ) && self.selectinglocation == 1 || !common_scripts\utility::isweaponenabled() && !maps\mp\gametypes\_damage::attackerinremotekillstreak();
    return var_1;
}

monitordisownkillstreaks()
{
    while ( isdefined( self ) )
    {
        if ( maps\mp\_utility::bot_is_fireteam_mode() )
            self waittill( "disconnect" );
        else
            common_scripts\utility::waittill_any( "disconnect", "joined_team", "joined_spectators" );

        self notify( "killstreak_disowned" );
    }
}

findunobstructedfiringpointaroundz( var_0, var_1, var_2, var_3 )
{
    var_4 = rotatevector( ( 0, 0, 1 ), ( -1 * var_3, 0, 0 ) );
    var_5 = vectortoangles( var_1 - var_0.origin );

    for ( var_6 = 0; var_6 < 360; var_6 = var_6 + 30 )
    {
        var_7 = var_2 * rotatevector( var_4, ( 0, var_6 + var_5[1], 0 ) );
        var_8 = var_1 + var_7;

        if ( _findunobstructedfiringpointhelper( var_0, var_8, var_1 ) )
            return var_8;
    }

    return undefined;
}

findunobstructedfiringpointaroundy( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    var_6 = vectortoangles( var_0.origin - var_1 );

    for ( var_7 = var_3; var_7 <= var_4; var_7 = var_7 + var_5 )
    {
        var_8 = rotatevector( ( 1, 0, 0 ), ( var_7 - 90, 0, 0 ) );
        var_9 = var_2 * rotatevector( var_8, ( 0, var_6[1], 0 ) );
        var_10 = var_1 + var_9;

        if ( _findunobstructedfiringpointhelper( var_0, var_10, var_1 ) )
            return var_10;
    }

    return undefined;
}

_findunobstructedfiringpointhelper( var_0, var_1, var_2 )
{
    var_3 = bullettrace( var_1, var_2, 0 );

    if ( var_3["fraction"] > 0.99 )
        return 1;

    return 0;
}

findunobstructedfiringpoint( var_0, var_1, var_2 )
{
    var_3 = findunobstructedfiringpointaroundz( var_0, var_1, var_2, 30 );

    if ( !isdefined( var_3 ) )
        var_3 = findunobstructedfiringpointaroundy( var_0, var_1, var_2, 15, 75, 15 );

    return var_3;
}

isairdropmarker( var_0 )
{
    switch ( var_0 )
    {
        case "airdrop_escort_marker_mp":
        case "airdrop_tank_marker_mp":
        case "airdrop_juggernaut_maniac_mp":
        case "airdrop_juggernaut_def_mp":
        case "airdrop_sentry_marker_mp":
        case "airdrop_mega_marker_mp":
        case "airdrop_marker_support_mp":
        case "airdrop_marker_assault_mp":
        case "airdrop_juggernaut_mp":
        case "airdrop_marker_mp":
            return 1;
        default:
            return 0;
    }
}

isusinghelisniper()
{
    return isdefined( self.onhelisniper ) && self.onhelisniper;
}

destroytargetarray( var_0, var_1, var_2, var_3 )
{
    var_4 = "MOD_EXPLOSIVE";
    var_5 = 5000;
    var_6 = ( 0, 0, 0 );
    var_7 = ( 0, 0, 0 );
    var_8 = "";
    var_9 = "";
    var_10 = "";
    var_11 = undefined;

    if ( level.teambased )
    {
        foreach ( var_13 in var_3 )
        {
            if ( maps\mp\_utility::isvalidteamtarget( var_0, var_1, var_13 ) )
            {
                var_13 notify( "damage", var_5, var_0, var_6, var_7, var_4, var_8, var_9, var_10, var_11, var_2 );
                wait 0.05;
            }
        }
    }
    else
    {
        foreach ( var_13 in var_3 )
        {
            if ( maps\mp\_utility::isvalidffatarget( var_0, var_1, var_13 ) )
            {
                var_13 notify( "damage", var_5, var_0, var_6, var_7, var_4, var_8, var_9, var_10, var_11, var_2 );
                wait 0.05;
            }
        }
    }
}
