• 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] more effective way of doing this?

Status
Not open for further replies.
Level 2
Joined
Jun 28, 2015
Messages
20
so i have a trigger that makes it so that if a player types in a chat message, and is in a specific location, then something will happen.
i currently have it set up like this:

  • Trigger Dark Green
    • Events
      • Player - Player 11 (Dark Green) types a chat message containing chatmessage as An exact match
    • Conditions
      • integer Greater than or equal to 1
    • Actions
      • action here
  • DarkGreen Exit
    • Events
      • Unit - A unit leaves area <gen>
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Set integer = (integer - 1)
  • DarkGreen Enter
    • Events
      • Unit - A unit enters area <gen>
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Set integer = (integer + 1)
is there a better (namely shorter) way of doing this? because if not ill have to re-make this trigger for every player, and that will be unoptimized as hell. this im a novice at best but this was the only way i could think of getting things to work.

any help is appreciated.
 
Use the "Unit Group - Pick every unit in region" function to find all units within <area>. It should work just fine. :) Here is an example (also, you might not need to split up triggers by player. you can have multiple events tied to one trigger, and it'll fire whenever any of those events are used):
  • Trigger Stuff
    • Events
      • Player - Player 1 (Red) types a chat message containing chatmessage as An exact match
      • Player - Player 10 (something) types a chat message containing chatmessage as An exact match
      • Player - Player 11 (Dark Green) types a chat message containing chatmessage as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units in area) matching (Matching unit is owned by (Triggering
  • player))
    • // do stuff
    • Custom script: call DestroyGroup(udg_TempGroup)
If you want to do something with the units, you can use "Pick every unit in TempGroup" to iterate over the units in the region owned by the player who typed the chat message. If you just need to check if there is more than 1 unit in the group, then you can use an if/then/else statement and check if the number of units in the group is greater than 0.
 
Level 6
Joined
Mar 17, 2012
Messages
105
Here you go, these three triggers let it work for all players. It works by using arrays, and calling the array value of the player number. Just check the "Array" box when you're making the Integer variable and set it to size 12.

  • ChatMessage
    • Events
      • Player - Player 1 (Red) types a chat message containing chatmessage as An exact match
      • Player - Player 2 (Blue) types a chat message containing chatmessage as An exact match
      • Player - Player 3 (Teal) types a chat message containing chatmessage as An exact match
      • Player - Player 4 (Purple) types a chat message containing chatmessage as An exact match
      • Player - Player 5 (Yellow) types a chat message containing chatmessage as An exact match
      • Player - Player 6 (Orange) types a chat message containing chatmessage as An exact match
      • Player - Player 7 (Green) types a chat message containing chatmessage as An exact match
      • Player - Player 8 (Pink) types a chat message containing chatmessage as An exact match
      • Player - Player 9 (Gray) types a chat message containing chatmessage as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing chatmessage as An exact match
      • Player - Player 11 (Dark Green) types a chat message containing chatmessage as An exact match
      • Player - Player 12 (Brown) types a chat message containing chatmessage as An exact match
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Active_Integer_Array[(Player number of (Triggering player))] Greater than or equal to 1
        • Then - Actions
          • -------- actions --------
        • Else - Actions
  • EnterRegion
    • Events
      • Unit - A unit enters Region <gen>
    • Conditions
    • Actions
      • Set Active_Integer_Array[(Player number of (Owner of (Entering unit)))] = 1
  • LeaveRegion
    • Events
      • Unit - A unit leaves Region <gen>
    • Conditions
    • Actions
      • Set Active_Integer_Array[(Player number of (Owner of (Entering unit)))] = 0
 
Level 2
Joined
Jun 28, 2015
Messages
20
thanks for the help you guys. i would've had to hammer out that trigger 9000 times else.
and thanks a ton for the explanations. i think i have a fair understanding of both methods now.
 
Level 5
Joined
Jan 17, 2014
Messages
131
Here you go:

  • Trigger 1
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Add the event of typing the message for all players to Trigger 2 --------
      • For each (Integer A) from 1 to 16, do (Trigger - Add to Trigger 2 <gen> the event (Player - (Player((Integer A))) types a chat message containing ChatMessage as An exact match))
  • Trigger 2
    • Events
    • Conditions
    • Actions
      • -------- Pick up all units owned by the triggering player in Region and place them in Unit_Group. --------
      • Set Unit_Group = (Units in Region owned by (Triggering player))
      • -------- Check if there are any units owned by the triggering player in Region. --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit_Group is empty) Equal to False
        • Then - Actions
          • -------- And now, do your desired action. --------
          • Do Stuff
          • -------- And lastly, remove all the units from the unit group. --------
          • Unit Group - Remove all units from Unit_Group
        • Else - Actions
          • Do nothing


That is if you just need a unit in the region, but if "Do Stuff" involves each and every unit owned by the triggering player in the Region, Trigger 2 should look like this:



  • Trigger 2
    • Events
    • Conditions
    • Actions
      • -------- Pick up all units owned by triggering player and place them in Unit_Group. --------
      • Set Unit_Group = (Units in Region owned by (Triggering player))
      • -------- Pick up all units in Unit_Group and do your desired action for each and every on of them. --------
      • Unit Group - Pick every unit in Unit_Group and do (Actions)
        • Loop - Actions
          • -------- And now, do your desired action. --------
          • Do Stuff
      • -------- And lastly, remove all the units from the unit group. --------
      • Unit Group - Remove all units from Unit_Group


And that's just about it.
 
Last edited:
Status
Not open for further replies.
Top