Warcraft 3 documentation
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] FlyHeight No New Posts Codes & Snippets

Started by
Magtheridon96

0 Members and 1 Guest are viewing this topic.

[Snippet] FlyHeight
on: August 05, 2012, 10:08:00 AM
Category: Units
Language: vJASS

Related Topics or Resources



by

The documentation has a brief explanation as to why I made this.

Code

Code: jass
  1. /*************************************
  2. *
  3. *   FlyHeight
  4. *   v1.0.0.1
  5. *   By Magtheridon96
  6. *
  7. *   - Warcraft III movement types are pretty
  8. *     bugged. It would be much better to write
  9. *     them from scratch. This system allows
  10. *     you to create flying units with changeable
  11. *     heights.
  12. *
  13. *     All units must have Movement Type Foot.
  14. *
  15. *   Requires:
  16. *   ---------
  17. *
  18. *       - UnitIndexer by Nestharus
  19. *           - https://wc3modding.info/4607/unitindexer/
  20. *
  21. *       Optional:
  22. *       ---------
  23. *
  24. *           - Table by Bribe
  25. *               - https://wc3modding.info/4611/snippet-new-table/
  26. *
  27. *   API:
  28. *   ----
  29. *
  30. *       - struct FlyHeight extends array
  31. *
  32. *           - static method operator [] takes unit u returns thistype
  33. *               - Returns an instance of the struct given a unit
  34. *
  35. *           - static method setDefault takes integer unitType, real flyHeight returns nothing
  36. *               - When a unit of a certain type enters the map, his height will be set
  37. *                 to a default value input by the user using this function.
  38. *
  39. *           - method operator height takes nothing returns real
  40. *               - Returns the height of a unit
  41. *
  42. *           - method operator height= takes real newHeight returns nothing
  43. *               - Sets the height of a unit
  44. *
  45. *************************************/
  46. library FlyHeight requires UnitIndexer, optional Table
  47.    
  48.     struct FlyHeight extends array
  49.         private static real array h
  50.        
  51.         static if LIBRARY_Table then
  52.             private static key defaultK
  53.             private static Table default = defaultK
  54.         else
  55.             private static hashtable default = InitHashtable()
  56.         endif
  57.        
  58.         method operator height takes nothing returns real
  59.             return h[this]
  60.         endmethod
  61.        
  62.         static method setDefault takes integer unitType, real defaultHeight returns nothing
  63.             static if LIBRARY_Table then
  64.                 set default.real[unitType] = defaultHeight
  65.             else
  66.                 call SaveReal(default, unitType, 0, defaultHeight)
  67.             endif
  68.         endmethod
  69.        
  70.         private static method haveDefault takes integer unitType returns boolean
  71.             static if LIBRARY_Table then
  72.                 return default.real.has(unitType)
  73.             else
  74.                 return HaveSavedReal(default, unitType, 0)
  75.             endif
  76.         endmethod
  77.        
  78.         private static method index takes nothing returns nothing
  79.             local integer unitType = GetUnitTypeId(GetIndexedUnit())
  80.            
  81.             if haveDefault(unitType) then
  82.                 static if not LIBRARY_AutoFly then
  83.                     if UnitAddAbility(GetIndexedUnit(), 'Amrf') then
  84.                         call UnitRemoveAbility(GetIndexedUnit(), 'Amrf')
  85.                     endif
  86.                 endif
  87.                 static if LIBRARY_Table then
  88.                     set h[GetIndexedUnitId()] = default.real[unitType]
  89.                 else
  90.                     set h[GetIndexedUnitId()] = LoadReal(default, unitType, 0)
  91.                 endif
  92.                 call SetUnitFlyHeight(GetIndexedUnit(), h[GetIndexedUnitId()], 0)
  93.             endif
  94.         endmethod
  95.        
  96.         implement UnitIndexStruct
  97.        
  98.         method operator height= takes real newHeight returns nothing
  99.             if h[this] != newHeight then
  100.                 set h[this] = newHeight
  101.                 call SetUnitFlyHeight(this.unit, newHeight, 0)
  102.             endif
  103.         endmethod
  104.     endstruct
  105.    
  106. endlibrary

Demo

Code: jass
  1. struct Demo extends array
  2.     private static method onInit takes nothing returns nothing
  3.         local unit peasant
  4.         local unit hawk
  5.            
  6.         call FlyHeight.setDefault('hpea', 200)
  7.         call FlyHeight.setDefault('hdhw', 150)
  8.            
  9.         set peasant = CreateUnit(Player(0), 'hpea', -256, 0, 270)
  10.         set hawk = CreateUnit(Player(0), 'hdhw', 256, 0, 270)
  11.            
  12.         call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, R2SW(FlyHeight[peasant].height, 5, 1))
  13.         call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, R2SW(FlyHeight[hawk].height, 5, 1))
  14.            
  15.         call TriggerSleepAction(5)
  16.            
  17.         set FlyHeight[peasant].height = 900
  18.         set FlyHeight[hawk].height = 2
  19.            
  20.         call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, R2SW(FlyHeight[peasant].height, 5, 1))
  21.         call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, R2SW(FlyHeight[hawk].height, 5, 1))
  22.            
  23.         set peasant = null
  24.         set hawk = null
  25.     endmethod
  26. endstruct

What do you think? :D
« Last Edit: December 19, 2017, 11:35:19 PM by moyack »



Re: [Snippet] FlyHeight
Reply #1 on: August 09, 2012, 10:21:25 PM

Hmmm, any possiblity of a test map??


Re: [Snippet] FlyHeight
Reply #2 on: August 13, 2012, 07:34:46 PM

Nahh i search for this!! + REPT!!



Re: [Snippet] FlyHeight
Reply #3 on: August 15, 2012, 10:23:46 PM

There we go, I attached a map ^_^

By the way, I am never going to approve my own code snippets because that just isn't right :D



Re: [Snippet] FlyHeight
Reply #4 on: August 15, 2012, 11:11:42 PM

There we go, I attached a map ^_^

By the way, I am never going to approve my own code snippets because that just isn't right :D

And who told you that I'm going to impose that?? That's the reason that I'm here heheeee!!

And approvezorded!!!


Re: [Snippet] FlyHeight
Reply #5 on: August 16, 2012, 03:37:04 AM

But there are any spell's here?? ;) ;)



 

Started by PitzerMike

Replies: 0
Views: 1588
Codes & Snippets

Started by Purgeandfire

Replies: 0
Views: 1672
Codes & Snippets

Started by Bribe

Replies: 0
Views: 1916
Codes & Snippets

Started by moyack

Replies: 0
Views: 9828
Codes & Snippets

Started by Magtheridon96

Replies: 1
Views: 8623
Codes & Snippets
Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...