• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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?
 
Level 6
Joined
Oct 4, 2011
Messages
226
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

  • Health Test MAP.w3x
    16.5 KB · Views: 39
Level 9
Joined
Apr 23, 2011
Messages
460
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
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
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.
Top