• 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] Chat command Unit transfer Help

Status
Not open for further replies.
Level 4
Joined
Dec 2, 2011
Messages
76
I am trying to make a trigger where if someone types something like -gu 2. It will give your selected units to player 2.

I have this so far.

  • Actions
  • Unit Group - Pick every unit in (Units currently selected by Player 1 (Red)) and do (Actions)
    • Loop - Actions
      • Unit - Change ownership of (Picked unit) to Player 2 (Blue) and Change color
The problem I am having is I can't figure out how to make it so any player can say this and it will work without me having to make lots of triggers for the situation.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
I will post the trigger soon, expect an edit.

<<< EDIT >>>

here you are:

  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Trigger - Add to Give Unit to Player <gen> the event (Player - (Picked player) types a chat message containing -gu as A substring)
  • Give Unit to Player
    • Events
    • Conditions
    • Actions
      • Set Index = (Integer((Substring((Entered chat string), 5, 5))))
      • Set gu_SourcePlayer = (Triggering player)
      • Set gu_TargetPlater = (Player(Index))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Index Greater than or equal to 0
          • gu_SourcePlayer Equal to gu_TargetPlater
        • Then - Actions
          • Game - Display to (Player group(gu_SourcePlayer)) the text: |cffffcc00Can not c...
        • Else - Actions
          • Set gu_SelectedUnit = (Random unit from (Units currently selected by gu_SourcePlayer))
          • Unit - Change ownership of gu_SelectedUnit to gu_TargetPlater and Change color
          • Game - Display to (All players) the text: ((Name of gu_SourcePlayer) + ( |cffffcc00changed ownership of|r + ((Name of gu_SelectedUnit) + ( |cffffcc00to|r + (Name of gu_TargetPlater)))))
 
Last edited:
Level 16
Joined
Mar 3, 2006
Messages
1,564
@ Maker, How about this, now ?

  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Trigger - Add to Give Unit to Player <gen> the event (Player - (Picked player) types a chat message containing -gu as A substring)
  • Give Unit to Player
    • Events
    • Conditions
    • Actions
      • Set Index = (Integer((Substring((Entered chat string), 5, 5))))
      • Set gu_SourcePlayer = (Triggering player)
      • Set gu_TargetPlater = (Player(Index))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Index Greater than or equal to 0
          • gu_SourcePlayer Equal to gu_TargetPlater
        • Then - Actions
          • Set gu_PlayerG = (Player group(gu_SourcePlayer))
          • Game - Display to gu_PlayerG the text: |cffffcc00Can not c...
        • Else - Actions
          • Set gu_Selection = (Units currently selected by gu_SourcePlayer)
          • Set gu_SelectedUnit = (Random unit from gu_Selection)
          • Unit - Change ownership of gu_SelectedUnit to gu_TargetPlater and Change color
          • Game - Display to (All players) the text: ((Name of gu_SourcePlayer) + ( |cffffcc00changed ownership of|r + ((Name of gu_SelectedUnit) + ( |cffffcc00to|r + (Name of gu_TargetPlater)))))
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Both leak, Player Group and Unit Group.

I got confused at first, you see I thought if I destroy the group the variable will be destroyed as well making it no longer available for another use but I now remember that variables are just pointer and I will be destroying what it is pointing to not the pointer itself. Anyway, thanks for the reminder. :ogre_hurrhurr:
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
You could name it TempVariableName, because you used it in the trigger that has instant effect.
Blizzard uses a single-threaded structure that you can never have bugs running 3 triggers at once as long as the effect of the trigger is instant (and yes, even those triggers uses same variable, but different variable setting for each trigger)

That's why after it is used, we destroy it.

By destroying the memory of the variable, we are not destroying the variable itself lol, just like Point variable and such.
 
Status
Not open for further replies.
Top