Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Changing array if same values exist.
#1
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; } }
Do not take life too seriously. You will never get out of it alive.
[Image: UGPjFJa.jpg]
Reply

#2
I may or may not be stupid and forget to set value again.
Do not take life too seriously. You will never get out of it alive.
[Image: UGPjFJa.jpg]
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.