1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Solved] Help with trigger

Discussion in 'Triggers & Scripts' started by Watcher, Oct 7, 2018.

  1. Watcher

    Watcher

    Joined:
    Aug 31, 2011
    Messages:
    87
    Resources:
    0
    Resources:
    0
    Hi guys,

    I have some questions regarding this trigger ("system"). The system that I'm trying to create is basically a spawn system, which would spawn x number of x unit types for every player every 60 secs.

    My question is: Can I somehow reduce the amount of lines, for example in "Spawn action" trigger, in "Human Player1" section, can I maybe merge 3 lines into a single one with the help of array that I have.
    Currently each line of the three spawns x number of x unit types for player 1. Can I make it that one line spawns x number of x unit types for player 1 and so on for every other player.

    This trigger is only made for 2 players instead for all, cause I'm asking for your advice and some tips regarding it.

    Initialized variables-1st trigger

    • Spawn init
      • Events
        • Time - Elapsed game time is 1.00 seconds
      • Conditions
      • Actions
        • Set int_var = 1
        • -------- Humans (Player1) --------
        • Set unit_type_var[1] = Footman
        • Set unit_type_var2[1] = Archer
        • Set unit_type_var3[1] = Knight
        • Set unit_count_var[1] = 3
        • Set unit_count_var2[1] = 2
        • Set unit_count_var3[1] = 1
        • -------- Orc (Player2) --------
        • Set unit_type_var[2] = Grunt
        • Set unit_type_var2[2] = Forest Troll
        • Set unit_type_var3[2] = Orc Warchief
        • Set unit_count_var[2] = 3
        • Set unit_count_var2[2] = 2
        • Set unit_count_var3[2] = 1




    Action trigger-2st trigger

    • Spawn action
      • Events
        • Time - Every 60.00 seconds of game time
      • Conditions
      • Actions
        • For each (Integer A) from 1 to int_var, do (Actions)
          • Loop - Actions
            • -------- Human (Player1) --------
            • Unit - Create unit_count_var[1] unit_type_var[1] for Player 1 (Red) at (Center of Human <gen>) facing Default building facing degrees
            • Unit - Create unit_count_var2[1] unit_type_var2[1] for Player 1 (Red) at (Center of Human <gen>) facing Default building facing degrees
            • Unit - Create unit_count_var3[1] unit_type_var3[1] for Player 1 (Red) at (Center of Human <gen>) facing Default building facing degrees
            • -------- Orc (Player2) --------
            • Unit - Create unit_count_var[2] unit_type_var[2] for Player 2 (Blue) at (Center of Human <gen>) facing Default building facing degrees
            • Unit - Create unit_count_var2[2] unit_type_var2[2] for Player 2 (Blue) at (Center of Human <gen>) facing Default building facing degrees
            • Unit - Create unit_count_var3[3] unit_type_var3[3] for Player 2 (Blue) at (Center of Human <gen>) facing Default building facing degrees




    Thank you in advance!
     
  2. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,532
    Resources:
    23
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    5
    JASS:
    3
    Resources:
    23
    The current loop is not really used, but if int_var is set to "2" in your setup trigger, then the loop could make sense.

    The loop would go from 1 to int_var (so looping with 1 and then with 2) .. so you could:

    • Unit - Create unit_count_var[Integer A] unit_type_var[Integer A] for Player[Integer A] at (Center of Human <gen>) facing Default building facing degrees
    • Unit - Create unit_count_var2[Integer A] unit_type_var[Integer A] for Player[Integer A] at (Center of Human <gen>) facing Default building facing degrees
    • Unit - Create unit_count_var3[Integer A] unit_type_var[Integer A] for Player[Integer A] at (Center of Human <gen>) facing Default building facing degrees


    .. it is adviced though, to create an extra integer vairbale, and use loop with it, instead of using the default IntegerA (to not potentially come in conflict with other triggers that are using IntegerA, as well)

    .. and probably you do want also to have seperate spawn locations, so not all spawn at the human spawn. So for each player there could be an extra location created at the setup, that could be used likewise in the loop:

    • Set Spawn[1] = (Center of Human <gen>)
    • ...
    • ...
    • Set Spawn[2] = (Center of Orc <gen>)


    in loop:
    • Unit - Create unit_count_var[Integer A] unit_type_var[Integer A] for Player[Integer A] at Spawn[Integer A] facing Default building facing degrees
     
  3. Watcher

    Watcher

    Joined:
    Aug 31, 2011
    Messages:
    87
    Resources:
    0
    Resources:
    0
    Yeah about seperate spawn locations, I already have them, I just forgot to put the different one.
    Btw do I need to set regions into variables and than destroy them or?
     
  4. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,532
    Resources:
    23
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    5
    JASS:
    3
    Resources:
    23
    If you create them dynamically, like maybe Picking all units in Region(0, 0, 100, 100), then yes, but ones created via the editor you may just use at any time, so you can let them.
     
  5. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Sorry I never replied to the other thread. You've mostly understood what I meant, but you should also have some location variables for the spawn.
    • Set PlayerSpawn[1] = Center of PS1 <gen>
    • Set PlayerSpawn[2] = Center of PS2 <gen>
    • Set PlayerSpawn[3] = Center of PS3 <gen>
    • -------- and so on for all players, if they each have unique spawn locations --------
    • -------- or this can be moved into the player group picks below if there's only one spawn location per force --------
    • Player Group - Add Player 1 (Red) to HUMAN_FORCE
    • Player Group - Add Player 2 (Blue) to ORC_FORCE
    • -------- and so on for each player, putting them into the correct force variable --------
    • -------- there are ways to automate this too, and make it so that defeated players or players who've left won't spawn units for their team, if you want --------
    • Player Group - Pick every player in HUMAN_FORCE and do (Actions)
      • Loop - Actions
        • Set PNum = Player Number of (Picked Player)
        • Set Spawns1[PNum] = Footman
        • Set SpawnCount1[PNum] = 3
        • -------- --------
        • Set Spawns2[PNum] = Archer
        • Set SpawnCount2[PNum] = 2
        • -------- --------
        • Set Spawns3[PNum] = Knight
        • Set SpawnCount3[PNum] = 1
    • Player Group - Pick every player in ORC_FORCE and do (Actions)
      • Loop - Actions
        • Set PNum = Player Number of (Picked Player)
        • Set Spawns1[PNum] = Grunt
        • Set SpawnCount1[PNum] = 3
        • -------- --------
        • Set Spawns2[PNum] = Forest Troll
        • Set SpawnCount2[PNum] = 2
        • -------- --------
        • Set Spawns3[PNum] = Orc Warchief
        • Set SpawnCount3[PNum] = 1

    • Events
      • Time - Ever 60.00 seconds of game-time
    • Conditions
    • Actions
      • Player Group - Pick every player in HUMAN_FORCE and do (Actions)
        • Loop - Actions
          • Set PNum = Player Number of (Picked Player)
          • Unit - Create SpawnCount1[PNum] Spawns1[Pnum] for (Picked Player) at PlayerSpawn[Pnum]
          • Unit - Create SpawnCount2[PNum] Spawns2[Pnum] for (Picked Player) at PlayerSpawn[Pnum]
          • Unit - Create SpawnCount3[PNum] Spawns3[Pnum] for (Picked Player) at PlayerSpawn[Pnum]
      • Player Group - Pick every player in ORC_FORCE and do (Actions)
        • Loop - Actions
          • Set PNum = Player Number of (Picked Player)
          • Unit - Create SpawnCount1[PNum] Spawns1[Pnum] for (Picked Player) at PlayerSpawn[Pnum]
          • Unit - Create SpawnCount2[PNum] Spawns2[Pnum] for (Picked Player) at PlayerSpawn[Pnum]
          • Unit - Create SpawnCount3[PNum] Spawns3[Pnum] for (Picked Player) at PlayerSpawn[Pnum]


    Now this setup has some limitations. Are there only ever 3 types of units that can be spawned at a time and upgrades just replace some of those units with different ones, or are there also upgrades that simply add units to the spawn? If the former then this will work perfectly. If the latter then you will either have to make a few other unit-type and integer arrays to hold the maximum possible different units to be spawned... or use a 2-D array. Replacing the unit types with other unit types will also require searching the different arrays and either replacing the stored unit-type or changing the stored number. This is actually relatively easy but will get weirder if you go with the 2-D array.
     
  6. Watcher

    Watcher

    Joined:
    Aug 31, 2011
    Messages:
    87
    Resources:
    0
    Resources:
    0
    Thank you for the tips and hints IcemanBo, they where very welcome.

    I must say I'm impressed Pyrogasm, thank you very much, really didn't expect that you would post the whole trigger. That is awesome man, and ty for some tips and tricks! This triggers are practically amazing.

    And yes, there wil be more than 3 type of units that can be spawned and some events/upgrades will add different unit types to the existing spawn or replace the current units. Also, each player will have multiple spawn locations.

    I can add everything else I will need into this trigger by myself, since this is just amazing.

    All in all, big thanks to you guys. This thread is officially solved!