HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Destrucatable dies problems

12-28-2006, 11:04 PM#1
grupoapunte
Hi, I want to make a trigger that when a dustructable dies an item is droped at its location, the idea is when a tree is chopped it creates wood (the item) in the floor, for some reason its not working:

Collapse JASS:
function Trig_Tree_Dies_Actions takes nothing returns nothing
    local location l = GetDestructableLoc(GetDyingDestructable())
    
    call CreateItemLoc('I000', l)
    call RemoveLocation(l)
    set l = null
endfunction

//===========================================================================
function InitTrig_Tree_Dies takes nothing returns nothing
    set gg_trg_Tree_Dies = CreateTrigger()
    call TriggerRegisterDestDeathInRegionEvent(gg_trg_Tree_Dies, GetEntireMapRect())
    call TriggerAddAction(gg_trg_Tree_Dies, function Trig_Tree_Dies_Actions)
endfunction

I know i could do this by selecting all the trees in the map and make them drop an item, but that makes the script file weight 8mb and thats crazy it should be posible to make it easier.

Thanks
12-28-2006, 11:10 PM#2
rulerofiron99
You'll need a few triggers.

Here:
Trigger:
PickAllDestructiblesForEvents
Collapse Events
Map initialization
Conditions
Collapse Actions
Collapse Destructible - Pick every destructible in (Playable map area) and do (Actions)
Collapse Loop - Actions
Trigger - Add to CreateLumberFromTrees <gen> the event (Destructible - (Picked destructible) dies)
This trigger selects all destructables (you can add destructable type comparisons if you like) and adds the event of that destructable to the next trigger.

Trigger:
CreateLumberFromTrees
Events
Collapse Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
(Destructible-type of (Dying destructible)) Equal to Ashenvale Tree Wall
(Destructible-type of (Dying destructible)) Equal to Ashenvale Canopy Tree
Collapse Actions
Set tempPoint[0] = (Position of (Dying destructible))
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Destructible-type of (Dying destructible)) Equal to Ashenvale Tree Wall
Collapse Then - Actions
Item - Create Lumber at tempPoint[0]
Item - Create Lumber at tempPoint[0]
Collapse Else - Actions
Item - Create Ironwood Branch at tempPoint[0]
Custom script: call RemoveLocation(udg_tempPoint[0])
This trigger checks the type of destructable and creates the item accordingly.

Hope this helps, GUI FTW.
12-28-2006, 11:30 PM#3
grupoapunte
Ok done, one more question, i never worked with destrucable groups so i would like to know if any of this trigger leaks and how to fix them:

Collapse JASS:
function Trig_Pick_Trees_Group takes nothing returns nothing
    if (GetDestructableTypeId(GetEnumDestructable()) == 'WTst') then
        call TriggerRegisterDeathEvent(gg_trg_Tree_Dies, GetEnumDestructable())
    endif
endfunction

function Trig_Pick_Trees_Actions takes nothing returns nothing
    call EnumDestructablesInRectAll(GetPlayableMapRect(), function Trig_Pick_Trees_Group)
endfunction

//===========================================================================
function InitTrig_Pick_Trees takes nothing returns nothing
    set gg_trg_Pick_Trees = CreateTrigger()
    call TriggerAddAction(gg_trg_Pick_Trees, function Trig_Pick_Trees_Actions)
endfunction

Collapse JASS:
function Trig_Tree_Dies_Actions takes nothing returns nothing
    local location l = GetDestructableLoc(GetDyingDestructable())
    
    call CreateItemLoc('I000', l)
    call RemoveLocation(l)
    set l = null
endfunction

//===========================================================================
function InitTrig_Tree_Dies takes nothing returns nothing
    set gg_trg_Tree_Dies = CreateTrigger()
    call TriggerAddAction(gg_trg_Tree_Dies, function Trig_Tree_Dies_Actions)
endfunction

Thanks
12-28-2006, 11:33 PM#4
rulerofiron99
Not sure, I heard before that they don't leak, and even if they do, it's not a leak you should be worried about.
12-29-2006, 11:57 AM#5
Vexorian
destructable groups would 'leak' if destructable groups existed, if you check the code there is no part in which an instance of a "destructable group" is ever created