• 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] Changing unit ownership

Status
Not open for further replies.
Level 4
Joined
Apr 9, 2010
Messages
60
Hey guys ...
I need to ask about changing selected unit ownership via GUI ...

I want to make this work like this:

Player types -give blue
Then the unit he selected will be given to blue player.

I've seen this in various maps, but couldn't find any of these to copy the trigger ...
I've googled for this, searched even by myself at some webpages (like thehelper, even hive's) but found nothing ... :/

Can you give me a hand? Thank you. :wink:
 
Level 5
Joined
May 12, 2008
Messages
80
  • give player
    • Ereignisse
      • Spieler - Spieler 1 (Rot) types a chat message containing -give as Ein Teil-String
      • Spieler - Spieler 2 (Blau) types a chat message containing -give as Ein Teil-String
      • Spieler - Spieler 3 (Blaugrau) types a chat message containing -give as Ein Teil-String
      • put following players here
    • Bedingungen
    • Aktionen
      • Set Picked_Units = (Units currently selected by (Triggering player))
      • Einheitengruppe - Pick every unit in Picked_Units and do (Actions)
        • Schleifen - Aktionen
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • 'IF'-Bedingungen
              • (Owner of (Picked unit)) Gleich (Triggering player)
            • 'THEN'-Aktionen
              • Einheit - Change ownership of (Picked unit) to (Player((Integer((Substring((Entered chat string), 7, 8)))))) and Farbe wechseln
            • 'ELSE'-Aktionen
      • Custom script: call DestroyGroup (udg_Picked_Units)
:fp:To give a unit or group (it should be yours) to a playeryou should pick it/them and enter "-give X" (X = player-number).
 
Well, it's actually kinda easy. I'll show you two triggers here and I've added comments to show you what each thing does:

  • Give Control Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- This is the text the player must write in order to change ownership to a player. --------
      • Set PlayerString[1] = Red
      • Set PlayerString[2] = Blue
      • Set PlayerString[3] = Teal
      • Set PlayerString[4] = Purple
      • Set PlayerString[5] = Yellow
      • Set PlayerString[6] = Orange
      • Set PlayerString[7] = etc....
  • Give Control
    • Events
      • Player - Player 1 (Red) types a chat message containing -give as A substring
      • Player - Player 2 (Blue) types a chat message containing -give as A substring
      • Player - Player 3 (Teal) types a chat message containing -give as A substring
      • Player - Player 4 (Purple) types a chat message containing -give as A substring
      • Player - Player 5 (Yellow) types a chat message containing -give as A substring
      • Player - Player 6 (Orange) types a chat message containing -give as A substring
    • Conditions
    • Actions
      • -------- Checks if the number of units a player has selected only is 1. --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units currently selected by (Triggering player))) Equal to 1
        • Then - Actions
          • -------- A temporary string variable --------
          • Set tempString = (Substring((Entered chat string), 7, (Length of (Entered chat string))))
          • -------- A temporary unit variable --------
          • Set tempUnit = (Random unit from (Units currently selected by (Triggering player)))
          • -------- Checks if the owner of the unit is the player that typed "-give" --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of tempUnit) Equal to (Triggering player)
            • Then - Actions
              • -------- Set 12 to the number of the total players of your map. --------
              • For each (Integer A) from 1 to 12, do (Actions)
                • Loop - Actions
                  • -------- Checks if the text a player typed in matches with any of the players --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • tempString Equal to PlayerString[(Integer A)]
                    • Then - Actions
                      • -------- If succeed, the unit will change it's owner --------
                      • Unit - Change ownership of tempUnit to (Player((Integer A))) and Change color
                    • Else - Actions
            • Else - Actions
          • -------- Clear variables --------
          • Custom script: set udg_tempUnit = null
          • Custom script: set udg_tempString = ""
        • Else - Actions
I am using three variables:
tempString > a string variable
PlayerString > a string array variable
tempUnit > a unit variable

Just copy and paste this and you'll have a working system :)
 
Level 4
Joined
Apr 9, 2010
Messages
60
Well, I am a kinda starting mapper so ...

My face went 'O_O' after I saw what you, Flood, wrote ...
I found out how to make the first trigger but got stuck on second 'coz I simply can't figure out how to get that c**p into it. :sad:

Would you please be that kind to get these triggers in an actual map and then upload it somewhere, so I can look where everything is? :sad:
 
Well, I am a kinda starting mapper so ...

My face went 'O_O' after I saw what you, Flood, wrote ...
I found out how to make the first trigger but got stuck on second 'coz I simply can't figure out how to get that c**p into it. :sad:

Would you please be that kind to get these triggers in an actual map and then upload it somewhere, so I can look where everything is? :sad:

Haha, now I didn't really saved the map xD, but yeah... Sure, I can make a quick remake :) Wait 5-10 minutes.

EDIT: View attachment Change Owner.w3x, there's the map :)
 
Status
Not open for further replies.
Top