• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Help with trigger

Status
Not open for further replies.
Level 4
Joined
Aug 31, 2011
Messages
88
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.


  • 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




  • 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!
 
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
 
Level 4
Joined
Aug 31, 2011
Messages
88
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?
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
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.
 
Level 4
Joined
Aug 31, 2011
Messages
88
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!
 
Status
Not open for further replies.
Top