HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Custom unit kills unit event not working

01-23-2009, 05:28 AM#1
Blackroot
Hey there, I'm trying to make a custom event based off dying units so that when a unit kills a unit it registers for the event. However, it's not working and I can't see why it's not .

Expand JASS:

Some notes reguarding the code, AssignUnitId(unit) returns the units ID if one is already assigned, or assigns an ID if a unit does not have one. SetUnitSpecialVal is a wrapper function for a gamecache. Both of these functions work.

I don't know why this doesn't however, I just don't see a problem with it ;?.
01-23-2009, 06:27 AM#2
Ammorth
Collapse JASS:
library KillUnitEvent initializer init uses UnitIdLib, USM
    globals
        trigger UnitDiesKill
        
        trigger array KillingEvents
        integer NumKillingEvents = 0
        unit EVENT_KILLING_UNIT
    endglobals
    
    function UnitIsKilled takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit k = GetKillingUnit()
        local integer I
        
        if(k == null or u == null)then
            return
        endif
        
        set I = AssignUnitId(k)
        set I = GetUnitSpecialVal(I, "KillEvent")
        if(I > 1 and I < NumKillingEvents)then
            set EVENT_KILLING_UNIT = k
            call TriggerExecute(KillingEvents[GetUnitSpecialVal(I, "KillEvent")])
        endif
    endfunction
    
    function RegisterUnitKillerEvent takes trigger t, unit killer returns nothing
        call SetUnitSpecialVal(AssignUnitId(killer), "KillEvent", NumKillingEvents)
        set KillingEvents[NumKillingEvents] = t
        set NumKillingEvents = NumKillingEvents + 1
    endfunction
    
    private function init takes nothing returns nothing
        set UnitDiesKill = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(UnitDiesKill, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddAction(UnitDiesKill, function UnitIsKilled)
    endfunction
endlibrary

You set I to a new value, and then try get a new value with it, instead of just re-using I in the array.
01-23-2009, 11:42 PM#3
Blackroot
Bleh! Easy fix, thanks!