problem with trigger need help pls

Discussion in 'Starcraft 2 (SC2) Editor Help' started by MissKerrigan, Mar 12, 2012.

  1. MissKerrigan

    MissKerrigan Active Member

    Hello,

    I want make a trigger the next:

    if you bring 4 hydralisk in a certain region, they must remove from map and 1 bigger hydralisk coming back for it
    Now if you bring 4 of this bigger hydralisk to this region, another hydralisk which is more bigger must coming now instead of the 4 smaller once

    Does anybody understand my situation?

    I wanna do the same with roach, but I need only an explaination of 1 trigger and I think I can fix all


    So to be clear: I have 3 hydralisk units which are smal/medium/big
    When bring 4 small hydras to region, hey must change into 1 medium hydralisk
    And when bring 4 medium hydralisk to this region, they must change into 1 big hydralisk

    Greetzz,

    MissKerrigan
  2. Dave312

    Dave312 Censored for your safe viewing

    This should do the trick:

    Trigger:
    • Hydralisk Small Upgrade
      • Events
        • Unit - Any Unit Enters HydraliskUpgradeArea
      • Local Variables
        • UpgradeUnits = (Small Hydralisk units in HydraliskUpgradeArea owned by player (Owner of (Triggering unit)) matching Excluded: Missile, Dead, Hidden, with at most 4) <Unit Group>
      • Conditions
        • (Unit type of (Triggering unit)) == Small Hydralisk
        • (Number of Living units in UpgradeUnits) == 4
      • Actions
        • Unit Group - Pick each unit in UpgradeUnits and do (Actions)
          • Actions
            • Unit - Remove (Picked unit) from the game
        • Unit - Create 1 Medium Hydralisk for player (Owner of (Triggering unit)) at SpawnPoint using default facing (No Options)


    FYI this will only upgrade the small hydralisks into the medium one. Create another copy of this trigger to go from medium to large. HydraliskUpgradeArea is the region which the hydralisks must enter. SpawnPoint is the location the where the new upgraded hydralisk is created. If the medium to large hydralisk upgrade occurs in the same region, then place this point outside this region. Otherwise it doesn't matter.
  3. MissKerrigan

    MissKerrigan Active Member

  4. Siretu

    Siretu Starcraft 2 Editor Moderator Staff Member

    Excuse me if I'm being slow today, but why is this? If you create it in the same region, it wont trigger the second upgrade immediately if you don't already have 3 medium hydralisks in the region. I don't see a problem.

    What part is hard? If you tell us what you're having trouble understanding, I'm sure someone will be able to explain it better.

    Here's what Dave's code does:
    When a unit enters the upgrade region, save all Small hydralisks in the upgrade region in the "UpgradeUnits" variable.

    If the unit that enters the region is a small hydralisk and the amount of small hydralisks in the region is 4, do the following:

    Remove all small hydralisks and create a medium hydralisk.
  5. Dave312

    Dave312 Censored for your safe viewing

    Creating a unit doesn't trigger the Enters Regions event. So if they were supposed to upgrade in the same region, and you already had 3 medium hydralisks in the region, then the upgrade to the big hydralisk wouldn't be triggered if 4 small hydralisks entered the region and turned into a medium hydralisk. Instead either another medium hydralisk would have to enter or one of the existing ones would have to leave and enter again. It's not really a big issue, but thought I'd mention it anyway.
  6. Phubar

    Phubar Active Member

    To fix the "probem" of upgrading units in chain (small to medium and medium to large) maybe you can create a exact copy of each trigger changing the evento from "Unit enter in region" in "unit is created" with condition "tipe of unit created=smallhydralisk" and "position of crated unit=point in HydraliskUpgradeArea".

    But i'm not an expert so wait for an answer from a more expert poster :)

    I have the italian version of the editor, that's why i have not posted an activator like Dave. I tried to translate by myself the commands, the meaning is the same buy they cant be like in you editor.
  7. Jokker

    Jokker Member

    This can be done more easily imho. Ill try to make the trigger for you when I get home.

    The basic idea being that you use a variable for the count of hydras more easily.
    I'll have to try it but I have a very easy trigger in mind.
  8. Siretu

    Siretu Starcraft 2 Editor Moderator Staff Member

    After some simple testing, I would like to disagree on this.

    For me, creating a unit in a region triggers the "A unit enters region" event. I just made a simple trigger that printed out "bar" when a unit enters the entire map and then I created a unit on the map through triggers. It printed "bar".

    I also tried it with a smaller manually made region and it gave the same result.

    Misskerrigan: If my testings are correct, you should be able to use the trigger Dave wrote without any problems. You don't have to place the point outside the region.
  9. Jokker

    Jokker Member

    Yeap, Daves version works. I made basically something like that, but only a little different.

    This needs two global variables:
    RoachGroup = (Empty unit group) <Unit Group>
    GreateAfterRoach = 0.0 <Real>

    Unit enters region trigger:
    Trigger:
    • Small Enter Region
      • Events
        • Unit - Any Unit Enters Region 001
      • Local Variables
      • Conditions
        • (Unit type of (Triggering unit)) == Roach
      • Actions
        • Unit Group - Add (Triggering unit) to RoachGroup
        • Variable - Set GreateAfterRoach = (GreateAfterRoach + 1.0)
        • General - If (Conditions) then do (Actions) else do (Actions)
          • If
            • GreateAfterRoach == 4.0
          • Then
            • Unit - Remove (Unit 1 from RoachGroup) from the game
            • Unit - Remove (Unit 2 from RoachGroup) from the game
            • Unit - Remove (Unit 3 from RoachGroup) from the game
            • Unit - Remove (Unit 4 from RoachGroup) from the game
            • Variable - Set GreateAfterRoach = 0
            • Unit - Create 1 Baneling for player 1 at (Center of Region 001) facing 270.0 degrees (No Options)
          • Else


    Unit leaves region ( if under 3 units, the leaving should change the unit group to less units)
    Trigger:
    • Small Leave Region
      • Events
        • Unit - Any Unit Leaves Region 001
      • Local Variables
      • Conditions
        • (Unit type of (Triggering unit)) == Roach
      • Actions
        • Unit Group - Remove (Triggering unit) from RoachGroup
        • Variable - Set GreateAfterRoach = (GreateAfterRoach - 1.0)


    This is an example. It takes 4 roaches and creates a baneling. So change the unit types XD

    And don't hate me. I tried to write this as beginner-friendly as possible
  10. Siretu

    Siretu Starcraft 2 Editor Moderator Staff Member

    I just wanted to comment on your code so you can learn from it.

    First of all, you don't have to use the "GreateAfterRoach" variable. Basically, that variable represents the amount of units in "RoachGroup". There is a function called "Number Of Units In Unit Group" which you can use instead of keeping track of it in "GreateAfterRoach".

    Secondly, instead of using "Unit - Remove (Unit 1 from RoachGroup) from the game", you can just use the action "Pick Each Unit In Unit Group" and remove the picked unit. This doesn't really matter but some would argue that the latter looks cleaner. Not to mention, if you would like triggers for combining 10, 15 or maybe 100 units, your way would become very long. Although your way is possibly clearer and easier to understand for beginners, which is good.

    Finally, the "RoachGroup" variable isn't really necessary. You're using it to keep track of all the units inside the region but there's a function called "Units In Region Matching Condition" that can give you that information at any time. If you use it instead, you no longer need the second trigger.

    Now, does it really matter? I'd say some of the fixes makes the code slightly more efficient but you're not going to notice it. The big thing here is to get a better understanding of the amount of functions that already exist to help you so you don't reinvent the wheel.

    Thanks for taking your time to put this together. Hopefully, both you and some other people can learn from it :)
  11. Dave312

    Dave312 Censored for your safe viewing

    Hmmm... I don't where I got the impression that that was the case. Oh well. Thanks for pointing that out Siretu :)
  12. MissKerrigan

    MissKerrigan Active Member

    Alright siretu, what I not understanding about this is the next:

    1. I don't know why I need a variable here, I think I just can make the trigger like this:


    event: unit enters region 'upgrade for unit'
    condition: unit type of unit = small hydralisk
    condition: number of living units are 4 (but what if diffirent units are in this location?)
    action: remove triggering unit from the game
    action: create 1 medium hydralisk 'spawn place (I have 2 zerg beacons, the left beacon is the meet location and the right beacon is the spawn unit beacon)

    for me this can without variable, am I right?


    2. the think I not understand is how to create the 'number of living unit' condition. Can't find it anywhere


    MissKerrigan
  13. Dave312

    Dave312 Censored for your safe viewing

    1) You could do without the local variable, but you would need to keep referencing that Unit Group. Variables make your life easier!

    Trigger:
    • Hydralisk Small Upgrade
      • Events
        • Unit - Any Unit Enters HydraliskUpgradeArea
      • Local Variables
      • Conditions
        • (Unit type of (Triggering unit)) == Small Hydralisk
        • (Number of Living units in (Small Hydralisk units in HydraliskUpgradeArea owned by player (Owner of (Triggering unit)) matching Excluded: Missile, Dead, Hidden, with at most 4)) == 4
      • Actions
        • Unit Group - Pick each unit in (Small Hydralisk units in HydraliskUpgradeArea owned by player (Owner of (Triggering unit)) matching Excluded: Missile, Dead, Hidden, with at most 4) and do (Actions)
          • Actions
            • Unit - Remove (Picked unit) from the game
        • Unit - Create 1 Medium Hydralisk for player (Owner of (Triggering unit)) at SpawnPoint using default facing (No Options)


    To create (Small Hydralisk units in HydraliskUpgradeArea owned by player (Owner of (Triggering unit)) matching Excluded: Missile, Dead, Hidden, with at most 4), it is a Units In Region Matching Condition function.

    I should also point out that Remove triggering unit from the game would not have worked because then you would have only lost 1 of the small hydralisks.
    When counting units, they need to be in a Unit Group and you can specify the type of units to be added when creating a unit group.

    2) It is the Number of Units In Unit Group function

Share This Page