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 IsDestructableTree 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 IsDestructableDead 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.
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?
1 library DestructableLib initializer Initialization
2 //* ============================================================================ *3 //* Made by PitzerMike *4 //* *5 //* I made this to detect if a destructable is a tree or not. It works not only *6 //* for the standard trees but also for custom destructables created with the *7 //* object editor. It uses a footie as a dummy with the goul's harvest ability. *8 //* The dummy ids can be changed though. I also added the IsDestructableDead *9 //* function for completeness. *10 //* ============================================================================ *11 12 globals13 private constant integer DUMMY_UNIT_ID = 'hfoo' // footman
14 private constant integer HARVEST_ID = 'Ahrl' // ghouls harvest
15 private constant player OWNING_PLAYER = Player(15)
16
17 private unit dummy = null
18 endglobals19 20 function IsDestructableDead takes destructable dest returns boolean
21 return GetDestructableLife(dest) <= 0.405
22 endfunction23 24 function IsDestructableTree takes destructable dest returns boolean
25 local boolean result = false
26 if (dest != null) then
27 call PauseUnit(dummy, false)
28 set result = IssueTargetOrder(dummy, "harvest", dest)
29 call PauseUnit(dummy, true) // stops order
30 endif31 return result32 endfunction33 34 private function Initialization takes nothing returns nothing
35 set dummy = CreateUnit(OWNING_PLAYER, DUMMY_UNIT_ID, 0.0, 0.0, 0.0)
36 call ShowUnit(dummy, false) // cannot enumerate
37 call UnitAddAbility(dummy, HARVEST_ID)
38 call UnitAddAbility(dummy, 'Aloc') // unselectable, invulnerable
39 call PauseUnit(dummy, true)
40 endfunction41 endlibrary42
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?