• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

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

Status
Not open for further replies.
Level 4
Joined
Dec 12, 2012
Messages
96
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?
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
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
 
Level 4
Joined
Dec 12, 2012
Messages
96
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
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
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 :/
 
Level 4
Joined
Dec 12, 2012
Messages
96
  • 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
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
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)
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
Mine worked perfectly as well. :) Thanks to you both. Can't give you both repus, says i should spread reputation around first. :D 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.
Top