1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. The member Kam is making HIVE coasters. Take a look. For every coaster you buy, Hive gets $1.
    Dismiss Notice
  3. Buy it, use it, break it, fix it, trash it, change it, mail - upgrade it. Join (Optionally) Paired Techtree Contest #11 - Techno Magic now!
    Dismiss Notice
  4. Dismiss Notice
  5. Hero Contest #8 is up and running! This time it's a joint contest between artists and coders. Go here for team matchmaking.
    Dismiss Notice
  6. The ninth Concept Art Contest has launched. Enter now!
    Dismiss Notice
  7. Our first StarCraft contest, The Galaxy Terraining Contest #1 - World Wonders has started. Enter to show off your Galaxy Editor skills and win a custom rank icon among other things.
    Dismiss Notice
  8. Ever wanted to get your sets ready for fast texturing while still having fun? Now it is possible with our newest Mini-Texturing Contest.
    The Skeleton Units need your dire help!
    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,192
    • 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