1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

changing ownership

Discussion in 'World Editor Help Zone' started by TheKurt009, Jan 30, 2011.

  1. TheKurt009

    TheKurt009

    Joined:
    Jan 21, 2011
    Messages:
    572
    Resources:
    0
    Resources:
    0
    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.
     
  2. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,101
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
     
  3. TheKurt009

    TheKurt009

    Joined:
    Jan 21, 2011
    Messages:
    572
    Resources:
    0
    Resources:
    0
    hmmm. i'll try that!
     
  4. TheWarchief

    TheWarchief

    Joined:
    Aug 19, 2009
    Messages:
    64
    Resources:
    0
    Resources:
    0
    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.
     
  5. ironman47

    ironman47

    Joined:
    Dec 12, 2010
    Messages:
    238
    Resources:
    0
    Resources:
    0
    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.
     
  6. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    Fix the leaks and use triggering unit, not a global variable :)
     
  7. ironman47

    ironman47

    Joined:
    Dec 12, 2010
    Messages:
    238
    Resources:
    0
    Resources:
    0
    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 :)
     
  8. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    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)
     
  9. ironman47

    ironman47

    Joined:
    Dec 12, 2010
    Messages:
    238
    Resources:
    0
    Resources:
    0
    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)