| 01-03-2009, 11:39 AM | #1 |
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. Library: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? PS: Anyone noticed how similar this looks to Dusquo's PathabilityCheck? ![]() |
| 01-03-2009, 12:35 PM | #2 |
Giving a unit Aloc also makes it invulnerable and it also removes its pathing, so aren't these two lines useless? JASS:call SetUnitPathing(dummy, false) call UnitAddAbility(dummy, 'Avul') // invulnerable |
| 01-03-2009, 12:41 PM | #3 |
So many of these (I mean types... the IsSomethingSomething)... but very useful, I've needed one of those many times. |
| 01-03-2009, 01:36 PM | #4 |
I wasn't exactly sure about the properties of Aloc, I'll just remove the two lines. Also updated the demo map. |
| 01-03-2009, 01:56 PM | #5 |
Does this only works for trees or can it work for other things such as bridges and other destructibles such as boxes? |
| 01-03-2009, 02:06 PM | #6 |
A wood abilitie can target only a tree or a custom destructable based on a tree, that's your anwser. |
| 01-03-2009, 07:13 PM | #7 |
Yeah, approved. |
| 01-03-2009, 07:43 PM | #8 |
Thanks, Dusk and Pyro. :) |
| 01-04-2009, 06:47 AM | #9 |
Hmm... 1. Why not creating ghoul ('ugho'), which is already have harvest ability, instead of footman? This can get rid of another two lines in script :) 2. GetWidgetLife(dest) is a little bit faster than GetDestructableLife(dest) (not noticeable, in fact...) |
| 01-04-2009, 07:35 AM | #10 |
Because what if someone edits the default ghoul unit on their map to not have the harvest ability? Then it doesn't matter what unit it is because you still have to add the harvest ability to it, so it's better to be safe and do it the way he has done. |
| 09-06-2011, 08:58 AM | #11 |
This library could be shortened to just this: JASS:library IsDestructableTree //* ============================================================================ * //* 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 locust as a dummy with the ghoul's harvest ability. * //* ============================================================================ * globals private constant integer HARVEST_ABIL = 'Ahrl' // ghouls harvest private constant integer HARVEST_ID = 0xD0032 // harvest order ID private constant integer DUMMY_ID = 'uloc' // locust unit type private unit u = null endglobals function IsDestructableTree takes destructable d returns boolean return IssueTargetOrderById(u, HARVEST_ID, d) endfunction private module M private static method onInit takes nothing returns nothing set u = CreateUnit(Player(15), DUMMY_ID, 0, 0, 0) // unselectable, untargetable, can't be enumerated call ShowUnit(u, false) //Invisible call UnitAddAbility(u, HARVEST_ABIL) call UnitRemoveAbility(u, 'Amov') // the unit can never follow through with order, so endmethod // you don't need to pause/unpause the unit. endmodule private struct S extends array implement M endstruct endlibrary |
| 09-23-2011, 08:55 PM | #12 |
Instead of call UnitAddAbility(u, HARVEST_ID) should be: call UnitAddAbility(u, HARVEST_ABIL) |
| 09-24-2011, 04:35 AM | #13 |
Thanks Spinnaker, I messed it up when I changed the order ID to be a constant and took over the old name. |
| 05-07-2014, 01:21 PM | #14 |
Bribe, your version is incorrect because hidden units can move and destroy trees. See attached map. Also see http://www.hiveworkshop.com/forums/j...letree-248054/ |
| 05-07-2014, 10:23 PM | #15 |
They tend to struggle at moving if they've had the move ability removed though :p call UnitRemoveAbility(u, 'Amov') |
