Couldn't find a good title for my problem so sorry for that.
I have a problem where I have a 2D array of [2][5] each with a real value:
array[1][1] = 25.00
array[1][2] = 17.00
array[1][3] = 31.00
array[1][4] = 5.00
array[1][5] = 15.00
and the values of [2][..]
all have diffrent values
also all values can change at any given time
now these values are just an example
ok now i want to do a chance based thing on them, but I have no idea how to do that.
for example all these values represent the chance of a unit spawning, and every second I want to spawn a unit. Now the total chance (if you add all values.) is 93%, but I want to spawn a unit everytime not only 93% of the time.
So how would I summon a unit based on the chances in the array?
If I understood well, you want a unit to be spawned more or less often depending on its type? Well, just pick a random value from 1 to 100 each time you want to spawn a unit, and check if the picked value is higher than the value in your array (assuming the values in your array is the percentage of chance it will spawn). Spawn the unit if random picked value > value in the array corresponding to the unit type you want to spawn. Is that what you wanted? I assume the first [1] is the player owning the units, and the second value in brackets is for the unit type, right?
If you want to spawn only the unit with the highest percentage, it might be a bit harder but not impossible at all.
I'm not sure what you're trying to do... You want a unit to be spawned, whatever happens, but the type of unit is determined by which array have the highest percentage?
Hmm let me think of a better example....
See the array as bags, the first value of the array says wich bag you currently have, and all the second values as a presents.
The higher the value the bigger the present so it has more chance to be picked.
Although you can also pick the small present even if the bigger presents are still in.
That might just work testing now.
Edit: ok now I have another question for the above post.
How would I do the above if the array's size can be changed and I don't want to edit the trigger that handles that?
Hey,
Couldn't find a good title for my problem so sorry for that.
I have a problem where I have a 2D array of [2][5] each with a real value:
array[1][1] = 25.00
array[1][2] = 17.00
array[1][3] = 31.00
array[1][4] = 5.00
array[1][5] = 15.00
and the values of [2][..]
all have diffrent values
also all values can change at any given time
now these values are just an example
ok now i want to do a chance based thing on them, but I have no idea how to do that.
for example all these values represent the chance of a unit spawning, and every second I want to spawn a unit. Now the total chance (if you add all values.) is 93%, but I want to spawn a unit everytime not only 93% of the time.
So how would I summon a unit based on the chances in the array?
I hope I made myself clear;)
Thanks!
@dudeim: Go
If I understood well, you want a unit to be spawned more or less often depending on its type? Well, just pick a random value from 1 to 100 each time you want to spawn a unit, and check if the picked value is higher than the value in your array (assuming the values in your array is the percentage of chance it will spawn). Spawn the unit if random picked value > value in the array corresponding to the unit type you want to spawn. Is that what you wanted? I assume the first [1] is the player owning the units, and the second value in brackets is for the unit type, right?
If you want to spawn only the unit with the highest percentage, it might be a bit harder but not impossible at all.
Well I thought of the random value between 1 and 100 but then if I have those 5 values and check them:
if array[1][1] > rand int 1,100 then
....
elseif array[1][2] > rand int 1,100 then etc..
as the value array[1][1] is greater then array [1][2] the thing when [1][2] is picked will never happen is it will always trigger the first one.
it's like:
if 25>(1,100) then
elseif 10>(1,100) then
if the value randomly picked is for example 8 then it will say
if 25>8 then
elseif 10>8 then
well as 25 is greater then 8 the "if" will stop there and will never reach the elseif and that's the one I then want to pick.
I'm not sure what you're trying to do... You want a unit to be spawned, whatever happens, but the type of unit is determined by which array have the highest percentage?
Hmm let me think of a better example....
See the array as bags, the first value of the array says wich bag you currently have, and all the second values as a presents.
The higher the value the bigger the present so it has more chance to be picked.
Although you can also pick the small present even if the bigger presents are still in.
@dudeim: Go
If I get what you're trying to do, something like the following might work:
(This is just off the top of my head, and could probably be done in a neater fashion.)
real arrayTotal = array[0][0] + array[0][1] + array[0][2] + array[0][3] + array[0][4];
real randomValue = random real between 0 and arrayTotal;
int chosenArrayIndex;
if ( randomValue < array[0][0] ){
chosenArrayIndex = 0;
} else if ( randomValue < array[0][0] + array[0][1] ){
chosenArrayIndex = 1;
} else if ( randomValue < array[0][0] + array[0][1] + array[0][2] ){
chosenArrayIndex = 2;
} else if ( randomValue < array[0][0] + array[0][1] + array[0][2] + array[0][3] ){
chosenArrayIndex = 3;
} else {
chosenArrayIndex = 4;
};
and from here you would spawn the unit depending on the chosenArrayIndexValue.
That might just work testing now.
Edit: ok now I have another question for the above post.
How would I do the above if the array's size can be changed and I don't want to edit the trigger that handles that?
Fear not!
http://forums.sc2mapster.com/resources/trigger-libraries/15552-triggers-unit-pool/
This is the answer to all your quesitons. I think so at least :P
Yep just what I needed:D thanks!