• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Very simple trigger fails to work?

Status
Not open for further replies.
Level 6
Joined
Mar 17, 2012
Messages
105
  • 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?
 
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.
 

Attachments

Here's a vJass script that should work for you. I can't test it because my World Editor is broken atm :/

JASS:
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
 
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.
 
Status
Not open for further replies.
Back
Top