HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need help with random numbers

06-28-2007, 02:58 PM#1
Hoernchen
Hey guys,
I made a spell which randomly creates units on a certain line.
It uses
For each Integer A from 0 to no.of units - 1 do:
Create a unit at location.....

Now my trigger makes it logically appear in a line, but I want it to appear in the line, but not like ordered, but random, to increase effect.
Now I could say For each Integer Random from 0 to no. of units - 1 do:
Create a unit at location...
Set Integer Random to Random Number from 0 to no. of units...

But then I'd have the problem, that it would always create units who are created on the same spot, destroying the line, since a random number can occur twice. So I need help, how can I make a Random Number, but so that when I do it again, it picks a random number, it didnt pick yet?

Well, if anyone gets it you are a genius, cause I sat 2 hours on it and didnt...
+Rep for the person who solves it
06-28-2007, 03:19 PM#2
tamisrah
One solution would require to change your spawn triggers:
Collapse JASS:
function Spawn takes nothing returns nothing
// some stuff
    call TriggerSleepAction(GetRandomReal(0,n))
    call CreateUnit(p,id,x,y,f)
// some stuff
endfunction

function Actions takes nothing returns nothing
// some stuff
    loop
        exitwhen i>n
        call ExecuteFunc("Spawn")
        set i =i+1
    endloop
// some stuff
endfunction

This would cause the units to spawn after a random amount of time which would give you the desired effect.
06-28-2007, 03:20 PM#3
zen87
seriously I don't understand what you trying to do, can you make it more easier to understand that what you are trying to do ?
06-28-2007, 03:55 PM#4
tamisrah
You call the CreateUnit function after a random delay to avoid spawning them all at the same time. So you'll get the impression that they're spawned in a random order. ( this concept is taken from one of vexorians spell demos )

Else you could do check if there's already a unit before creating one:
Trigger:
Unnamed Trigger 001
Events
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 10, do (Actions)
Collapse Loop - Actions
Set loc = ((Position of (Triggering unit)) offset by ((Real((Integer A))) x 200.00) towards (Facing of (Triggering unit)) degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse IF - Conditions
(Number of units in (Units within 50.00 of loc)) Equal To 0
Collapse THEN - Actions
Unit - Create 1 Unit for (Owner of (Triggering unit)) at loc facing (Random angle) degrees
ELSE - Actions
06-29-2007, 08:27 AM#5
Hoernchen
Alright let me explain it a bit better, what I want, so you know it exactly.
I have the Hero 'Wind Runner', who has skill 'Phantom Parade', which is a copy of blink. Now the effect will be, you select Phantom Parade, then you select a target and then the 'Wind Runner' vanishes and around the target point, it starts creating N units of type 'Phantom Image', with a distance of <Range> from the point of ability being cast, so that every unit has the same distance from each other and the center of the created circle.
Trigger:
Collapse Events
Unit - A unit starts the effect of a skill
Collapse Conditions
Ability being cast = (Phantom Parade)
Collapse Actions
Set temppoint = (Target point of ability being cast)
Set H = Integer(X of(temppoint))
Set K = Integer(Y of (temppoint))
Set radius = 450
Set surroundtime = 2
Set N = 24
Set startalpha = (Random integer number between 0 and 359)
Set delta = (360/(Real(N)))
Set direction = (Random integer number between -1 and 1)
Collapse If (All Conditions Are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
direction equal to 0.00
Collapse Then - Actions
Set direction to 1
Collapse Else - Actions
Do nothing
Unit - Hide (Casting unit)
Collapse For each (Integer A) from 0 to (N-1), do (Actions)
Collapse Loop - Actions
Wait ((Real(Surroundtime))/(Real(N))) seconds
Set alpha = ((delta*((Real((Integer A)))*(Sign(direction)))) + (Real(startalpha)))
Set midpeacex1 = (Cos(alpha))
Set midpeacey1 = (Sin(alpha))
Set midpeacex2 = ((Real(radius))*midpeacex1)
Set midpeacey2 = ((Real(radius))*midpeacey1)
Set X = (H + (Integer(midpeacex2)))
Set Y = (K + (Integer(midpeacey2)))
Unit - Create 1 Phantom Image for (Owner of (Casting unit)) at Point((Real(X)), (Real(Y))) facing (alpha + 180) degrees
Special effect - Create a special effect at (position of (Last created unit)) using Abilities\Spells\Orc\MirrorImage\MirrorImageCaster.mdl
Unit - Unhide (Casting unit)

Alright so that works good, it makes a circle appear over 2 seconds made of 24 units within 450 range. Now, what I want to do, is make, that instead of the units appearing in a regular line, the 1st unit, then the 2nd, then the 3rd and so on, I want it to be so that 1st one unit, then another one spawns, but not next to, but at a random one of the 24 spots on the circle. So basically instead of For each (Integer A) from 0 to (n-1), do actions:
i want: For each (Integer A) from 0 to (n-1), do actions in no particular order, like 3, 22, 1, 7, 12, 14 , so not that its 1,2,3,4, but totally random
06-29-2007, 10:17 AM#6
Pyrogasm
First off, since you're using waits in an integer A loop, you'll want to change the "For each (Integer A)" part to "For each integer (Variable)" and create a new variable for this spell specifically. (I called mine IllusionLoopCounter)

Then, create an integer array and add something like this as the beginning of your loop:
Trigger:
Collapse For each (Integer B) from 1 to N do (Actions)
Collapse Loop - Actions
Set UsedIntegers[(Integer B)] = 0
Set RandomInteger = Random Integer number between 1 and N
Set TempInteger = 0
Custom script: loop
Set TempInteger = TempInteger + 1
Custom script: exitwhen udg_TempInteger > udg_N
Collapse If (All conditions are true) then do (Then actions) else do (Else actions)
Collapse If - Conditions
RandomInteger equal to UsedIntegers[TempInteger]
Collapse Then - Actions
Set RandomInteger = Random Integer number between 1 and N
Set TempInteger = 0
Else - Actions
Custom script: endloop
For each (Integer B) from 1 to N do (If (UsedIntegers[(Integer B)] equal to 0) then do (Set UsedIntegers[(Integer B)] = RandomInteger)) else do (Do nothing)
And then reference "RandomInteger" instead of "Integer A" in the rest of the loop, as follows:
Trigger:
Collapse Events
Unit - A unit starts the effect of a skill
Collapse Conditions
Ability being cast = (Phantom Parade)
Collapse Actions
Set temppoint = (Target point of ability being cast)
Set H = Integer(X of(temppoint))
Set K = Integer(Y of (temppoint)
Set radius = 450
Set surroundtime = 2
Set N = 24
Set startalpha = (Random integer number between 0 and 359)
Set delta = (360/(Real(N)))
Set direction = (Random integer number between -1 and 1)
Collapse If (All Conditions Are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
direction equal to 0.00
Collapse Then - Actions
Set direction to 1
Else - Actions
Unit - Hide (Casting unit)
Collapse For each (Integer IllusionLoopCounter) from 1 to (N), do (Actions)
Collapse Loop - Actions
Collapse For each (Integer B) from 1 to N do (Actions)
Collapse Loop - Actions
Set UsedIntegers[(Integer B)] = 0
Set RandomInteger = Random Integer number between 1 and N
Set TempInteger = 0
Custom script: loop
Set TempInteger = TempInteger + 1
Custom script: exitwhen udg_TempInteger > udg_N
Collapse If (All conditions are true) then do (Then actions) else do (Else actions)
Collapse If - Conditions
RandomInteger equal to UsedIntegers[TempInteger]
Collapse Then - Actions
Set RandomInteger = Random Integer number between 1 and N
Set TempInteger = 0
Else - Actions
Custom script: endloop
For each (Integer B) from 1 to N do (If (UsedIntegers[(Integer B)] equal to 0) then do (Set UsedIntegers[(Integer B)] = RandomInteger)) else do (Do nothing)
Wait ((Real(Surroundtime))/(Real(N))) seconds
Set alpha = ((delta*((Real(RandomInteger))*(Sign(direction)))) + (Real(startalpha)))
Set midpeacex1 = (Cos(alpha))
Set midpeacey1 = (Sin(alpha))
Set midpeacex2 = ((Real(radius))*midpeacex1)
Set midpeacey2 = ((Real(radius))*midpeacey1)
Set X = (H + (Integer(midpeacex2)))
Set Y = (K + (Integer(midpeacey2)))
Unit - Create 1 Phantom Image for (Owner of (Triggering unit)) at Point((Real(X)), (Real(Y))) facing (alpha + 180) degrees
Special effect - Create a special effect at (position of (Last created unit)) using Abilities\Spells\Orc\MirrorImage\MirrorImageCaster.mdl
Unit - Unhide (Triggering unit)
And you should have created these new variables, all of type "integer":
Table:
NameArray?
IllusionLoopCounterNo
RandomIntegerNo
TempIntegerNo
UsedIntegersYes
06-30-2007, 09:20 AM#7
Hoernchen
hey thanks for the great help, but now ive already found a good way to do it, but hey thanks anyway, for the effort +rep
i did it with this:
Trigger:
Collapse For each Integer A from 0 to (N-1), do actions:
Unit - Create 1 DummyCounter for (Owner of(casting unit)) at someplace facing anydegrees
Unit - Set custom value for (last created unit) to Integer A
Unit Group - Add (last created unit) to tempgroup
Collapse For each Integer A from 0 to (N-1), do actions:
Collapse Unit Group - Pick every 1 units in tempgroup, and do:
Set Randomnumber[Integer A] = (Customvalue of (picked unit))
Unit Group - Remove (picked unit) from tempgroup
Unit - Remove (picked unit) from game
And then i changed the part where it says set alpha
Trigger:
For each Integer A from 0 to (N-1), do actions:
Set alpha = ((delta*((Real(RandomNumber[((Integer A]))
...rest of formula