1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Choose a model and craft your spell in Zephyr Contest #15!
    Dismiss Notice
  3. Compete in Concept Art Contest - Bounty Hunter . May the best artist's bounty hunter execute!
    Dismiss Notice
  4. The Modeling Mini-Contest #5 - Familiar is up! Compete to design a pet companion to a lonely WC3 Hero of your preference.
    Dismiss Notice
  5. The 6th installment of our Music Contest just got fired up! Now with an Apocalyptic taste. Get started and compete in this musical battle!
    Dismiss Notice
  6. Looking to expand an altered melee race of yours? Join the Advanced Techtree Contest - Recycle, Revise, Reinvent contest!
    Dismiss Notice

Very simple trigger fails to work?

Discussion in 'Triggers & Scripts' started by Marine, Apr 8, 2012.

  1. Marine

    Marine
    Joined:
    Mar 17, 2012
    Messages:
    102
    • CC
      • Events
        • Unit - Village 0050 <gen>'s life becomes Less than 50.00
      • Conditions
      • Actions
        • Unit - Change ownership of Village 0050 <gen> to (Owner of (Attacking unit)) and Change color


    When tested, the Village remains in control of the original player once the health goes below 50. Why does this not work?
     
  2. khamarr3524

    khamarr3524
    Joined:
    Apr 23, 2011
    Messages:
    450
    I believe since you aren't using an attacking event it wont register that the unit is attacked. Try changing the event to A Unit is Attacked. Then the condition unit is == your unit and life of attacked unit < 50. Then do your actions.
     
  3. Space_Ship

    Space_Ship
    Joined:
    Oct 4, 2011
    Messages:
    223
    Attacking unit wont exit the event doesnt refer to a unit attacking.
    Here this is how you would do it a small test map.
    let me know if you still have questions.

    Edit: I used a unit takes damage because this can work for more then just attacking you might be wanting attackers only though.
     

    Attached Files:

  4. khamarr3524

    khamarr3524
    Joined:
    Apr 23, 2011
    Messages:
    450
    Here's a vJass script that should work for you. I can't test it because my World Editor is broken atm :/

    Code (vJASS):
    scope OwnerSwap initializer init
        private function SwapOwner takes unit u, real hp, player p returns nothing
            local integer spawnType = GetUnitTypeId(u)
            local real x = GetUnitX(u)
            local real y = GetUnitY(u)
            local real f = GetUnitFacing(u)
            call RemoveUnit(u)
            call CreateUnit(p, spawnType, x, y, f)
            call SetUnitState(u, UNIT_STATE_LIFE, hp)
            set u = null
            set p = null
        endfunction
        private function ConditionRun takes nothing returns nothing
            local unit u = GetTriggerUnit()
            local real hp = GetUnitState(u, UNIT_STATE_LIFE)
            local player p = GetOwningPlayer(GetAttacker())
            if GetUnitTypeId(u) == 'htow' and hp < 50. then
                call SwapOwner(u, hp, p)
            endif
            set u = null
            set p = null
        endfunction
        private function init takes nothing returns nothing
            local trigger t = CreateTrigger()
            local integer i = 0
            loop
                call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, null)
                set i = i + 1
                exitwhen i > 11
            endloop
            call TriggerAddAction(t, function ConditionRun)
            set t = null
        endfunction
    endscope
       
     
  5. Spartipilo

    Spartipilo
    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Use the event "A unit is attacked" in the conditions check if "Attack Unit = Village 0050 <gen>" and in the conditions check if "Healt of Village 0050 <gen>" is less than or equal to 50" Then you can use the action to change ownership of the unit to the attacking unit.
     
  6. Maker

    Maker
    Joined:
    Mar 6, 2006
    Messages:
    9,189
    • Untitled Trigger 007
      • Events
        • Unit - Archer 0023 <gen> Takes damage
      • Conditions
        • ((Life of (Triggering unit)) - (Damage taken)) Less than or equal to 50.00
      • Actions
        • Unit - Change ownership of (Triggering unit) to (Owner of (Damage source)) and Change color