HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

taking a unit HP to death makes GetOwningPlayer(GetKillingUnit()) == Player(0)

09-18-2007, 09:32 PM#1
grupoapunte
Hey im having this weird problem, i made a trigger that takes HP from a unit if it dont have mana until it dies, the problem is that after the unit dies another trigger takes the dead and updates a Multiboard giving the kill to player 0 (red), but this shouldnt happend, I displayed the value of GetOwningPlayer(GetKillingUnit()) and it says its Player(0). This shouldnt be like this because Red didnt kill that unit. This is the trigger that takes the HP:

Collapse JASS:
function Trig_HP_Lose_Actions takes nothing returns nothing
    local integer i = 1
    
    loop
        exitwhen i > 12
        if (GetUnitStateSwap(UNIT_STATE_MANA, udg_Heros[i]) <= 1) then
            if (GetUnitTypeId(udg_Heros[i]) == rcSurvivor()) then
                call SetUnitLifeBJ(udg_Heros[i], (GetUnitStateSwap(UNIT_STATE_LIFE, udg_Heros[i]) - 15.00))
            endif
        endif
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_HP_Lose takes nothing returns nothing
    set gg_trg_HP_Lose = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(gg_trg_HP_Lose, 1.00)
    call TriggerAddAction(gg_trg_HP_Lose, function Trig_HP_Lose_Actions)
endfunction

Any idea why this happends?

Thanks
09-19-2007, 01:41 AM#2
TaintedReality
Red didn't kill the unit, *nobody* did. You're using SetUnitLife, not having a unit deal damage, so it's just kind of neutral damage (not really damage at all actually, just changing the unit state). By default the player id is going to be 0, because that's what integers default to, so it just goes with Player(0).

What do you want to happen? Then we can help you more ^^.
09-19-2007, 02:12 AM#3
botanic
if you want to do it that way you could just make it so that the multiboard is set to -1 in the ability so when it is set to +1 it evens out
09-19-2007, 08:40 AM#4
Anitarf
GetOwningPlayer(GetKillingUnit()) gives you Player(0) because GetKillingUnit() gives you null and GetOwningPlayer(null) gives you Player(0). All you need is an additional check to make sure the killing unit is not equal to null to prevent neutral kills from being assigned to the first player.
09-19-2007, 05:09 PM#5
grupoapunte
Yes you are right, i never though of that, GetKillingUnit() gives you null, i just added that to the trigger that takes de unit deaths and its working great, thanks a lot