HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need help with panda items

05-11-2006, 07:27 PM#1
The_AwaKening
I gave the panda spawns an inventory of 2. My goal was to have the items on the panda transfer over to his spawns when he splits. It works and he gets them back ok except in one situation. If all 3 of them die, then the last one to die doesn't have the items transfer back over. The items just get dropped.

Here is the trigger to transfer items to spawns. This one works fine.
Collapse JASS:
function PandaSplitBool takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit())=='npn1' or GetUnitTypeId(GetFilterUnit())=='npn2' or GetUnitTypeId(GetFilterUnit())=='npn3'
endfunction

function Trig_Panda_Split_Actions takes nothing returns nothing
 local integer i=0
 local unit u=GetTriggerUnit()
 local player p=GetOwningPlayer(u)
 local group g=CreateGroup()
 local item array It
 local boolexpr b=Condition(function PandaSplitBool)

    set udg_pandas[GetPlayerId(p)]=u
    loop
        exitwhen i>5
        if GetItemTypeId(UnitItemInSlot(u,i))!='IC16' and GetItemTypeId(UnitItemInSlot(u,i))!='IC15' then
            set It[i]=UnitItemInSlot(u,i)
        endif
        set i=i+1
    endloop
    call TriggerSleepAction(2)
    set i=0
    call GroupEnumUnitsOfPlayer(g,p,b)
    set u=FirstOfGroup(g)
    loop
        exitwhen u==null
        call UnitAddItem(u,It[i])
    call UnitAddItem(u,It[i+1])
        call GroupRemoveUnit(g,u)
        set u=FirstOfGroup(g)
        set i=i+2
    endloop
    call DestroyGroup(g)
    call DestroyBoolExpr(b)
    set i=0

 loop
     exitwhen i>5
     set It[i]=null
     set i=i+1
 endloop
 set u=null
 set p=null
 set g=null
 set b=null
endfunction

//===========================================================================
function Trig_Panda_Split_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'ANef'
endfunction

function InitTrig_Panda_Split takes nothing returns nothing
    set gg_trg_Panda_Split = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Panda_Split, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Panda_Split, Condition( function Trig_Panda_Split_Conditions ) )
    call TriggerAddAction( gg_trg_Panda_Split, function Trig_Panda_Split_Actions )
endfunction
Here is the next part which is actually part of a bigger trigger. I removed everything else and only put in the panda part of it.
Collapse JASS:
function Trig_Army_kill_Actions takes nothing returns nothing
 local unit t=GetDyingUnit()
 local player pt=GetOwningPlayer(t)
 local integer i

    if GetUnitTypeId(t)=='npn1' or GetUnitTypeId(t)=='npn2' or GetUnitTypeId(t)=='npn3' then
        call UnitAddItem(udg_pandas[GetPlayerId(pt)],UnitItemInSlot(t,0))
        call UnitAddItem(udg_pandas[GetPlayerId(pt)],UnitItemInSlot(t,1))
     endif

 set t=null
 set pt=null
endfunction

//=================================================================
function InitTrig_Unit_killed takes nothing returns nothing
    local integer i = 0
    set gg_trg_Unit_killed = CreateTrigger(  )
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerUnitEventSimple( gg_trg_Unit_killed, Player(i), EVENT_PLAYER_UNIT_DEATH )
        set i = i + 1
    endloop
    call TriggerAddAction( gg_trg_Unit_killed, function Trig_Army_kill_Actions )
endfunction
Any suggestions to improve would be great !!
05-11-2006, 08:37 PM#2
Blade.dk
This is just a guess, but it might be because the main unit dies when all the spanws are dead, and adding an item then causes problems.

Eventually check if it is dead, and if it is, revive it, add the items and kill it again instantly.
05-11-2006, 09:14 PM#3
Anitarf
I'm not sure if heroes can be revived the moment they die, there's the whole "becomes revivable" event that happens a couple of seconds after the death, but it could be just the "becomes revivable at altars" event and maybe they can be revived sooner by triggers.
05-11-2006, 09:36 PM#4
Blade.dk
Never tested it, you might be right.

If that is the case, you can just save the items, wait for the unit to become revivable and add them. Nobody will see that the unit does not have the items yet if it is dead, so it should not really be a problem.
05-12-2006, 01:28 AM#5
The_AwaKening
Other problem with that though is that the items end up on the ground after the spawn dies. Suppose I could set them to a global and have them added back when revived. I wish there was a global for item groups