• 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.

Loot Tables for Created Units

Status
Not open for further replies.
Level 6
Joined
Aug 11, 2015
Messages
223
I have started a project which will rely on having huge quantities of loot dropping constantly. But I've run into a snag.

I cannot find a way to add a loot table to a unit created with triggers. Is there a way I can do this, or another method that will let me bypass this limitation?
 
Off the top of my head, use a Unit Indexer. Then, on Index, if unit type equal to X unit, add your items, indexed to that specific unit (using 2D arrays). Then when said unit dies, drop the items from that specific list. It's kinda simplistic, so maybe you can find a better system out there if you want something more complex like item sets and such.

Or you can use hashtables. Should probably use hashtables. I'll make an example if I have time.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
6iXIKik.png

JASS:
function Unit000000_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( 'ratf', 50 )
        call RandomDistAddItem( 'gmfr', 50 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

        // Item set 1
        call RandomDistReset(  )
        call RandomDistAddItem( 'ckng', 75 )
        call RandomDistAddItem( -1, 25 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function CreateUnitsForPlayer0 takes nothing returns nothing
    local player p = Player(0)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set u = CreateUnit( p, 'hfoo', -4.9, -5.6, 31.170 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000000_DropItems )
endfunction
 
Status
Not open for further replies.
Top