1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. The SharpCraft World Editor Extended (WEX) has been updated for the latest Warcraft 3 version: Forum.
    Dismiss Notice
  3. The Paired Modeling/Texturing Contest #3 - Leaders has begun! Artists group up and struggle! May the best team lead the run.
    Dismiss Notice
  4. The long awaited results for Mini-Mapping Contest #13 is here! Congratulate the winners!
    Dismiss Notice
  5. Vote for the best Concept Art Contest - Bounty Hunter entry!
    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,199
    • 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