[snippet] IsDestructableTree

Scripts

14 years
edited 8 years
So I went through my old scripts at www.wc3jass.com and found this one. I decided to remake it as a library with some minor improvements. The [lcode=jass]IsDestructableTree[/lcode] function should come in handy for certain spells and systems. It works for the standard trees as well as custom trees (destructables based off trees). I've also included [lcode=jass]IsDestructableDead[/lcode] for completeness. It uses the unmodified footman as a dummy with the ghoul harvest ability, so there are no changes in the object editor required.


Code (jass) Select
library DestructableLib initializer Initialization
//* ============================================================================ *
//* Made by PitzerMike                                                           *
//*                                                                              *
//* I made this to detect if a destructable is a tree or not. It works not only  *
//* for the standard trees but also for custom destructables created with the    *
//* object editor. It uses a footie as a dummy with the goul's harvest ability.  *
//* The dummy ids can be changed though. I also added the IsDestructableDead     *
//* function for completeness.                                                   *
//* ============================================================================ *

globals
    private constant integer DUMMY_UNIT_ID = 'hfoo' // footman
    private constant integer HARVEST_ID    = 'Ahrl' // ghouls harvest
    private constant player OWNING_PLAYER  = Player(15)
   
    private unit dummy = null
endglobals

function IsDestructableDead takes destructable dest returns boolean
    return GetDestructableLife(dest) <= 0.405
endfunction

function IsDestructableTree takes destructable dest returns boolean
    local boolean result = false
    if (dest != null) then
        call PauseUnit(dummy, false)
        set result = IssueTargetOrder(dummy, "harvest", dest)
        call PauseUnit(dummy, true) // stops order
    endif
    return result
endfunction

private function Initialization takes nothing returns nothing
    set dummy = CreateUnit(OWNING_PLAYER, DUMMY_UNIT_ID, 0.0, 0.0, 0.0)
    call ShowUnit(dummy, false) // cannot enumerate
    call UnitAddAbility(dummy, HARVEST_ID)
    call UnitAddAbility(dummy, 'Aloc') // unselectable, invulnerable
    call PauseUnit(dummy, true)
endfunction
endlibrary



I've also included a test map with standard and custom trees to validate the script. It's not too exciting though.
Can you think of anything else that could be useful in a DestructableLib?
  • DestructableLib.w3x (19.74 KB)