• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

changing ownership

Status
Not open for further replies.
Level 16
Joined
Jan 21, 2011
Messages
999
guys! just wanna ask how to change the ownership of a unit!
say, pokemon game (no, i'm not making a pokemon game!) the units are passive and dare to not even attack, but when you attack them, they become hostile.
how can i make a trigger like that?
oh and another thing!, how to make a unit attack when you're in his range for quite long? say, 7 seconds??

EDIT: i don't know how to JASS.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
There is a native to change the ownership of a unit. It takes the unit and the player you want to give it to and when executed it will change the ownership.
If you can not devise a simple trigger for that, then you need to practice more before maping. Break the problem down into its individual elements and create code to perform them.

Make all units neutral pasive, and when your in their range for 7 seconds change them to hostile.
 
Level 16
Joined
Jan 21, 2011
Messages
999
There is a native to change the ownership of a unit. It takes the unit and the player you want to give it to and when executed it will change the ownership.
If you can not devise a simple trigger for that, then you need to practice more before maping. Break the problem down into its individual elements and create code to perform them.

Make all units neutral pasive, and when your in their range for 7 seconds change them to hostile.

hmmm. i'll try that!
 
Level 4
Joined
Aug 19, 2009
Messages
81
There is a "Change owner" in the unit section in the trigger editor. If you dont know how to use the trigger editor then you should probably look at some tutorials.
 
Level 8
Joined
Dec 12, 2010
Messages
280
This trigger would probably do the trick

  • ChangeOwner
    • Events
      • Unit - A unit comes within 256.00 of <your unit here>
    • Conditions
    • Actions
      • Set Temp_Unit = (Triggering unit)
      • Wait 7.00 game-time seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between (Position of Temp_Unit) and (Position of <your unit here>)) Less than or equal to 256.00
        • Then - Actions
          • Unit - Change ownership of <your unit here> to Neutral Hostile and Change color
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • Set Temp_Unit = No unit
You will have to create one unit variable for this trigger named Temp_Unit
After 7 seconds this trigger checks to make sure the unit is still in the area if so it fires the action if not it does nothing.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • ChangeOwner
    • Events
      • Unit - A unit comes within 256.00 of <your unit here>
    • Conditions
    • Actions
      • Set Temp_Unit = (Triggering unit)
      • Wait 7.00 game-time seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between (Position of Temp_Unit) and (Position of <your unit here>)) Less than or equal to 256.00
        • Then - Actions
          • Unit - Change ownership of <your unit here> to Neutral Hostile and Change color
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • Set Temp_Unit = No unit

Fix the leaks and use triggering unit, not a global variable :)
 
Level 8
Joined
Dec 12, 2010
Messages
280
Ok, Ya caught me. This trigger fixes the point leaks.

  • ChangeOwner
    • Events
      • Unit - A unit comes within 256.00 of <your unit>
    • Conditions
    • Actions
      • Set Temp_Unit = (Triggering unit)
      • Wait 7.00 game-time seconds
      • Set TempPoint_1 = (Position of Temp_Unit)
      • Set TempPoint_2 = (Position of <your unit>)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between TempPoint_1 and TempPoint_2) Less than 256.00
        • Then - Actions
          • Unit - Change ownership of <your unit> to Neutral Hostile and Change color
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Set Temp_Unit = No unit
      • Custom script: call RemoveLocation(udg_TempPoint_1)
      • Custom script: call RemoveLocation(udg_TempPoint_2)
But setting <your unit> to a unit variable, maybe at map ini, and using that variable here in place of <your unit> would make this trigger fire faster and more efficently. Btw where you see <your unit> in this trigger would be where you select a unit on the map.

I know its better to use triggering unit (local) instead of something like unit within range (global) as I did in the above triggers so I'm not sure what you meant? Please show me the error of my ways master Maker :)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Now it's MUI. But turning the trigger off isn't enough, check that the owner of the converted unit is the original owner, that it hasn't been converted yet.
  • ChangeOwner
    • Events
      • Unit - A unit comes within 256.00 of <your unit>
    • Conditions
    • Actions
      • Wait 7.00 game-time seconds
      • Set TempPoint_1 = (Position of Triggering unit)
      • Set TempPoint_2 = (Position of <your unit>)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between TempPoint_1 and TempPoint_2) Less than 256.00
        • Then - Actions
          • Unit - Change ownership of <your unit> to Neutral Hostile and Change color
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_TempPoint_1)
      • Custom script: call RemoveLocation(udg_TempPoint_2)
 
Level 8
Joined
Dec 12, 2010
Messages
280
That makes a lot of sense

  • ChangeOwner
    • Events
      • Unit - A unit comes within 256.00 of No unit
    • Conditions
      • (Owner of <your unit>) Not equal to Neutral Passive
    • Actions
      • Set Temp_Unit = (Triggering unit)
      • Wait 7.00 game-time seconds
      • Set TempPoint_1 = (Position of Temp_Unit)
      • Set TempPoint_2 = (Position of No unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between TempPoint_1 and TempPoint_2) Less than 256.00
        • Then - Actions
          • Unit - Change ownership of No unit to Neutral Hostile and Change color
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Set Temp_Unit = No unit
      • Custom script: call RemoveLocation(udg_TempPoint_1)
      • Custom script: call RemoveLocation(udg_TempPoint_2)
 
Status
Not open for further replies.
Top