# [Solved]Spawn 3 out of 5 different units randomly by trigger

Status
Not open for further replies.

#### Maltheo2005

Level 4
I have 1 Major Unit (Z) and I have 5 minor units (a,b,c,d,e). Now I want to create a trigger that when 'Z' unit dies, 3 out of 5 minor units will spawn, but these units should be randomly selected and must not be the same.
Example: (1) Z dies > spawns a,b & c (2) Z dies > spawns d,b,e (3) Z dies > spawns e,a,c

Now how can I make this work with trigger?

#### Maker

Level 37
Init trigger:
Set max = 5 // integer
set u[1] = u1 // unit types
set u[2] = u2
set u[3] = u3
set u[4] = u4
set u[5] = u5

Spawn trigger:
Unit dies
Unit(type) == your unit(type)
set count = max
set ua[1] = u[1]
set ua[2] = u[2]
set ua[3] = u[3]
set ua[4] = u[4]
set ua[5] = u[5]
loop integer a from 1 to 3
-set int = random integer between 1 and count
-create ua[int]
-set ua[int] = ua[count]
-set count = count - 1

#### Maltheo2005

Level 4
Init trigger:
Set max = 5 // integer
set u[1] = u1 // unit types
set u[2] = u2
set u[3] = u3
set u[4] = u4
set u[5] = u5

I don't get it, should I create variable with brackets?

#### Maker

Level 37
Make the variable an array, that is what the brackets mean.

#### Maltheo2005

Level 4
Make the variable an array, that is what the brackets mean.

Okay, hang on a sec.

Like this?
• Spawn Init
• Events
• Conditions
• Actions
• Set Element_Max = 5
• Set Element[1] = Earth Element
• Set Element[2] = Fire Element
• Set Element[3] = Ice Element
• Set Element[4] = Nature Element
• Set Element[5] = Void Element

#### TwoVenomous

Level 12
Init trigger:
Set max = 5 // integer
set u[1] = u1 // unit types
set u[2] = u2
set u[3] = u3
set u[4] = u4
set u[5] = u5

Spawn trigger:
Unit dies
Unit(type) == your unit(type)
set count = max
set ua[1] = u[1]
set ua[2] = u[2]
set ua[3] = u[3]
set ua[4] = u[4]
set ua[5] = u[5]
loop integer a from 1 to 3
-set int = random integer between 1 and count
-create ua[int]
-set ua[int] = ua[count]
-set count = count - 1

didn't work :/

• Unit Initialization
• Events
• Map initialization
• Conditions
• Actions
• Set MajorUnitType = Footman
• Set MinorUnitType[1] = Noob
• Set MinorUnitType[2] = Peon
• Set MinorUnitType[3] = Dumb
• Set MinorUnitType[4] = Deaf
• Set MinorUnitType[5] = Chick
• Set NumberOfMinorUnit = 5
• Major Dies
• Events
• Unit - A unit Dies
• Conditions
• (Unit-type of (Triggering unit)) Equal to MajorUnitType
• Actions
• Set Count = NumberOfMinorUnit
• For each (Integer Variable) from 1 to 5, do (Actions)
• Loop - Actions
• Set ua[Variable] = MinorUnitType[Variable]
• For each (Integer Variable) from 1 to 3, do (Actions)
• Loop - Actions
• Set Roll = (Random integer number between 1 and Count)
• Set tempPoint = (Position of (Triggering unit))
• Unit - Create 1 ua[Roll] for (Owner of (Triggering unit)) at tempPoint facing Default building facing degrees
• Set MinorUnitType[Roll] = MinorUnitType[Count]
• Set Count = (Count - 1)
• Custom script: call RemoveLocation(udg_tempPoint)
the first time it creates Dumb,Deaf, and Noob, the second time it creates Peon, Chick and Chick, the third until the fifth it creates Chick,Chick and Chick :/

#### Maltheo2005

Level 4
• Spawn Init
• Events
• Conditions
• Actions
• Set Element_Max = 5
• Set Element[1] = Earth Element
• Set Element[2] = Fire Element
• Set Element[3] = Ice Element
• Set Element[4] = Nature Element
• Set Element[5] = Void Element

• Spawn random element
• Events
• Unit - A unit Dies
• Conditions
• (Unit-type of (Triggering unit)) Equal to Hellraiser
• Actions
• Set Element_Count = Element_Max
• Set Element2[1] = Element[1]
• Set Element2[2] = Element[2]
• Set Element2[3] = Element[3]
• Set Element2[4] = Element[4]
• Set Element2[5] = Element[5]
• For each (Integer A) from 1 to 3, do (Actions)
• Loop - Actions
• Set Element_Ran = (Random integer number between 1 and Element_Count)
• Unit - Create 1 Element2[Element_Ran] for Neutral Hostile at (Position of (Triggering unit)) facing Default building facing degrees
• Set Element2[Element_Ran] = Element2[Element_Count]
• Set Element_Count = (Element_Count - 1)
@TWOVENOMOUS

Awww.. wait i'll try that

#### Maker

Level 37
Set MinorUnitType[Roll] = MinorUnitType[Count]
^Use ua

#### TwoVenomous

Level 12
Set MinorUnitType[Roll] = MinorUnitType[Count]
^Use ua

Okay! work flawlessly! thanks a lot sir!

• Unit Initialization
• Events
• Map initialization
• Conditions
• Actions
• Set MajorUnitType = Footman
• Set MinorUnitType[1] = Noob
• Set MinorUnitType[2] = Peon
• Set MinorUnitType[3] = Dumb
• Set MinorUnitType[4] = Deaf
• Set MinorUnitType[5] = Chick
• Set NumberOfMinorUnit = 5
• Major Dies
• Events
• Unit - A unit Dies
• Conditions
• (Unit-type of (Triggering unit)) Equal to MajorUnitType
• Actions
• Set Count = NumberOfMinorUnit
• For each (Integer Variable) from 1 to 5, do (Actions)
• Loop - Actions
• Set ua[Variable] = MinorUnitType[Variable]
• For each (Integer Variable) from 1 to 3, do (Actions)
• Loop - Actions
• Set Roll = (Random integer number between 1 and Count)
• Set tempPoint = (Position of (Triggering unit))
• Unit - Create 1 ua[Roll] for (Owner of (Triggering unit)) at tempPoint facing Default building facing degrees
• Set ua[Roll] = ua[Count]
• Set Count = (Count - 1)
• Custom script: call RemoveLocation(udg_tempPoint)

#### Maltheo2005

Level 4
Mine worked perfectly as well. Thanks to you both. Can't give you both repus, says i should spread reputation around first. sry

#### TwoVenomous

Level 12
Mine worked perfectly as well. Thanks to you both. Can't give you both repus, says i should spread reputation around first. sry

you should remember to remove the point leaks.

• Set tempPoint = (Position of (Triggering unit))
• Unit - Create 1 ua[Roll] for (Owner of (Triggering unit)) at tempPoint facing Default building facing degrees
• Custom script: call RemoveLocation(udg_tempPoint)

Status
Not open for further replies.

Replies
8
Views
699
Replies
3
Views
592
Replies
1
Views
753
Replies
22
Views
1K
Replies
8
Views
670