ItsMods

Full Version: Changing array if same values exist.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ey guys got a problem with my gungame script for WAW. Currently it goes through a for loop and select a new weapon based on an array list using strTok; and, sometimes the script would select a weapon that's already used in another part of that array. I tried fixing it by doing a backwards array but I got it wrong.... So, I resorted to just another function with the array parameter to check for the weapon and it returned true/false so it would reselect the weapon but it's not working either.

Functions used:
Code:
selectRandomWeapons()
{
    if( !isDefined( level.gg_weapons ) )
        level.gg_weapons = [];
    if( !isDefined( level.kill_max ) )
        level.kill_max = [];

    kill_max = 0;
    kills_increment = getDvarInt("scr_zom_kill_increment");
    if( level.max_level <= 0 || level.max_level > 18 )
        level.max_level = 12;
    
    for( i = 0; i <= level.max_level; i++ )
    {
        kill_max += kills_increment;
        val = randomIntRange( 0, 4 );
        level.gg_weapons[i] = selectWeapon( val );
        level.kill_max[i] = kill_max;

        check_weapon = level.gg_weapons[i];
        while( checkIfUsed( check_weapon ) )
            check_weapon = selectWeapon( val );
    }
}

Code:
checkIfUsed( weapon )
{
    if( !isDefined( weapon ) )
        return;

    for( i = 0; i < level.gg_weapons.size; i++ )
    {
        if( level.gg_weapons[i] == weapon )
            return true;
        else
            return false;
    }
}
I may or may not be stupid and forget to set value again.