• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Selected units by player

Status
Not open for further replies.
Level 22
Joined
Feb 3, 2009
Messages
3,292
In the bellow trigger (the event is added on map ini (any player writes -f as substring).

It works fine, but if a player uses it while he has no units selected then the whole game freezes or random strange bugs occur. I'm sure checking for if group is empty won't work due to some of the errors I saw till now...

How would I fix it?

  • Set Facing
    • Events
    • Conditions
    • Actions
      • Set TempInt = (Integer((Substring((Entered chat string), 3, 8))))
      • Unit Group - Pick every unit in (Units currently selected by (Triggering player)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Titan Palace <gen> contains (Picked unit)) Equal to False
                  • (Owner of (Picked unit)) Equal to (Triggering player)
            • Then - Actions
              • Custom script: call SetImmovableUnitFacing(GetEnumUnit(), udg_TempInt)
            • Else - Actions
      • Custom script: call DestroyGroup(bj_lastCreatedGroup)
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
  • Untitled Trigger 030
    • Events
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set i = (Number of units in (Units currently selected by (Triggering player)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • i Greater than 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is A structure) Equal to True
              • ((Triggering unit) is A Hero) Equal to True
            • Then - Actions
            • Else - Actions
        • Else - Actions
You don't need the extra AND for the conditions, also there is no bj_lastCreatedGroup involved here.
 
Level 22
Joined
Feb 3, 2009
Messages
3,292
This is how it looks like currently:

  • Set Facing
    • Events
    • Conditions
    • Actions
      • Set TempInt = (Integer((Substring((Entered chat string), 3, 8))))
      • Set TempGroup = (Units currently selected by (Triggering player))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in TempGroup) Greater than 0
        • Then - Actions
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Titan Palace <gen> contains (Picked unit)) Equal to True
                      • (Owner of (Picked unit)) Not equal to (Triggering player)
                • Then - Actions
                  • Unit Group - Remove (Picked unit) from TempGroup
                • Else - Actions
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • And - All (Conditions) are true
                    • Conditions
                      • (Titan Palace <gen> contains (Picked unit)) Equal to False
                      • (Owner of (Picked unit)) Equal to (Triggering player)
                • Then - Actions
                  • Custom script: call SetImmovableUnitFacing(GetEnumUnit(), udg_TempInt)
                • Else - Actions
        • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup)
 
Why are you using SetImmovableUnitFacing if you said the units should be able to move? Just use "SetUnitFacing" then.

First, you can greatly simplify your trigger:

  • Select
    • Events
    • Conditions
    • Actions
      • Set TempInt = (Integer((Substring((Entered chat string), 3, 8))))
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units currently selected by (Triggering player)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Titan Palace <gen> contains (Picked unit)) Equal to False
              • (Owner of (Picked unit)) Equal to (Triggering player)
            • Then - Actions
              • Custom script: call SetImmovableUnitFacing(GetEnumUnit(), udg_TempInt)
            • Else - Actions
Second, SetImmovableUnitFacing uses SetUnitPosition, which issues the "stop" order. So whenever this trigger fires, all the units will get issued stop orders.
 
Level 22
Joined
Feb 3, 2009
Messages
3,292
The problem is, that without moving the unit first it doesn't seem to work on buildings. I also decided to only make it work if the selected count equals to 1 unit.

Here's the new trigger:

  • Set Facing
    • Events
    • Conditions
    • Actions
      • Set TempInt = (Integer((Substring((Entered chat string), 3, 8))))
      • Set TempGroup = (Units currently selected by (Triggering player))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in TempGroup) Equal to 1
        • Then - Actions
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • And - All (Conditions) are true
                    • Conditions
                      • (Titan Palace <gen> contains (Picked unit)) Equal to False
                      • (Owner of (Picked unit)) Equal to (Triggering player)
                • Then - Actions
                  • Unit - Make (Picked unit) face (Real(TempInt)) over 0.00 seconds
                  • Custom script: call SetImmovableUnitFacing(GetEnumUnit(), udg_TempInt)
                • Else - Actions
        • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup)
 
Run some tests to see if some combinations of function could be causing it. For example if I remember right, from previous experiences setting a units facing angle over 0.00 seconds isn't instant. Prehapse replace it with this function as it doesn't require a wait (as I have observed).
JASS:
call SetUnitFacing(udg_Unit, bj_UNIT_FACING)
Although I have not actually tested it without doing it this way before though.
 
yes, but it doesn't suggest for a possible turn for the unit so it should just set it directly set the angle instead of having suggest that it may make another slight wait for it to function although it is set to 0.00 seconds. Anyway I am only suggesting that this may help with a function like the one done in the trigger strait after.
I am only suggesting that it is worth a try considering that some WE functions are bugged and this may fix the problem.
 
Status
Not open for further replies.
Top