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

How to make killed destructibles drop items?

Status
Not open for further replies.
Level 6
Joined
Jan 8, 2009
Messages
140
The number of trees on my map is too large to just add item drop tables to them as I get some overflow error when trying to save after doing so. I figure I need to trigger it to get it to work but the problem i'm having is it doesn't seem to register when I cut the trees, it does work when using drop tables though.

My ability is based on Harvest (Ghouls Lumber) could this be the problem?
 
If I recall, there (was) is an event that allowed the detection of the death of widgets. When it fires, be it unit, item or destructable, you can filter out those that are trees.

This native can give you a clue as to how to make it work...
TriggerRegisterDeathEvent( <trigger>, <widget>)

EDIT:

You'll need a real variable: (Creating a variable in the variable editor will append a "udg_" prefix)

JASS:
real udg_WIDGET_DeathEvent = 1.00

Make a trigger.
Call it OnGameStart Enum.
Convert it to Custom Text.

Make sure to click the Run on Map Initialization checkbox first if it is not clicked already.

Now, copy and paste the following code into the newly generated JASS script:

JASS:
function OnGameStart_onDeathEvent takes nothing returns nothing
    call DestroyTrigger(GetTriggeringTrigger( ))
    set udg_WIDGET_DeathEvent = 1.00
    set udg_WIDGET_DeathEvent = 0.00
endfunction

function OnGameStart_onEnum takes nothing returns boolean
    local trigger t = CreateTrigger( )
    
    call TriggerRegisterDeathEvent(t, GetEnumDestructable( ))
    call TriggerAddCondition(t, Filter(function OnGameStart_onDeathEvent))

    set t = null
    return true
endfunction

function OnGameStart_onInit takes nothing returns nothing
    call EnumDestructablesInRect(bj_mapInitialPlayableArea, Filter(function OnGameStart_onEnum), null)
endfunction

function InitTrig_OnGameStart_Enum takes nothing returns nothing
    call ExecuteFunc("OnGameStart_onInit")
endfunction

To obtain the triggering widget, just use the native:

JASS:
constant native GetTriggerWidget takes nothing returns widget
 
Last edited:
Level 16
Joined
Mar 25, 2016
Messages
1,327
  • Tree
    • Events
      • Destructible - A destructible within (Playable map area) dies
    • Conditions
      • (Destructible-type of (Dying destructible)) Equal to Summer Tree Wall
    • Actions
      • Item - Create Crown of Kings +5 at (Position of (Dying destructible))
This worked for me. I tested it with ghoul and there was no problem.

The trigger is not good, because it has a leak, but the trigger is just to showcase, how you can do it.
 
Status
Not open for further replies.
Top