vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

[snippet] IsDestructableTree

Guest · 569

0 Members and 1 Guest are viewing this topic.

[snippet] IsDestructableTree
on: December 22, 2011, 12:44:16 AM
Category: Variables
Language: vJASS
Download Demo Map

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.


Code: jass
  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. globals
  13.     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. endglobals
  19.  
  20. function IsDestructableDead takes destructable dest returns boolean
  21.     return GetDestructableLife(dest) <= 0.405
  22. endfunction
  23.  
  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.     endif
  31.     return result
  32. endfunction
  33.  
  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. endfunction
  41. endlibrary
  42.  


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?
« Last Edit: December 18, 2017, 01:25:31 PM by moyack »



 

Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)