Random Region + Point

AlExAlExAlEx

Member
Reaction score
7
Hey guys,

I have 10 regions and 10 points(the points are in the middle of the regions). I want to kill any unit in a random region and add a explosion at the point.

Now.. I know that to generate a random number from 1 to 10 I make a variable and set it to a random integer between 1 and 10;
I know how to create explosions point with Environment - Create a x explosion at Point;

but I can not for the life of me figure out how to kill any unit in a random region and add an explosion to the corresponding point. (if region 5 is randomly chosen, explosion must be at point 5)

Any help, please?
 

Dave312

Censored for your safe viewing
Reaction score
269
You want to create 2 global variables, one to store the points and another to store the regions (set the variable type of one variable to Point and the other to Region). Because you want these variables to store multiple values (i.e 10 points and 10 regions) you need to check the Array field and set the Size to 10.

Now you need to create a trigger which runs when the maps starts which will store all your regions and points into your variables:
Trigger:
  • Map Initialization
    • Events
      • Game - Map initialization
    • Local Variables
    • Conditions
    • Actions
      • ------- Store Regions into variable
      • Variable - Set My_Region[0] = Region 001
      • Variable - Set My_Region[1] = Region 002
      • Variable - Set My_Region[2] = Region 003
      • Variable - Set My_Region[3] = Region 004
      • Variable - Set My_Region[4] = Region 005
      • Variable - Set My_Region[5] = Region 006
      • ...etc
      • Variable - Set My_Region[9] = Region 009
      • ------- Store Points into variable
      • Variable - Set My_Points[0] = Point 001
      • Variable - Set My_Points[1] = Point 002
      • Variable - Set My_Points[2] = Point 003
      • Variable - Set My_Points[3] = Point 004
      • Variable - Set My_Points[4] = Point 005
      • ...etc
      • Variable - Set My_Points[9] = Point 009


Now when you create your random number and store it to your local variable, you can easily reference the correct region/point by calling the appropriate global variable and putting in your local variable as the index. It is important to note that the first index of an array is 0, so you will want get a random number between 0 and 9 not 1 and 10.

To kill all units in a region you can use the Pick Each Unit in Unit Group action and set the Unit Group parameter to Units in Region Matching Condition and input your selected region. Then use the Kill Unit action to kill the picked unit.

Your trigger should end up something like this:
Trigger:
  • Actions
    • Variable - Set i = (Random integer between 0 and 9)
    • Environment - Create a Large Terran explosion at My_Points
    • Unit Group - Pick each unit in (Any units in My_Region owned by player Any Player matching Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)
      • Actions
        • Unit - Kill (Picked unit)


It is also worth mentioning that if you want your explosion to be created at the exact center of your regions, you could use the function Center of Region to get the center of your region rather than having to get create/store points.
 

AlExAlExAlEx

Member
Reaction score
7
First of all, thank you for the very in depth answer. I am still trying to understand it fully.

But I'd like to quickly go over "It is also worth mentioning that if you want your explosion to be created at the exact center of your regions, you could use the function Center of Region to get the center of your region rather than having to get create/store points."

While looking at Create a X explosion I did not think to go over the functions - Thank you for this shortcut. I'll try to use just regions and post back with results.

Thanks again.

EDIT:
It worked like a charm, thank you for your time and through explanation.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top