SC2Mapster Forums

Development > Triggers

how to spawn random units

  • 16 posts
    #1 Nov 05, 2012 at 04:23 UTC - 0 likes

    i couldnt understand the other posts about arrays and smth cause im a noob but how to make a trigger that spawns a random unit of a type (Light/Armored) at a region

    #2 Nov 05, 2012 at 08:17 UTC - 0 likes

    Blank

    Last edited Nov 05, 2012 by TwoDie

    http://img27.imageshack.us/img27/8882/abasizedr.jpg

    #3 Nov 05, 2012 at 08:27 UTC - 0 likes

    ................................................................................. step by step maybe? :X

    #4 Nov 05, 2012 at 09:29 UTC - 0 likes

    @xDarkZeratulX: Go

    To celebrate my return, I made you an example.....

    Name Size MD5
    randomUnitTypeLib.SC2Map 11.6 KiB dde5634fc3df...

    Skype
    KageNinpo = SN

    My Libraries
    DialogLeaderboard & TeamSort

    My Projects
    SPACEWAR Tribute
    Infinite TD

    #5 Nov 05, 2012 at 11:49 UTC - 0 likes

    Welcome Back ANd Thank You Very Much

    #6 Nov 06, 2012 at 04:53 UTC - 0 likes

    im stupid yeah but how to put those triggers into my predone map >.<

    #7 Nov 06, 2012 at 04:54 UTC - 0 likes

    Bump

    Last edited Nov 06, 2012 by xDarkZeratulX
    #8 Nov 06, 2012 at 08:30 UTC - 0 likes

    @xDarkZeratulX: Go First: no need to bump every minute. A Forum has some kind of response time ;-)

    First step: Create a new Variable Array of type Unit and name it RandomUnit. The size names the amount of units you want to be able to spawn (I choose 21). 2: Make a new trigger:

    E:
    Map init
    C:
    (empty)
    A:
    Set Variable RandomUnit[0] = Space Marine
    Set Variable RandomUnit[1] = Zergling
    Set Variable RandomUnit[2] = Zealot
    Set Variable RandomUnit[3] = Sentry
    Set Variable RandomUnit[4] = Carrier
    ...
    Set Variable RandomUnit[20] = Queen
    

    and so on...

    now make a second trigger

    E:
    Every 10seconds
    Local Variable:
    int i =0;
    C:
    A:
    i = random int between 0 and 20
    Spawn 1 unit (RandomUnit(i)) for player 1 in region (center of Map) facing somewhere.
    

    finished.

    #9 Nov 06, 2012 at 08:53 UTC - 1 like

    i cant get the last part done which action am i supposed to click create unit with default facing? theres no option behind unit to say (randomUnit(i))

    #10 Nov 06, 2012 at 09:00 UTC - 0 likes

    @xDarkZeratulX: Go maybe this helps http:www.sc2mapster.com/wiki/galaxy/triggers/create-units-with-point-facing/ I didnt write the exact name, dont have Galaxy on this PC so it was a little bit of pseudocode, but this is the action I ment.

    #11 Nov 06, 2012 at 09:45 UTC - 0 likes

    errrr im stupid soooo really idk how to do it :X

    #12 Nov 06, 2012 at 16:31 UTC - 0 likes

    @xDarkZeratulX: Go

    I was going to refrain from posing because I figured you'd get help from someone else, but let me see if I can help.

    Firstly Mojo was partially right, you need to create a unit array and set each unit that could conceivably be spawned to said array.

    Then what you do is create a spawn trigger, set it to run whenever a round is supposed to start (if no rounds, a periodic trigger would work as well).

    Set a local variable and call it randomnumber (any name will do).

    Then set randomnumber to a random number between 0 and the maximum number of units in your array (you could automate this process or do it manually, do it manually to begin with however).

    Pick each integer.

    then do an if then else (switch would work, but for a beginner this will make more sense).

    If randomnumber is =  picked integer
    then Create X units UnitArray[Picked Integer] at SpawnPoint.
    Skip Remaining Actions/Break
    else wait .1 seconds.
    

    I haven't tested this (obviously) but I have done similar things before; it should work for your purposes.

    EDIT: actually, you could do this as well to be even more efficient:

    Do the whole randomnumber bit, then just do Create X units UnitArray[randomnumber] at SpawnPoint.

    This should be much more efficient.

    Last edited Nov 06, 2012 by Yaksmanofage
    #13 Nov 07, 2012 at 00:45 UTC - 0 likes

    i cant find UnitArray in the menu

    Last edited Nov 07, 2012 by xDarkZeratulX
    • 1111111.jpg
      am i doing this right???? ...
    #14 Nov 07, 2012 at 04:16 UTC - 0 likes

    @xDarkZeratulX: Go

    Create a global variable. Select it's type as unit type, check the array box and set it to the maximum number of units you'll think you'll need to spawn.

    and yes, the random number part is correct.

    Last edited Nov 07, 2012 by Yaksmanofage
    #15 Nov 07, 2012 at 04:45 UTC - 0 likes

    @xDarkZeratulX: Go

    Why arnt you using the sample I made you? If you cant figure out how it works pm me.

    You just have to have both maps open at the same time and copy and paste all the trigger stuff in.

    For the function I made you

    you just do

    create 1 RandomUNit for player 1 facing default

    Last edited Nov 07, 2012 by SouLCarveRR
    #16 Nov 11, 2012 at 16:01 UTC - 0 likes

    I made a quite easy random system in my map.

    Local variable: Unit type = 0<integer> actions: Variable - Set Unit type = (Random interger between 0 and 10)

    General if then do else do

    if: Unit type == 0 then: Unit - create zergling for player (triggering player) else

    if: Unit type == 1 then: Unit - create zealotfor player (triggering player)

    etc.

    Last edited Nov 11, 2012 by Skaffe123
  • 16 posts

You must login to post a comment. Don't have an account? Register to get one!