Complex Trigger Problem

Discussion in 'Starcraft 2 (SC2) Editor Help' started by Kyuft, May 27, 2013.

  1. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    I want to create a system that selects a group of units, when just one of the units in the group is selected. I can just make it so when one unit in the group is selected, the whole unit group is selected. Simple, right? No. There will be an infinite amount of these groups, and so I cannot make unit group variables for all of them. Instead, I set up a very complex system which works... to a degree.
    My System (simplified):
    When a unit enters the map, it is assigned to a temporary (global variable) unit group and the units custom value (Index: 0) is set to a global integer variable, GroupDataValue. When the unit group becomes full (8 units), it converts the GroupDataValue (which starts at 1, by the way) to a string which is saved in a global string variable, GroupData. All of the units in the unit group are stored in the global data table (Index: Group[GroupData]) and the value of GroupDataValue is increased by 1, as to prepare for the next group. When a unit is selected, it's custom value (Index:0) is converted to a string, which is saved in a local variable, CustomData. Then, all units in the global data table (Index: Group[CustomData]) are selected. This, after many hours of work is working surprisingly well, however there is one major problem, considering I do not want to make it possible to only select one unit.

    If I click on a unit, the whole group is selected, GREAT! Problem: Once the whole group is selected, if I click on ONE unit that is already selected, then it will be the only one selected. I assume this is because instead of deselecting all of the units in the group and selecting that one, it just deselects the others. Therefore, the trigger that detects the selection of a unit is not triggered.

    Attempts:
    1. I tried setting it so that when a unit is clicked (technically it also selects it) it will select the whole group, but for some reason this did not work.
    2. I tried making a trigger that realizes when units are deselected. I was going to make a condition that checked if the deselected unit's custom value was equal to the currently selected unit's value (meaning that they are in the same group), and making it select the whole group of the currently selected unit, but there is no option that returns the unit that is currently selected.

    Please help! I have spent 5 hours trying to perfect this, and I do not want to have to trash it all.
    Thanks!

    -Kyuft:cool:
     
  2. Phubar

    Phubar Well-Known Member

    Ratings:
    +30 / 0 / -0
    Is there a way to set the all units in that group unselectable?
    Of course you have to create an action in the "Group selection trigger" that makes all your units selectable again OR only the units of the previous group (store the units in a temp group, same for all actuals groups, when you select them and use it to mae them selectable again when you select another unit/group)
     
  3. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    Only problem with that is, if I highlight and select two groups, and I want to only select one, the best way to do that would be to click on one of the units. However, if I made them unselectable, then I could not select only one of the groups, except by clicking on the ground, and then on the unit, which would get really annoying, considering my map requires a lot of micro skills.

    -Kyuft:cool:
     
  4. Phubar

    Phubar Well-Known Member

    Ratings:
    +30 / 0 / -0
    Didnt think about multiple group selection :D
     
  5. Phubar

    Phubar Well-Known Member

    Ratings:
    +30 / 0 / -0
    For your 2nd attempt you want a functions that gives to you the unit selected OR that checks if the unit is in the selected ones?

    Your problem is not simple and my undestandings not too big but if you change all your triggers activations fron "unit selected" to "unit clicked" you can make units temp unselectables and make checks on what units are selected when you click on a unit, make units selectable again an then continue. All the stuff about setting selectable/unselectable wont be needed if an unseletable unit can be still selected by trigger actions.
     
  6. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    The "Unit Is Clicked" event seems to do nothing, but if an untargetable unit can b targeted by triggers, then I might take a stab at your solution, although it is messy. But heh, my triggers are already messy :p

    -Kyuft:cool:
     
  7. Siretu

    Siretu Starcraft 2 Editor Moderator Staff Member

    Ratings:
    +295 / 0 / -0
    How is the grouping supposed to work? Are units placed in groups depending on when they enter the map? So the first 8 units are in the first group, and the next 8 units are in the next group?

    Also, I know there's probably a lot of triggers, but you should probably post them anyway.
     
  8. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    Yes, they are placed in groups depending on when they enter the map because they are created in groups, rather that one at a time.
    Triggers:

    Trigger that adds them to groups (temporary):
    Trigger:
    • Save Squad
      • Events
        • Trigger - Generic event named "Unit Added to Unit Group"
      • Local Variables
      • Conditions
      • Actions
        • Player Group - Pick each player in (Active Players) and do (Actions)
          • Actions
            • General - If (Conditions) then do (Actions) else do (Actions)
              • If
                • (Number of Living units in MarineSquad[(Picked player)]) == 8
              • Then
                • Variable - Set SquadData = (String(SquadDataValue[(Picked player)]))
                • Data Table - Save (Units in MarineSquad[(Picked player)] owned by player (Picked player), with at most 8) as "MarineSquad[" + gv_squadData + "]" in the Global data table
                • Variable - Modify SquadDataValue[(Picked player)]: + 1
                • Variable - Set MarineSquad[(Picked player)] = (Empty unit group)
              • Else
    Trigger that saves their groups outside of a temporary variable:
    Trigger:
    • Save Squad
      • Events
        • Trigger - Generic event named "Unit Added to Unit Group"
      • Local Variables
      • Conditions
      • Actions
        • Player Group - Pick each player in (Active Players) and do (Actions)
          • Actions
            • General - If (Conditions) then do (Actions) else do (Actions)
              • If
                • (Number of Living units in MarineSquad[(Picked player)]) == 8
              • Then
                • Variable - Set SquadData = (String(SquadDataValue[(Picked player)]))
                • Data Table - Save (Units in MarineSquad[(Picked player)] owned by player (Picked player), with at most 8) as "MarineSquad[" + gv_squadData + "]" in the Global data table
                • Variable - Modify SquadDataValue[(Picked player)]: + 1
                • Variable - Set MarineSquad[(Picked player)] = (Empty unit group)
              • Else
    Trigger that selects the whole group when unit is selected:
    Trigger:
    • Select Squad
      • Events
        • Unit Selection - Any Unit is Selected by player Any Player
      • Local Variables
        • DataValue = "" <String>
      • Conditions
        • (Owner of (Triggering unit)) == (Triggering player)
      • Actions
        • General - If (Conditions) then do (Actions) else do (Actions)
          • If
            • ((Triggering unit) has Marine) == True
          • Then
            • Variable - Set DataValue = (String((Custom value 0 of (Triggering unit))) with Any Precision decimal places)
            • Unit Selection - Select ("MarineSquad[" + lv_dataValue + "]" from the Global data table) for player (Triggering player)
          • Else

    -Kyuft:cool:
     
  9. Phubar

    Phubar Well-Known Member

    Ratings:
    +30 / 0 / -0
    All units are flagged unclickable, you have to change it in data editor. I had same problem in one of my maps :)
     
  10. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    For some odd reason, making a trigger that selects a unit when it is clicked, even after editing the flags, makes no difference.

    -Kyuft:cool:
     
  11. Phubar

    Phubar Well-Known Member

    Ratings:
    +30 / 0 / -0
    The unit is set to selectable or not?
     
  12. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    It is selectable because if they were unselectable and I changed the trigger event to "Unit Is Clicked", then you would not be able to highlight by dragging an area over units and selecting multiple groups.

    -Kyuft:cool:
     
  13. Phubar

    Phubar Well-Known Member

    Ratings:
    +30 / 0 / -0
    Yes i was just thinking that "click unit" makes the drag box useless.. Sry i have to think a bit more... and i mean days :D
     
  14. Phubar

    Phubar Well-Known Member

    Ratings:
    +30 / 0 / -0
    Maybe this will work (i didnt understand your method of selecting units so i will explain in general way)

    When a unit is deselected (this happens when you have a group selected and click on one of their units) peek all units in "units that are selected" an then select the group that contain that unit.

    I cant find a function that gives back the group of a given unit... so maybe you have to do a custom function.
     
  15. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    Is there a parameter for "Units That Are Selected"?

    -Kyuft:cool:
     
  16. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    I tried the following trigger, but it did not seem to work...

    Trigger:
    • SquadDebug
      • Events
        • Unit Selection - Any Unit is Deselected by player Any Player
      • Local Variables
      • Conditions
        • (Owner of (Triggering unit)) == (Triggering player)
      • Actions
        • General - Pick each integer from 1 to (Number of Living units in (Selected units for player (Triggering player))), and do (Actions)
          • Actions
            • General - If (Conditions) then do (Actions) else do (Actions)
              • If
                • (Owner of (Triggering unit)) == (Owner of (Picked unit))
                • (Unit type of (Triggering unit)) == (Unit type of (Unit (Picked integer) from (Selected units for player (Triggering player))))
              • Then
                • Unit Group - Pick each unit in (Selected units for player (Triggering player)) and do (Actions)
                  • Actions
                    • Unit Selection - Deselect (Picked unit) for player (Triggering player)
                    • Unit Selection - Select (Picked unit) for player (Triggering player)
              • Else


    -Kyuft:cool:
     
  17. Phubar

    Phubar Well-Known Member

    Ratings:
    +30 / 0 / -0
    Sry for language error, i meant pick not peek :D
    Btw... Solved! :)

    Code:
    TRIGGER Keep selection
        Events
            Unit selection - Any unit is Deselected by Any player
       
        Conditions
        Actions
            Unit group - Pick all units in (Units selected for player 1) and do (actions)
                Actions
                    Unit group - Add (Picked unit) to To reselect
            Unit selection - Deselect To reselect for player 1
            General - Wait 0.01 seconds
            Unit selection - Select To reselect for player 1
            Unit group - remove all units from To reselect
    
    you have to insert a wait time in oirder to make it work :)

    PS i transleted my italian trigger so some words may not be correct
    PPS Units selected for player 1 is a basic "group" function, you can find it under "unit selection", its called something like "Selected units" or "Unit selection".
     
  18. Phubar

    Phubar Well-Known Member

    Ratings:
    +30 / 0 / -0
    Just reselect the units currently selected after they were deselected. The other trigger (the one that selects the whole group when a unit is selected) will do all the work.
    IMPORTANT add a little wait time between deselection and reselection
     
  19. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    Isn't your trigger almost identical to the one I posted that didn't work? Besides the wait time...

    -Kyuft:cool:
     
  20. Kyuft

    Kyuft Member

    Ratings:
    +11 / 0 / -0
    You are right, this does work, however, I have found a new problem. I want this "squad system" to be completely foolproof, neat, clean, and instant. I have realized that in the time it takes for the trigger to process all of the Actions, and select the rest of the squad (when a unit is selected), you can still command that single unit. I want to somehow make it so that the instant the unit is selected, the rest of the squad is selected, as if they are one big unit. However, I do not want to make a single unit for them with a model of 8 marines, because that would not flow well, and it would be very uptight. I realize that my system, although it was very tedious to make, cannot perform how I would like it to. Does anybody have any clue how to make an instant, neat system like the one I have described?

    EDIT: If this can't be done, then the whole concept of my map (or at least, my favorite part) will be destroyed :(

    -Kyuft:cool:
     

Share This Page