HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Making 100+ randomly triggered triggers

11-04-2003, 01:12 AM#1
Wanderer
This is going to be weird but don't worry about why i'm doing it. I like wasting my time. Actually, hopefully you'll see it if I actually get this going.

I plan to make at least 100 triggers that I want to be totally random.

For example

Every 5 seconds

Do trigger #1 or do trigger #2 or do trigger #3 or do trigger #4

Each trigger will be similar

For example

Make 5 Footmen or make 6 Footmen or make 7 Footmen or make 8 Footmen

What is the best way to do this?

The second important but not as important question is, how can I make it so that the random trigger does not repeat? Thank you.
11-04-2003, 01:18 AM#2
SpectreReturns
Youd have to turn off the trigger, and then remove it from an array so that it is not run again.
11-04-2003, 01:18 AM#3
Eriond
Turn off (This Trigger) would do it...]

Using math - Random Number between x and x would handle the random part...

There you have it.
11-04-2003, 01:26 AM#4
AllPainful
Well... Turn Off (this trigger) would not work for the triggers being run, because they are being run by the Random trigger, and triggers that are turned off can still be run by another trigger...

I suggest you make a Boolean Array called "HasRun" and name all your triggers that are run by your random trigger as numbers.

Then in the begining of the triggers being run do a check.

If HasRun[integer(string(this trigger name))] = True
then
Run trigger "run random trigger"
Cancel other actions of this trigger
else
Set variable hasrun[integer(string(this trigger name))] = True
**********

********** is where you would put the actions of the trigger...

I hope you understand what I mean...
11-04-2003, 01:29 AM#5
Wanderer
Thanks both. Guess I do have to do that. I was hoping there was an easier way. If there is, let me know!

Another important question, I can do this by doing If/Then/Else all under one trigger or by making separate triggers. Does anyone know if doing it one way will lead to a bigger or smaller file size?
11-04-2003, 01:31 AM#6
AllPainful
I don't know about making it smaller... but yes it can be done in one trigger that is "if then else".

Example to follow:

Code:
event
 Every 5 seconds of game
conditions
 ??????
actions
 Set variable RandomNum = random integer from 1 to 10
 If
   Conditions
     RandomNum = 1
   Then
     If HasRun[1] = True then Stop remaining actions else do nothing
     Set variable HasRun[1] = True
     **********
 If
   Conditions
     RandomNum = 2
   Then
     If HasRun[2] = True then Stop remaining actions else do nothing
     Set variable HasRun[2] = True
     **********
 If
   Conditions
     RandomNum = 3
   Then
     If HasRun[3] = True then Stop remaining actions else do nothing
     Set variable HasRun[3] = True
     **********
 If
   Conditions
     RandomNum = 4
   Then
     If HasRun[4] = True then Stop remaining actions else do nothing
     Set variable HasRun[4] = True
     **********
 If
   Conditions
     RandomNum = 5
   Then
     If HasRun[5] = True then Stop remaining actions else do nothing
     Set variable HasRun[5] = True
     **********
 If
   Conditions
     RandomNum = 6
   Then
     If HasRun[6] = True then Stop remaining actions else do nothing
     Set variable HasRun[6] = True
     **********
 If
   Conditions
     RandomNum = 7
   Then
     If HasRun[7] = True then Stop remaining actions else do nothing
     Set variable HasRun[7] = True
     **********
 If
   Conditions
     RandomNum = 8
   Then
     If HasRun[8] = True then Stop remaining actions else do nothing
     Set variable HasRun[8] = True
     **********
 If
   Conditions
     RandomNum = 9
   Then
     If HasRun[9] = True then Stop remaining actions else do nothing
     Set variable HasRun[9] = True
     **********
 If
   Conditions
     RandomNum = 10
   Then
     If HasRun[10] = True then Stop remaining actions else do nothing
     Set variable HasRun[10] = True
     **********


You would put your actions where the ** are for each random variable, and I set that particular trigger to stop running if the integer it chose had allready run.

11-04-2003, 01:35 AM#7
Quell
You'll need one variable named mytriggervariable that is a trigger array size 100.

Next, you'll need two triggers.
Code:
Trigger Variables
    Events
        Map initialization
    Conditions
    Actions
        Set mytriggervariable[1] = a1 <gen>
        Set mytriggervariable[2] = a2 <gen>
        Set mytriggervariable[3] = a3 <gen>
        Set mytriggervariable[4] = a4 <gen>
        Set mytriggervariable[5] = a5 <gen>
        Set mytriggervariable[6] = a6 <gen>
        Set mytriggervariable[7] = a7 <gen>
        [i]etc...[/i]

Random Runnings
    Events
        Time - Every 5.00 seconds of game time
    Conditions
    Actions
        Trigger - Run mytriggervariable[(Random integer number between 1 and 100)] (ignoring conditions)

EDIT: Huh, missed the second problem. This was taken directly from the Map Making FAQ.
Quote:
Selecting random, non-repeating elements of an array.

Replace udg_pl with the name of your array, udg_bpl is a duplicate array of the same type.


local integer x=1
local integer y
local integer z

loop
exitwhen x>12 // failsafe. 12 is the maximum size of the array
set udg_bpl[x]=udg_pl[x]
set x=x+1
endloop


set x=1 // array minimuim
loop
exitwhen x > udg_pls // pls is the actual size of the array
set y=GetRandomInt(1, (udg_pls-x)+1)
set udg_pl[x]=udg_bpl[y]

set z=y
loop
exitwhen z == udg_pls
set udg_bpl[z] = udg_bpl[z+1]

set z=z+1
endloop

set x=x+1
endloop

11-04-2003, 01:39 AM#8
Zachary_Shadow
No need to make it that complicated, here is what u can do. It's easy.

Actions
Set Random = (Random integer number between 0 and 100)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Random Equal to 0
Then - Actions
Do this
Else - Actions
Do nothing

If - Conditions
Random Equal to 1
Then - Actions
Do this
Else - Actions
Do nothing


EDIT: Doh, Didn't see All Painfuls post :P hehe
And so on, under each Then -Actions, u just put what you need it to do, if that number is set...

Piece of cake
11-04-2003, 01:41 AM#9
AllPainful
Quell has the right run trigger if you devide all the actions into seperate triggers, but you would still need the "HasRun" boolean and the check, otherwise it could run the same trigger more than 1 time.



EDIT: WOW! I actually be Zachary_Shadow to an answer? theres a first time for everything
:ggani:
11-04-2003, 01:46 AM#10
Wanderer
Thanks all, you guys are the best :D. Now that I know how to do it, i'm just hoping it doesn't make the map 50 MB in size :ggani:

When I do finish, i'm sure I will at least get a few laughs when I tell you what I did. Now is it worth it......Ah I guess so. We'll see what happens. Thanks again.
11-04-2003, 01:50 AM#11
Grater
The array method is more effecient and cleaner and makes it really easy to not repeat a trigger.

Heres how I would do it.

Trigger to fill the array.
Code:
Init
    Events
        Map initialization
    Conditions
    Actions
        Set NumberOfTriggers = (NumberOfTriggers + 1)
        Set Triggers[NumberOfTriggers] = A1 <gen>
        Set NumberOfTriggers = (NumberOfTriggers + 1)
        Set Triggers[NumberOfTriggers] = A2 <gen>
        Set NumberOfTriggers = (NumberOfTriggers + 1)
        Set Triggers[NumberOfTriggers] = A3 <gen>
...

Trigger to run a random trigger, then remove it from the array.
Code:
RunAndRemove
    Events
        Time - Every 2.00 seconds of game time
    Conditions
    Actions
        Set TempInt = (Random integer number between 1 and NumberOfTriggers)
        Trigger - Run Triggers[TempInt] (checking conditions)
        Set Triggers[TempInt] = Triggers[NumberOfTriggers]
        Set NumberOfTriggers = (NumberOfTriggers - 1)
The bottom part should be famialler to programmers, it's a recognised method to quickly and cleanly remove something from an array. If you dont know squat about that sorta stuff, then just suffice to say it works great ;)
11-04-2003, 01:55 AM#12
AllPainful
Well I ain't a programmer, but I DO see the logic behind the Clean removal (your moving the trigger at the end of the array to where the trigger just run was, and then telling the main trigger, via a variable, that there is 1 less thing in the array therefore effectivly eliminating the items at the end of the array.) And I LOVE it, sounds like the most effeciant way to do that... I might just have to keep that for future reference. :D
11-04-2003, 02:03 AM#13
Wanderer
Guess that's how i'm gonnna do it! Thanks a lot Grater :D
11-04-2003, 03:33 AM#14
dataangel
ICK! You guys are loco! Jebus this can be done easier

Event
Every 5 Seconds
Action
Create Math - Random 1 to 5 units of type Units[Math Random 1 to ... ]

Where Units is a unit-type array you've made in the variable editor. Then at map init set Units[0], Units[1], and so on, to the different unit types you want.
11-04-2003, 01:49 PM#15
Aiursrage2k
Code:
function addToList takes trigger t returns nothing
   set udg_ListBool[udg_count] = true
   set udg_List[udg_count] =  t
   set udg_count = udg_count + 1
endfunction

Code:
function resize takes nothing returns nothing
   local integer i = 0
   local integer x = 0
   loop
       exitwhen i > 100
        if udg_ListBool[i]  then
            set udg_List[x] = udg_List[i]
            set x = x + 1
        endif
       set i = i + 1
    endloop
endfunction
You will need four variables; udg_List a trigger array, udg_count an integer, udg_ListBool a boolean arary and integer SZ. First add your triggers to the list by using function addToList.

Then every x ammount of time execute a random trigger from 0 to SZ. Then set udg_ListBool[rand] to false, decrement udg_SZ by one, and finally call the function resize.