Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: [Snippet] FlyHeight  (Read 9719 times)

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
[Snippet] FlyHeight
« on: August 05, 2012, 10:08:00 AM »
The documentation has a brief explanation as to why I made this.

Code

Code: jass  [Select]
  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. *           - hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
  20. *
  21. *       Optional:
  22. *       ---------
  23. *
  24. *           - Table by Bribe
  25. *               - hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
  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  [Select]
  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: August 15, 2012, 10:23:07 PM by Magtheridon96 »

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 987
  • WC3 Models: 43
  • WC3 Tutorials: 13
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: [Snippet] FlyHeight
« Reply #1 on: August 09, 2012, 10:21:25 PM »
Hmmm, any possiblity of a test map??

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Rookie - level 3
  • ***
  • Posts: 123
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 3
  • A FRENGERS
    • View Profile
Re: [Snippet] FlyHeight
« Reply #2 on: August 13, 2012, 07:34:46 PM »
Nahh i search for this!! + REPT!!

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
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

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 987
  • WC3 Models: 43
  • WC3 Tutorials: 13
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
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!!!

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Rookie - level 3
  • ***
  • Posts: 123
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 3
  • A FRENGERS
    • View Profile
Re: [Snippet] FlyHeight
« Reply #5 on: August 16, 2012, 03:37:04 AM »
But there are any spell's here?? ;) ;)

 

[Snippet] Group Units in line, with distance and optional spread-value

Started by rvonsonsnadtzBoard Codes & Snippets

Replies: 5
Views: 11935
Last post March 13, 2013, 06:52:16 PM
by rvonsonsnadtz
[Snippet] Single Player Detector

Started by moyackBoard Codes & Snippets

Replies: 12
Views: 21563
Last post March 13, 2013, 12:48:49 PM
by Magtheridon96
[Snippet] Simple Unit Indexer

Started by moyackBoard Codes & Snippets

Replies: 17
Views: 27029
Last post September 30, 2013, 08:07:19 AM
by moyack
[Snippet] Disable Transmission Skip

Started by PurgeandfireBoard Codes & Snippets

Replies: 2
Views: 9005
Last post July 02, 2013, 01:34:55 PM
by Purgeandfire
[Snippet] Timed Effects

Started by moyackBoard Codes & Snippets

Replies: 0
Views: 7770
Last post January 09, 2012, 07:03:32 PM
by moyack
Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!