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

init()
{
    level.scoreinfo = [];
    level.xpscale = getdvarint( "scr_xpscale" );

    if ( level.xpscale > 4 || level.xpscale < 0 )
        exitlevel( 0 );

    level.xpscale = min( level.xpscale, 4 );
    level.xpscale = max( level.xpscale, 0 );
    level.teamxpscale["axis"] = 1;
    level.teamxpscale["allies"] = 1;
    level.ranktable = [];
    level.weaponranktable = [];
    level.maxrank = int( tablelookup( "mp/rankTable.csv", 0, "maxrank", 1 ) );
    level.maxprestige = int( tablelookup( "mp/rankTable.csv", 0, "maxprestige", 1 ) );
    level.maxforbotmatch = getdvarint( "max_xp_per_match", 0 );
    var_0 = 0;
    var_1 = 0;

    for ( var_0 = 0; var_0 <= min( 10, level.maxprestige ); var_0++ )
    {
        for ( var_1 = 0; var_1 <= level.maxrank; var_1++ )
            precacheshader( tablelookup( "mp/rankIconTable.csv", 0, var_1, var_0 + 1 ) );
    }

    var_2 = 0;

    for ( var_3 = tablelookup( "mp/rankTable.csv", 0, var_2, 1 ); isdefined( var_3 ) && var_3 != ""; var_3 = tablelookup( "mp/rankTable.csv", 0, var_2, 1 ) )
    {
        level.ranktable[var_2][1] = tablelookup( "mp/rankTable.csv", 0, var_2, 1 );
        level.ranktable[var_2][2] = tablelookup( "mp/rankTable.csv", 0, var_2, 2 );
        level.ranktable[var_2][3] = tablelookup( "mp/rankTable.csv", 0, var_2, 3 );
        level.ranktable[var_2][7] = tablelookup( "mp/rankTable.csv", 0, var_2, 7 );
        precachestring( tablelookupistring( "mp/rankTable.csv", 0, var_2, 16 ) );
        var_2++;
    }

    var_4 = int( tablelookup( "mp/weaponRankTable.csv", 0, "maxrank", 1 ) );

    for ( var_5 = 0; var_5 < var_4 + 1; var_5++ )
    {
        level.weaponranktable[var_5][1] = tablelookup( "mp/weaponRankTable.csv", 0, var_5, 1 );
        level.weaponranktable[var_5][2] = tablelookup( "mp/weaponRankTable.csv", 0, var_5, 2 );
        level.weaponranktable[var_5][3] = tablelookup( "mp/weaponRankTable.csv", 0, var_5, 3 );
    }

    maps\mp\gametypes\_missions::buildchallegeinfo();
    level thread patientzerowaiter();
    level thread onplayerconnect();
}

patientzerowaiter()
{
    level endon( "game_ended" );

    while ( !isdefined( level.players ) || !level.players.size )
        wait 0.05;

    if ( !maps\mp\_utility::matchmakinggame() )
    {
        if ( getdvar( "mapname" ) == "mp_rust" && randomint( 1000 ) == 999 )
            level.patientzeroname = level.players[0].name;
    }
    else if ( getdvar( "scr_patientZero" ) != "" )
        level.patientzeroname = getdvar( "scr_patientZero" );
}

isregisteredevent( var_0 )
{
    if ( isdefined( level.scoreinfo[var_0] ) )
        return 1;
    else
        return 0;
}

registerscoreinfo( var_0, var_1 )
{
    level.scoreinfo[var_0]["value"] = var_1;

    if ( var_0 == "kill" )
        setomnvar( "ui_game_type_kill_value", int( var_1 ) );
}

getscoreinfovalue( var_0 )
{
    var_1 = "scr_" + level.gametype + "_score_" + var_0;

    if ( getdvar( var_1 ) != "" )
        return getdvarint( var_1 );
    else
        return level.scoreinfo[var_0]["value"];
}

getscoreinfolabel( var_0 )
{
    return level.scoreinfo[var_0]["label"];
}

getrankinfominxp( var_0 )
{
    return int( level.ranktable[var_0][2] );
}

getweaponrankinfominxp( var_0 )
{
    return int( level.weaponranktable[var_0][1] );
}

getrankinfoxpamt( var_0 )
{
    return int( level.ranktable[var_0][3] );
}

getweaponrankinfoxpamt( var_0 )
{
    return int( level.weaponranktable[var_0][2] );
}

getrankinfomaxxp( var_0 )
{
    return int( level.ranktable[var_0][7] );
}

getweaponrankinfomaxxp( var_0 )
{
    return int( level.weaponranktable[var_0][3] );
}

getrankinfofull( var_0 )
{
    return tablelookupistring( "mp/rankTable.csv", 0, var_0, 16 );
}

getrankinfoicon( var_0, var_1 )
{
    return tablelookup( "mp/rankIconTable.csv", 0, var_0, var_1 + 1 );
}

getrankinfolevel( var_0 )
{
    return int( tablelookup( "mp/rankTable.csv", 0, var_0, 13 ) );
}

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

        if ( !isai( var_0 ) )
        {
            if ( maps\mp\_utility::matchmakinggame() )
            {
                var_0.pers["activeSquadMember"] = var_0 getrankedplayerdata( "activeSquadMember" );
                var_0.pers["rankxp"] = var_0 getrankedplayerdata( "squadMembers", var_0.pers["activeSquadMember"], "squadMemXP" );
                var_1 = var_0 getrankedplayerdatareservedint( "prestigeLevel" );

                if ( !isdefined( var_0.pers["xpEarnedThisMatch"] ) )
                    var_0.pers["xpEarnedThisMatch"] = 0;
            }
            else
            {
                var_0.pers["activeSquadMember"] = var_0 getprivateplayerdata( "privateMatchActiveSquadMember" );
                var_1 = 0;
                var_0.pers["rankxp"] = 0;
            }
        }
        else
        {
            var_1 = 0;
            var_0.pers["rankxp"] = 0;
        }

        var_0.pers["prestige"] = var_1;

        if ( var_0.pers["rankxp"] < 0 )
            var_0.pers["rankxp"] = 0;

        var_2 = var_0 getrankforxp( var_0 getrankxp() );
        var_0.pers["rank"] = var_2;
        var_0 setrank( var_2, var_1 );

        if ( var_0.clientid < level.maxlogclients )
        {
            setmatchdata( "players", var_0.clientid, "rank", var_2 );
            setmatchdata( "players", var_0.clientid, "Prestige", var_1 );

            if ( !isai( var_0 ) && ( maps\mp\_utility::privatematch() || maps\mp\_utility::matchmakinggame() ) )
            {
                setmatchdata( "players", var_0.clientid, "isSplitscreen", var_0 issplitscreenplayer() );
                setmatchdata( "players", var_0.clientid, "activeSquadMember", var_0.pers["activeSquadMember"] );
            }
        }

        var_0.pers["participation"] = 0;
        var_0.xpupdatetotal = 0;
        var_0.bonusupdatetotal = 0;
        var_0.postgamepromotion = 0;

        if ( !isdefined( var_0.pers["postGameChallenges"] ) )
            var_0 setclientdvars( "ui_challenge_1_ref", "", "ui_challenge_2_ref", "", "ui_challenge_3_ref", "", "ui_challenge_4_ref", "", "ui_challenge_5_ref", "", "ui_challenge_6_ref", "", "ui_challenge_7_ref", "" );

        var_0 setclientdvar( "ui_promotion", 0 );

        if ( !isdefined( var_0.pers["summary"] ) )
        {
            var_0.pers["summary"] = [];
            var_0.pers["summary"]["xp"] = 0;
            var_0.pers["summary"]["score"] = 0;
            var_0.pers["summary"]["operation"] = 0;
            var_0.pers["summary"]["challenge"] = 0;
            var_0.pers["summary"]["match"] = 0;
            var_0.pers["summary"]["misc"] = 0;
            var_0.pers["summary"]["entitlementXP"] = 0;
            var_0.pers["summary"]["clanWarsXP"] = 0;
        }

        var_0 setclientdvar( "ui_opensummary", 0 );
        var_0 thread maps\mp\gametypes\_missions::updatechallenges();
        var_0.explosivekills[0] = 0;
        var_0.xpgains = [];
        var_0 thread onplayerspawned();
        var_0 thread onplayergiveloadout();

        if ( var_0 maps\mp\_utility::rankingenabled() )
        {
            if ( issquadsmode() )
            {
                if ( var_0 getrankedplayerdata( "prestigeDoubleXp" ) )
                    var_0.prestigedoublexp = 1;
                else
                    var_0.prestigedoublexp = 0;
            }

            if ( var_0 getrankedplayerdata( "prestigeDoubleWeaponXp" ) )
            {
                var_0.prestigedoubleweaponxp = 1;
                continue;
            }

            var_0.prestigedoubleweaponxp = 0;
        }
    }
}

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

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

        if ( isai( self ) )
            self.pers["rankxp"] = maps\mp\_utility::get_rank_xp_for_bot();
        else if ( !level.rankedmatch )
            self.pers["rankxp"] = 0;
        else
        {

        }

        playerupdaterank();
    }
}

playerupdaterank()
{
    if ( self.pers["rankxp"] < 0 )
        self.pers["rankxp"] = 0;

    var_0 = getrankforxp( getrankxp() );
    self.pers["rank"] = var_0;

    if ( isai( self ) || !isdefined( self.pers["prestige"] ) )
    {
        if ( level.rankedmatch && isdefined( self.bufferedstats ) )
            var_1 = getprestigelevel();
        else
            var_1 = 0;

        self setrank( var_0, var_1 );
        self.pers["prestige"] = var_1;
    }

    if ( isdefined( self.clientid ) && self.clientid < level.maxlogclients )
    {
        setmatchdata( "players", self.clientid, "rank", var_0 );
        setmatchdata( "players", self.clientid, "Prestige", self.pers["prestige"] );
    }
}

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

    for (;;)
    {
        common_scripts\utility::waittill_any( "giveLoadout", "changed_kit" );

        if ( issubstr( self.class, "custom" ) )
        {
            if ( !level.rankedmatch )
            {
                self.pers["rankxp"] = 0;
                continue;
            }

            if ( isai( self ) )
            {
                self.pers["rankxp"] = 0;
                continue;
            }
        }
    }
}

roundup( var_0 )
{
    if ( int( var_0 ) != var_0 )
        return int( var_0 + 1 );
    else
        return int( var_0 );
}

giverankxp( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    if ( maps\mp\_utility::is_aliens() )
        return;
    else
        giverankxp_regularmp( var_0, var_1, var_2, var_3, var_4, var_5 );
}

giverankxp_regularmp( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    self endon( "disconnect" );
    var_6 = "none";

    if ( isdefined( self.owner ) && !isbot( self ) )
    {
        self.owner giverankxp( var_0, var_1, var_2, var_3, var_4, var_5 );
        return;
    }

    if ( !isbot( self ) )
    {
        if ( isdefined( self.commanding_bot ) )
            self.commanding_bot giverankxp( var_0, var_1, var_2, var_3, var_4, var_5 );
    }

    if ( isai( self ) )
        return;

    if ( !isplayer( self ) )
        return;

    if ( !maps\mp\_utility::rankingenabled() )
    {
        if ( var_0 == "assist" )
        {
            if ( isdefined( self.taggedassist ) )
                self.taggedassist = undefined;
            else
            {
                var_7 = "assist";

                if ( level.gametype == "cranked" )
                {
                    if ( isdefined( self.cranked ) )
                        var_7 = "assist_cranked";
                }

                if ( maps\mp\_utility::_hasperk( "specialty_assists" ) )
                {
                    if ( !( self.pers["assistsToKill"] % 2 ) )
                        var_7 = "assist_to_kill";
                }

                thread xpeventpopup( var_7 );
            }
        }

        return;
    }

    if ( !isdefined( level.forceranking ) || !level.forceranking )
    {
        if ( level.teambased && ( !level.teamcount["allies"] || !level.teamcount["axis"] ) )
            return;
        else if ( !level.teambased && level.teamcount["allies"] + level.teamcount["axis"] < 2 )
            return;
    }

    if ( !isdefined( var_1 ) )
        var_1 = getscoreinfovalue( var_0 );

    if ( !isdefined( self.xpgains[var_0] ) )
        self.xpgains[var_0] = 0;

    var_8 = var_1;
    var_9 = 0;
    var_10 = 0;

    if ( isdefined( var_5 ) && maps\mp\_utility::gettimepassed() > 90000.0 )
    {
        var_11 = self;

        if ( level.teambased )
        {
            var_12 = common_scripts\utility::array_sort_with_func( level.teamlist[maps\mp\_utility::getotherteam( var_11.team )], ::is_score_a_greater_than_b );
            var_13 = common_scripts\utility::array_sort_with_func( level.teamlist[var_11.team], ::is_score_a_greater_than_b );

            if ( isdefined( var_12[0] ) && var_5 == var_12[0] )
            {
                if ( isdefined( var_13[1] ) && var_11.score < var_13[1].score )
                {
                    var_8 = var_8 * 2.0;
                    var_11 thread xpeventpopup( "first_place_kill" );
                }
            }
            else if ( isdefined( var_12[1] ) && var_5 == var_12[1] )
            {
                if ( isdefined( var_13[2] ) && var_11.score < var_13[2].score )
                {
                    var_8 = var_8 * 1.5;
                    var_11 thread xpeventpopup( "second_place_kill" );
                }
            }
        }
        else
        {
            var_12 = common_scripts\utility::array_sort_with_func( level.players, ::is_score_a_greater_than_b );

            if ( isdefined( var_12[0] ) && var_5 == var_12[0] )
            {
                if ( isdefined( var_12[1] ) && var_11.score < var_12[1].score )
                {
                    var_8 = var_8 * 2.0;
                    var_11 thread xpeventpopup( "first_place_kill" );
                }
            }
            else if ( isdefined( var_12[1] ) && var_5 == var_12[1] )
            {
                if ( isdefined( var_12[2] ) && var_11.score < var_12[2].score )
                {
                    var_8 = var_8 * 1.5;
                    var_11 thread xpeventpopup( "second_place_kill" );
                }
            }
            else if ( isdefined( var_12[2] ) && var_5 == var_12[2] )
            {
                if ( isdefined( var_12[2] ) && var_11.score < var_12[2].score )
                {
                    var_8 = var_8 * 1.5;
                    var_11 thread xpeventpopup( "third_place_kill" );
                }
            }
        }

        var_14 = var_11.killsthislife.size + 1;

        if ( var_14 > 2 )
        {
            if ( !( var_14 % 5 ) )
            {
                if ( !isdefined( var_11.lastkillsplash ) || var_14 != var_11.lastkillsplash )
                {
                    var_11 thread maps\mp\_utility::teamplayercardsplash( "callout_kill_streaking", var_11, undefined, var_14 );
                    var_11.lastkillsplash = var_14;
                }
            }
        }
    }

    var_15 = 0;
    var_16 = 0;

    switch ( var_0 )
    {
        case "shield_damage":
        case "headshot":
        case "kill":
            var_8 = var_8 * self.xpscaler;
        case "assist":
        case "kill_head":
        case "kill_melee":
        case "kill_normal":
        case "damage_head":
        case "damage_body":
        case "jugg_on_jugg":
        case "kill_juggernaut":
        case "kill_as_juggernaut":
        case "got_juggernaut":
        case "dropped_enemy_gun_rank":
        case "gained_gun_rank":
        case "final_rogue":
        case "survivor":
        case "draft_rogue":
        case "kill_carrier":
        case "kill_bonus":
        case "team_assist":
        case "tags_retrieved":
        case "kill_denied":
        case "kill_confirmed":
        case "defuse":
        case "save":
        case "plant":
        case "pickup":
        case "obj_return":
        case "defend":
        case "capture":
        case "teamkill":
        case "assault":
        case "suicide":
        case "destroy":
            if ( maps\mp\_utility::getgametypenumlives() > 0 && var_0 != "shield_damage" )
            {
                if ( !isdefined( level.skiplivesxpscalar ) || !level.skiplivesxpscalar )
                {
                    if ( level.gametype == "sd" )
                        var_17 = max( 1, int( 10 / maps\mp\_utility::getgametypenumlives() ) );
                    else
                        var_17 = max( 1, int( 5 / maps\mp\_utility::getgametypenumlives() ) );

                    var_8 = int( var_8 * var_17 );
                }
            }

            var_18 = 0;

            if ( issquadsmode() )
            {
                if ( self.prestigedoublexp )
                {
                    var_19 = self getrankedplayerdata( "prestigeDoubleXpTimePlayed" );

                    if ( var_19 >= self.bufferedstatsmax["prestigeDoubleXpMaxTimePlayed"] )
                    {
                        self setrankedplayerdata( "prestigeDoubleXp", 0 );
                        self setrankedplayerdata( "prestigeDoubleXpTimePlayed", 0 );
                        self setrankedplayerdata( "prestigeDoubleXpMaxTimePlayed", 0 );
                        self.prestigedoublexp = 0;
                    }
                    else
                        var_18 = 1.1;
                }
            }

            var_9 = getxpmultiplier();
            var_10 = self getclanwarsbonus();

            if ( var_18 > 0 )
                var_8 = int( var_8 * var_18 );

            var_20 = 1;

            if ( level.teambased )
                var_20 = level.teamxpscale[self.team];
            else if ( isdefined( level.teamxpscale[self getentitynumber()] ) )
                var_20 = level.teamxpscale[self getentitynumber()];

            var_8 = int( var_8 * level.xpscale * var_20 );

            if ( isdefined( level.nukedetonated ) && level.nukedetonated )
            {
                if ( level.teambased && level.nukeinfo.team == self.team )
                    var_8 = var_8 * level.nukeinfo.xpscalar;
                else if ( !level.teambased && level.nukeinfo.player == self )
                    var_8 = var_8 * level.nukeinfo.xpscalar;

                var_8 = int( var_8 );
            }

            var_21 = getrestxpaward( var_8 );
            var_8 = var_8 + var_21;

            if ( var_21 > 0 )
            {
                if ( islastrestxpaward( var_8 ) )
                    thread maps\mp\gametypes\_hud_message::splashnotify( "rested_done" );

                var_16 = 1;
            }

            break;
        case "challenge":
            var_10 = self getclanwarsbonus();
            var_9 = getxpmultiplier();
            break;
        case "operation":
            var_9 = 0;

            if ( self getrankedplayerdata( "challengeXPMultiplierTimePlayed", 0 ) < self.bufferedchildstatsmax["challengeXPMaxMultiplierTimePlayed"][0] )
                var_9 = var_9 + int( self getrankedplayerdata( "challengeXPMultiplier", 0 ) );

            break;
        default:
            var_10 = self getclanwarsbonus();
            var_9 = getxpmultiplier();
            break;
    }

    if ( level.maxforbotmatch && self.pers["xpEarnedThisMatch"] > level.maxforbotmatch )
    {
        if ( !isdefined( level.skippointdisplayxp ) )
            thread xppointspopup( var_8, var_15 );

        var_8 = 0;

        if ( self.pers["xpEarnedThisMatch"] != 999790 )
        {
            thread maps\mp\gametypes\_hud_message::splashnotifydelayed( "max_xp_for_match" );
            thread maps\mp\killstreaks\_killstreaks::givekillstreak( "airdrop_assault", 0, 0, self );
            self thread [[ level.leaderdialogonplayer_func ]]( "achieve_carepackage", undefined, undefined, self.origin );
            self.pers["xpEarnedThisMatch"] = 999790;
        }
    }

    var_22 = int( max( var_8 * var_9 - var_8, 0 ) );
    var_23 = int( var_8 * var_10 );
    var_24 = getrankxp();
    incrankxp( var_8 + var_22 + var_23 );

    if ( maps\mp\_utility::rankingenabled() && updaterank( var_24 ) )
    {
        thread updaterankannouncehud();
        var_25 = getrank();

        if ( var_25 < 5 )
            giveunlockpoints( 5, 0 );
        else
            giveunlockpoints( 2, 0 );
    }

    syncxpstat();
    var_26 = maps\mp\gametypes\_missions::isweaponchallenge( var_4 );

    if ( var_26 )
        var_2 = self getcurrentweapon();

    if ( var_0 == "shield_damage" )
    {
        var_2 = self getcurrentweapon();
        var_3 = "MOD_MELEE";
    }

    if ( !level.hardcoremode )
    {
        if ( !isdefined( level.skippointdisplayxp ) )
            thread xppointspopup( var_8, var_15 );

        if ( var_0 == "assist" )
        {
            if ( isdefined( self.taggedassist ) )
                self.taggedassist = undefined;
            else
            {
                var_7 = "assist";

                if ( level.gametype == "cranked" )
                {
                    if ( isdefined( self.cranked ) )
                        var_7 = "assist_cranked";
                }

                if ( maps\mp\_utility::_hasperk( "specialty_assists" ) )
                {
                    if ( !( self.pers["assistsToKill"] % 2 ) )
                        var_7 = "assist_to_kill";
                }

                thread xpeventpopup( var_7 );
            }
        }
    }

    switch ( var_0 )
    {
        case "assist":
        case "kill_head":
        case "kill_melee":
        case "kill_normal":
        case "damage_head":
        case "damage_body":
        case "jugg_on_jugg":
        case "kill_juggernaut":
        case "kill_as_juggernaut":
        case "got_juggernaut":
        case "dropped_enemy_gun_rank":
        case "gained_gun_rank":
        case "final_rogue":
        case "survivor":
        case "draft_rogue":
        case "kill_carrier":
        case "kill_bonus":
        case "team_assist":
        case "tags_retrieved":
        case "kill_denied":
        case "kill_confirmed":
        case "defuse":
        case "plant":
        case "pickup":
        case "obj_return":
        case "defend":
        case "capture":
        case "teamkill":
        case "headshot":
        case "kill":
        case "assault":
        case "suicide":
            self.pers["summary"]["score"] = self.pers["summary"]["score"] + var_8;
            self.pers["summary"]["entitlementXP"] = self.pers["summary"]["entitlementXP"] + var_22;
            self.pers["summary"]["clanWarsXP"] = self.pers["summary"]["clanWarsXP"] + var_23;
            self.pers["summary"]["xp"] = self.pers["summary"]["xp"] + ( var_8 + var_22 + var_23 );
            break;
        case "loss":
        case "win":
        case "tie":
            self.pers["summary"]["match"] = self.pers["summary"]["match"] + var_8;
            self.pers["summary"]["xp"] = self.pers["summary"]["xp"] + var_8;
            break;
        case "challenge":
            self.pers["summary"]["challenge"] = self.pers["summary"]["challenge"] + var_8;
            self.pers["summary"]["entitlementXP"] = self.pers["summary"]["entitlementXP"] + var_22;
            self.pers["summary"]["clanWarsXP"] = self.pers["summary"]["clanWarsXP"] + var_23;
            self.pers["summary"]["xp"] = self.pers["summary"]["xp"] + ( var_8 + var_22 + var_23 );
            break;
        case "operation":
            self.pers["summary"]["entitlementXP"] = self.pers["summary"]["entitlementXP"] + var_22;
            self.pers["summary"]["operation"] = self.pers["summary"]["operation"] + var_8;
            self.pers["summary"]["xp"] = self.pers["summary"]["xp"] + ( var_8 + var_22 );
            break;
        default:
            self.pers["summary"]["misc"] = self.pers["summary"]["misc"] + var_8;
            self.pers["summary"]["entitlementXP"] = self.pers["summary"]["entitlementXP"] + var_22;
            self.pers["summary"]["clanWarsXP"] = self.pers["summary"]["clanWarsXP"] + var_23;
            self.pers["summary"]["xp"] = self.pers["summary"]["xp"] + ( var_8 + var_22 + var_23 );
            break;
    }
}

is_score_a_greater_than_b( var_0, var_1 )
{
    return var_0.score > var_1.score;
}

getxpmultiplier()
{
    var_0 = 0;

    for ( var_1 = 0; var_1 < 3; var_1++ )
    {
        var_2 = self getrankedplayerdata( "xpMultiplierTimePlayed", var_1 );
        var_3 = self.bufferedchildstatsmax["xpMaxMultiplierTimePlayed"][var_1];

        if ( var_2 < var_3 )
            var_0 = var_0 + int( self getrankedplayerdata( "xpMultiplier", var_1 ) );
    }

    return var_0;
}

weaponshouldgetxp( var_0, var_1 )
{
    if ( self isitemunlocked( "cac" ) && !maps\mp\_utility::isjuggernaut() && isdefined( var_0 ) && isdefined( var_1 ) && !maps\mp\_utility::iskillstreakweapon( var_0 ) )
    {
        if ( maps\mp\_utility::isbulletdamage( var_1 ) )
            return 1;

        if ( isexplosivedamagemod( var_1 ) || var_1 == "MOD_IMPACT" )
        {
            if ( maps\mp\_utility::getweaponclass( var_0 ) == "weapon_projectile" || maps\mp\_utility::getweaponclass( var_0 ) == "weapon_assault" )
                return 1;
        }

        if ( var_1 == "MOD_MELEE" )
        {
            if ( maps\mp\_utility::getweaponclass( var_0 ) == "weapon_riot" )
                return 1;
        }
    }

    return 0;
}

charactertypebonusxp( var_0, var_1 )
{
    var_2 = 1.2;

    if ( isdefined( var_0 ) && isdefined( self.character_type ) )
    {
        switch ( maps\mp\_utility::getweaponclass( var_0 ) )
        {
            case "weapon_smg":
                if ( self.character_type == "charactertype_smg" )
                    var_1 = var_1 * var_2;

                break;
            case "weapon_assault":
                if ( self.character_type == "charactertype_assault" )
                    var_1 = var_1 * var_2;

                break;
            case "weapon_shotgun":
                if ( self.character_type == "charactertype_shotgun" )
                    var_1 = var_1 * var_2;

                break;
            case "weapon_dmr":
                if ( self.character_type == "charactertype_dmr" )
                    var_1 = var_1 * var_2;

                break;
            case "weapon_sniper":
                if ( self.character_type == "charactertype_sniper" )
                    var_1 = var_1 * var_2;

                break;
            case "weapon_lmg":
                if ( self.character_type == "charactertype_lmg" )
                    var_1 = var_1 * var_2;

                break;
            default:
                break;
        }
    }

    return int( var_1 );
}

updaterank( var_0 )
{
    var_1 = getrank();

    if ( var_1 == self.pers["rank"] || self.pers["rank"] == level.maxrank )
        return 0;

    var_2 = self.pers["rank"];
    self.pers["rank"] = var_1;
    self setrank( var_1 );
    return 1;
}

updaterankannouncehud()
{
    self endon( "disconnect" );
    self notify( "update_rank" );
    self endon( "update_rank" );
    var_0 = self.pers["team"];

    if ( !isdefined( var_0 ) )
        return;

    if ( !maps\mp\_utility::levelflag( "game_over" ) )
        level common_scripts\utility::waittill_notify_or_timeout( "game_over", 0.25 );

    var_1 = getrankinfofull( self.pers["rank"] );
    var_2 = level.ranktable[self.pers["rank"]][1];
    var_3 = int( var_2[var_2.size - 1] );
    thread maps\mp\gametypes\_hud_message::splashnotifyurgent( "ranked_up", self.pers["rank"] );

    if ( var_3 > 1 )
        return;

    for ( var_4 = 0; var_4 < level.players.size; var_4++ )
    {
        var_5 = level.players[var_4];
        var_6 = var_5.pers["team"];

        if ( isdefined( var_6 ) && var_5 != self )
        {
            if ( var_6 == var_0 )
                var_5 iprintln( &"RANK_PLAYER_WAS_PROMOTED", self, var_1 );
        }
    }
}

endgameupdate()
{
    var_0 = self;
}

xppointspopup( var_0, var_1 )
{
    self endon( "disconnect" );
    self endon( "joined_team" );
    self endon( "joined_spectators" );

    if ( var_0 == 0 )
        return;

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

    self notify( "xpPointsPopup" );
    self endon( "xpPointsPopup" );
    self.xpupdatetotal = self.xpupdatetotal + var_0;
    self.bonusupdatetotal = self.bonusupdatetotal + var_1;
    self setclientomnvar( "ui_points_popup", self.xpupdatetotal );
    var_2 = max( int( self.bonusupdatetotal / 20 ), 1 );

    if ( self.bonusupdatetotal )
    {
        while ( self.bonusupdatetotal > 0 )
        {
            self.xpupdatetotal = self.xpupdatetotal + min( self.bonusupdatetotal, var_2 );
            self.bonusupdatetotal = self.bonusupdatetotal - min( self.bonusupdatetotal, var_2 );
            wait 0.05;
        }
    }
    else
        wait 1.0;

    self.xpupdatetotal = 0;
}

xpeventpopupfinalize( var_0 )
{
    self endon( "disconnect" );
    self endon( "joined_team" );
    self endon( "joined_spectators" );
    self notify( "xpEventPopup" );
    self endon( "xpEventPopup" );

    if ( level.hardcoremode )
        return;

    if ( !isdefined( self ) )
        return;

    var_1 = tablelookuprownum( "mp/xp_event_table.csv", 0, var_0 );

    if ( !isdefined( var_1 ) || isdefined( var_1 ) && var_1 == -1 )
        return;

    self setclientomnvar( "ui_points_popup_desc", var_1 );
    wait 1.0;

    if ( !isdefined( self ) )
        return;

    self notify( "PopComplete" );
}

xpeventpopup( var_0 )
{
    if ( maps\mp\_utility::is_aliens() )
        return;
    else
        xpeventpopup_regularmp( var_0 );
}

xpeventpopup_regularmp( var_0 )
{
    if ( isdefined( self.owner ) )
        self.owner xpeventpopup( var_0 );

    if ( !isplayer( self ) )
        return;

    thread xpeventpopupfinalize( var_0 );
}

getrank()
{
    var_0 = self.pers["rankxp"];
    var_1 = self.pers["rank"];

    if ( var_0 < getrankinfominxp( var_1 ) + getrankinfoxpamt( var_1 ) )
        return var_1;
    else
        return getrankforxp( var_0 );
}

getweaponrank( var_0 )
{
    var_1 = self getrankedplayerdata( "weaponXP", var_0 );
    return getweaponrankforxp( var_1, var_0 );
}

levelforexperience( var_0 )
{
    return getrankforxp( var_0 );
}

weaponlevelforexperience( var_0 )
{
    return getweaponrankforxp( var_0 );
}

getcurrentweaponxp()
{
    var_0 = self getcurrentweapon();

    if ( isdefined( var_0 ) )
        return self getrankedplayerdata( "weaponXP", var_0 );

    return 0;
}

getrankforxp( var_0 )
{
    var_1 = 0;
    var_2 = level.ranktable[var_1][1];

    while ( isdefined( var_2 ) && var_2 != "" )
    {
        if ( var_0 < getrankinfominxp( var_1 ) + getrankinfoxpamt( var_1 ) )
            return var_1;

        var_1++;

        if ( isdefined( level.ranktable[var_1] ) )
        {
            var_2 = level.ranktable[var_1][1];
            continue;
        }

        var_2 = undefined;
    }

    var_1--;
    return var_1;
}

getweaponrankforxp( var_0, var_1 )
{
    if ( !isdefined( var_0 ) )
        var_0 = 0;

    var_2 = tablelookup( "mp/statsTable.csv", 4, var_1, 2 );
    var_3 = int( tablelookup( "mp/weaponRankTable.csv", 0, var_2, 1 ) );

    for ( var_4 = 0; var_4 < var_3 + 1; var_4++ )
    {
        if ( var_0 < getweaponrankinfominxp( var_4 ) + getweaponrankinfoxpamt( var_4 ) )
            return var_4;
    }

    return var_4 - 1;
}

getspm()
{
    var_0 = getrank() + 1;
    return ( 3 + var_0 * 0.5 ) * 10;
}

getprestigelevel()
{
    if ( isai( self ) && isdefined( self.pers["prestige_fake"] ) )
        return self.pers["prestige_fake"];
    else
        return maps\mp\gametypes\_persistence::statget( "prestige" );
}

getrankxp()
{
    return self.pers["rankxp"];
}

getweaponrankxp( var_0 )
{
    return self getrankedplayerdata( "weaponXP", var_0 );
}

getweaponmaxrankxp( var_0 )
{
    var_1 = tablelookup( "mp/statsTable.csv", 4, var_0, 2 );
    var_2 = int( tablelookup( "mp/weaponRankTable.csv", 0, var_1, 1 ) );
    var_3 = getweaponrankinfomaxxp( var_2 );
    return var_3;
}

isweaponmaxrank( var_0 )
{
    var_1 = self getrankedplayerdata( "weaponXP", var_0 );
    var_2 = getweaponmaxrankxp( var_0 );
    return var_1 >= var_2;
}

giveunlockpoints( var_0, var_1 )
{
    if ( !isdefined( var_1 ) )
        var_2 = 1;

    var_3 = self.pers["activeSquadMember"];
    var_4 = self getrankedplayerdata( "squadMembers", var_3, "commendationsEarned" );
    var_4 = var_4 + var_0;
    self setrankedplayerdata( "squadMembers", var_3, "commendationsEarned", var_4 );

    if ( var_1 )
        thread maps\mp\gametypes\_hud_message::playercardsplashnotify( "earned_unlock", self );

    var_5 = self getrankedplayerdata( "unlockPoints" );
    var_6 = var_5 + var_0;
    self setrankedplayerdata( "unlockPoints", var_6 );
}

incrankxp( var_0 )
{
    if ( !maps\mp\_utility::rankingenabled() )
        return;

    if ( isai( self ) )
        return;

    var_1 = self getrankedplayerdata( "points" );
    var_2 = var_1 + var_0;
    var_2 = int( clamp( var_2, 0, 5999 ) );

    if ( var_2 >= 3000 )
    {
        var_2 = var_2 % 3000;
        self setrankedplayerdata( "points", var_2 );
        giveunlockpoints( 1, 1 );
    }
    else
        self setrankedplayerdata( "points", var_2 );

    var_3 = getrankxp();
    var_4 = int( min( var_3, getrankinfomaxxp( level.maxrank ) ) ) + var_0;

    if ( self.pers["rank"] == level.maxrank && var_4 >= getrankinfomaxxp( level.maxrank ) )
        var_4 = getrankinfomaxxp( level.maxrank );

    self.pers["xpEarnedThisMatch"] = self.pers["xpEarnedThisMatch"] + var_0;
    self.pers["rankxp"] = var_4;
}

getrestxpaward( var_0 )
{
    if ( !getdvarint( "scr_restxp_enable" ) )
        return 0;

    var_1 = getdvarfloat( "scr_restxp_restedAwardScale" );
    var_2 = int( var_0 * var_1 );
    var_3 = self getrankedplayerdata( "restXPGoal" ) - getrankxp();

    if ( var_3 <= 0 )
        return 0;

    return var_2;
}

islastrestxpaward( var_0 )
{
    if ( !getdvarint( "scr_restxp_enable" ) )
        return 0;

    var_1 = getdvarfloat( "scr_restxp_restedAwardScale" );
    var_2 = int( var_0 * var_1 );
    var_3 = self getrankedplayerdata( "restXPGoal" ) - getrankxp();

    if ( var_3 <= 0 )
        return 0;

    if ( var_2 >= var_3 )
        return 1;

    return 0;
}

syncxpstat()
{
    if ( level.xpscale > 4 || level.xpscale <= 0 )
        exitlevel( 0 );

    var_0 = getrankxp();
    var_1 = self.pers["activeSquadMember"];
    self setrankedplayerdata( "squadMembers", var_1, "squadMemXP", var_0 );
    self setrankedplayerdata( "experience", var_0 );

    if ( var_0 >= getrankinfomaxxp( level.maxrank ) )
    {
        var_3 = self getrankedplayerdata( "characterXP", var_1 );

        if ( var_3 == 0 )
        {
            var_4 = getsystemtime();
            self setrankedplayerdata( "characterXP", var_1, var_4 );
            var_5 = self getrankedplayerdatareservedint( "prestigeLevel" );
            var_6 = var_5 + 1;
            self setrankedplayerdatareservedint( "prestigeLevel", var_6 );
            self setrank( level.maxrank, var_6 );
            thread maps\mp\gametypes\_hud_message::splashnotifyurgent( "prestige" + var_6 );
            var_7 = self.pers["team"];

            for ( var_8 = 0; var_8 < level.players.size; var_8++ )
            {
                var_9 = level.players[var_8];
                var_10 = var_9.pers["team"];

                if ( isdefined( var_10 ) && var_9 != self )
                {
                    if ( var_10 == var_7 )
                        var_9 iprintln( &"RANK_PLAYER_WAS_PROMOTED", self, &"MPUI_PRESTIGE" );
                }
            }
        }
    }
}

createmultipliertext()
{
    var_0 = newclienthudelem( self );
    var_0.horzalign = "center";
    var_0.vertalign = "bottom";
    var_0.alignx = "center";
    var_0.aligny = "middle";
    var_0.x = 70;

    if ( level.splitscreen )
        var_0.y = -55;
    else
        var_0.y = -10;

    var_0.font = "default";
    var_0.fontscale = 1.3;
    var_0.archived = 0;
    var_0.color = ( 1, 1, 1 );
    var_0.sort = 10000;
    var_0 maps\mp\gametypes\_hud::fontpulseinit( 1.5 );
    return var_0;
}

multipliertextpopup( var_0 )
{
    self endon( "disconnect" );
    level endon( "game_ended" );
    level endon( "round_end_finished" );
    self endon( "death" );
    self notify( "multiplierTextPopup" );
    self endon( "multiplierTextPopup" );

    if ( !isdefined( self.hud_multipliertext ) )
        self.hud_multipliertext = createmultipliertext();

    wait 0.05;
    thread multipliertextpopup_watchdeath();
    thread multipliertextpopup_watchgameend();
    self.hud_multipliertext settext( var_0 );

    for (;;)
    {
        self.hud_multipliertext.alpha = 0.85;
        self.hud_multipliertext thread maps\mp\gametypes\_hud::fontpulse( self );
        wait 1.0;
        self.hud_multipliertext fadeovertime( 0.75 );
        self.hud_multipliertext.alpha = 0.25;
        wait 1.0;
    }
}

multipliertextpopup_watchdeath()
{
    self waittill( "death" );

    if ( isdefined( self.hud_multipliertext ) )
        self.hud_multipliertext.alpha = 0;
}

multipliertextpopup_watchgameend()
{
    level waittill( "game_ended" );

    if ( isdefined( self.hud_multipliertext ) )
        self.hud_multipliertext.alpha = 0;
}
