| 09-16-2005, 04:16 AM | #1 |
I'm making a TD that will have random units each level. The way I want the randomization to work is this: Lets say the randomization can choose from unit1, unit2, unit3, or unit4. It picks unit2. Then unit2 is removed from the availible units. So level 2 randomizes between unit1, unit3, and unit4. This goes on until there are no more units left to choose from. Then unit1, unit2, unit3, and unit4 are all added back into the availible units. This process would repeat until all the levels have been chosen. I would appreciate any help very much, and just ask if you need anything clarified. |
| 09-16-2005, 02:55 PM | #2 |
Make a unit array fill it with your units, also make a integer array fill it with numbers. //A unit array set udg_ua[0] = Marine set udg_ua[1] = Marine1 set udg_ua[2] = Marine2 set udg_ua[3] = Marine3 //An integer array set udg_ptr[0] = 0 set udg_ptr[1] = 1 set udg_ptr[2] = 2 set udg_ptr[3] = 3 //Inialize max to 3 Everytime you want to spawn: //pick a random number from 0 to max... rnd = rand(0,max) //Swap the picked index with the one at the back of the list temp = udg_ptr[max] udg_ptr[max] = udg_ptr[rnd] udg_ptr[rnd] = temp create unit of type udg_ua[udg_ptr[rnd]] //Decrease max by 1 max = max - 1 When max == 0 then put it (max) back to 3 (or whatever), this will ensure the cycle continues... |
