Chooseing A Random Region?

hunterrravyn

TH.net Regular
Reaction score
19
Okay so basicly how would i find a random region from a group of regions?

I.e 10 regions 1 is choosen at random...

If anyone could be of help it would be graetly appreciated

Sincerly Hunterrravyn
 

Jooster

New Member
Reaction score
7
Ok. So....You're going to need to variables.

1 Integer(integer)
1 Rect(rect) array (1)

so then u want to take the number of regions u want to choose from, in my case i have 4 regions. so i go and set all 4 regions as the variables in the map initialization like this

Code:
initialization
    Events
        Map initialization
    Conditions
    Actions
        Set Region_Array[1] = random rect 1 <gen>
        Set Region_Array[2] = random rect 2 <gen>
        Set Region_Array[3] = random rect 3 <gen>
        Set Region_Array[4] = random rect 4 <gen>


i then make another trigger like this

Code:
Untitled Trigger 001
    Events
        What ever event u want goes here
    Conditions
    Actions
        Set Random_Num = (Random integer number between 1 and 4)
        Unit - Create 1 Footman for Player 1 (Red) at (Center of Region_Array[Random_Num]) facing Default building facing (270.0) degrees

basically when every this trigger is ran it will pick a number between in and 4 and that variable(Random_Num) will stay that same exact number throughout this entire trigger. so then like i did u create the footmen in center of the Region_array[Random_Num]) where as that Random_Num has 4 preset values 1-4. when the trigger is ran like i stated above the random num is now a set number, 1-4.

so lets say that

Trigger runs. Random_Num now set its self to 2. now when the trigger runs the action to create a footmen it will create the footmen in the Region_array(2) that we set in the map initialization.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,497
> 338 regions.. oh joy!

Depending on your needs, there might be an alternative.

Like putting some Barrels instead of regions, and let the game do the rest from there.

Event:
- Map init
Conditions:
Actions:
Set RegionCount = 0
Pick every destructible in (Entire map) and do
- If Destructible type of (Picked destructible) equal to Barrel
- - Set RegionsCount = RegionCount + 1
- - Set myPoints[RegionsCount] = Position of (Picked destructible)
- - Destructible - Remove (Picked destructible)

Works pretty much automatically.
And there's nothing to edit just because you added or removed some.

Usage is still the same: myPoints[Random integer between 1 and RegionsCount] will be one of those points at random.
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top