Blizzard Modding Network

Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chaos Arena - A Warcraft III mod
Check all that happens in this network through BLIZZARD MODDING.INFO

* Announcements!!

  • We're now at wc3 top 200 lists. Please vote for us.
  • WC3jass.com has a new theme, very similar to the original but lighter to load. If you have any suggestions or comments about it, just post it here.
  • We are getting more social!!! Visit the new social group section and create your own group with your friends

Jass New Gen Pack

Download Jass New Generation Pack (JNGP) to use all the vJASS & Zinc scripts posted in any of the Blizzardmodding sites.

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

Offline Magtheridon96

  • Awesome Global Code Moderator
  • Code Director
  • Rookie - level 2
  • *
  • Posts: 81
  • Reputation: 515
  • vJass Incarnate
  • Referrals: 0
    • View Profile
    • Awards
[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
  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
  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 »

Online moyack

  • Site Owner
  • Administrator
  • Frequent - level 2
  • *
  • Posts: 1707
  • Reputation: 1144
  • Site Admin - I love fix things
  • Referrals: 0
    • View Profile
    • Blizzard Modding Information Center
    • Awards
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. Not only a forum, a complete page!!.

A custom altered melee map where you can play Naga and Demons. Featuring a nice additions in features and game style. Check it out!!

Offline LembidiZ

  • Rookie - level 1
  • *
  • Posts: 67
  • Reputation: 2
  • A FRENGERS
  • Referrals: 0
    • View Profile
    • Awards
Re: [Snippet] FlyHeight
« Reply #2 on: August 13, 2012, 07:34:46 PM »
Nahh i search for this!! + REPT!!

Offline Magtheridon96

  • Awesome Global Code Moderator
  • Code Director
  • Rookie - level 2
  • *
  • Posts: 81
  • Reputation: 515
  • vJass Incarnate
  • Referrals: 0
    • View Profile
    • Awards
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

Online moyack

  • Site Owner
  • Administrator
  • Frequent - level 2
  • *
  • Posts: 1707
  • Reputation: 1144
  • Site Admin - I love fix things
  • Referrals: 0
    • View Profile
    • Blizzard Modding Information Center
    • Awards
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. Not only a forum, a complete page!!.

A custom altered melee map where you can play Naga and Demons. Featuring a nice additions in features and game style. Check it out!!

Offline LembidiZ

  • Rookie - level 1
  • *
  • Posts: 67
  • Reputation: 2
  • A FRENGERS
  • Referrals: 0
    • View Profile
    • Awards
Re: [Snippet] FlyHeight
« Reply #5 on: August 16, 2012, 03:37:04 AM »
But there are any spell's here?? ;) ;)

Tags:
 

[Snippet] Timed Effects

Started by moyack

Replies: 0
Views: 884
Last post January 09, 2012, 07:03:32 PM
by moyack
[Snippet] StringIndexer

Started by Magtheridon96

Replies: 1
Views: 1089
Last post September 02, 2012, 11:51:03 AM
by moyack
[Snippet] AddSpecialEffectZ

Started by Purgeandfire

Replies: 4
Views: 2138
Last post August 14, 2012, 12:06:10 AM
by LembidiZ
[Snippet] Parabolic Function

Started by moyack

Replies: 1
Views: 857
Last post January 13, 2012, 12:11:45 PM
by Magtheridon96
[Snippet] RegisterAnyUnitEvent

Started by moyack

Replies: 2
Views: 937
Last post February 12, 2012, 09:20:29 PM
by moyack
  UDMod Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Vote for Blizzmod at Warcraft 3 Top 200 - Cheats Free Clans and Resources