Issues with random factors

Status
Not open for further replies.
Level 30
Joined
Jan 31, 2010
Messages
3,546
So I'm projectin' and I've encountered an issue.

Basically, I have 140 types of creeps a player can face in a game. There are 70 groups of creeps, which means that, there's a preset of one ranged and one melee creep per group, and the groups are always the same. Out of them all, a player can possibly encounter only 50 every game, meaning 20 will not be played at the time.

I've tried to trigger this via simple method: setting a variable to a random value between 1 and 70, and then doing the other things. However, this has a great flaw of making it possible to encounter same creep groups more than once per game. I've also tried to add conditions to the trigger whenever a group is selected, looping the trigger until it gets a value which is not played already, but this caused both lag and is not functional.

I'm kinda trapped in place, as I'm trying to get a random number from 1 to 70, which also removes the randomed value whenever it's played per run of the trigger.

Suggestions for random factor with exclusion of randomed numbers? Or a testmap, anything can do.
 
The solution is actually quite similar to how deindexing works.

At map ini: Set MaxWaves = 70

When spawning creeps:
Set waveNumber = random number between 1 and MaxWaves
Spawn group[waveNumber]
Set group[waveNumber] = group[MaxWaves]
Set MaxWaves = MaxWaves - 1

---
In actual game
Let's say waveNumber will be number 59
After you spawn group number 59, you replace this group with the last indexed group - so new group[59] will consist of units from group[70].
The problem now, would be that group[59] and group[70] are the same group. So you decrease the index MaxWaves by 1 - now the maximum number of groups is 69.

Basically you replace the used group by last unused group.
 
Wouldn't it mean that, let's go an example since I can't explain.

Set waveNumber = random number between 1 and MaxWaves
Out of 70 groups, number 32 is selected.
Spawn group[32]
Set group[32] = group[70]
Set MaxWaves = MaxWaves - 1


Wouldn't this mean that now you can get all the creeps from 1 to 69? Or the indexing discards the 32 instead of 70? Kinda confusing.
 
You basicaly swap the last group and the picked group and lower the number of groups.

So if we have A B C D E F... X Y Z [26]
Pick random E
Swap E and LastOfRandomsGroup, which is Letter[MaxIndex]
Lower MaxIndex by 1
Now you have A B C D Z F... X Y [25]

Meaning that now you have no E to pick random, put some actions and a loop and you are done
 
Status
Not open for further replies.
Back
Top