• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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
77
  • 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).
 
Level 19
Joined
Aug 16, 2007
Messages
881
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:
 
Level 19
Joined
Aug 16, 2007
Messages
881
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