# Create a random unit of :.....?

Status
Not open for further replies.

#### daverave1212

Level 11
How can i make a trigger that creates for example a random unit from Footman,Rifleman and Knight?
Also,how to make a trigger that moves one random of some units(i chose the units)???

#### Bannar

Level 26
I dont get what is your 2nd question about, explain it futher if you can.
One of options to solve 1st one:
you can set level for units:footman, rifleman and knight to specific number, lets set to 15.
Make sure no other units in game have the same level (here 15)
and use action that creates random unit with level 15.

#### Maker

Level 37
• Actions
• Set i1 = (Random integer number between 1 and 3)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• i1 Equal to 1
• Then - Actions
• Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• i1 Equal to 2
• Then - Actions
• Unit - Create 1 Knight for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
• Else - Actions
• Unit - Create 1 Rifleman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
For the second issue, add the units into a unit group and the pic random units from the group.

Remember to clear leaks: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/

#### Bannar

Level 26
Ok i checked idea about creating by level. Its not efficent, unit has to be creep - race, its not worth to set in every case unit's race to creep.
Better use creating units depending on values of integers where each integer marks given unit.
Maker did great egzample above.

#### defskull

Level 33
To improve Maker's IFs efficiency, do it like this:

• Setup
• Events
• Map initialization
• Conditions
• Actions
• Set TypesOfUnit[1] = Footman
• Set TypesOfUnit[2] = Knight
• Set TypesOfUnit[3] = Rifleman
• Create
• Events
• Conditions
• Actions
• Set RandomInteger = (Random integer number between 1 and 3)
• Unit - Create 1 TypesOfUnit[RandomInteger] for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
In the setup trigger, you can set as many units as you want without having to do many IFs in the 2nd trigger

#### daverave1212

Level 11
Ok thanks.Now what if at the end of the trigger i want to reset the variables?Is that possible(lol i know it is but how?)

• Actions
• Set i1 = (Random integer number between 1 and 3)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• i1 Equal to 1
• Then - Actions
• Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• i1 Equal to 2
• Then - Actions
• Unit - Create 1 Knight for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
• Else - Actions
• Unit - Create 1 Rifleman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
For the second issue, add the units into a unit group and the pic random units from the group.

Remember to clear leaks: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/

Ok thanks a lot ^^!!Now what if at the end of the trigger i want to reset that variable(clear it) ???How can i do that>??

#### Maker

Level 37
You don't have to clear it

And to improve defskull's trigger's efficiency,
• Unit - Create 1 TypesOfUnit[(Random integer number between 1 and 3)] for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees

Status
Not open for further replies.

Replies
4
Views
369
Replies
6
Views
816
Replies
8
Views
652
[General] Random Unit
Replies
3
Views
582
Replies
8
Views
695