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

AbilityPreload

moyack · 616

0 Members and 1 Guest are viewing this topic.

Rating

Average Score - 5 / 5

« Created: January 04, 2018, 11:26:25 PM by moyack »

AbilityPreload
on: March 21, 2012, 03:44:14 AM
Category: Execution
Language: vJASS

Requires vJass

This library gives you one new function: call AbilityPreload(abilityid). It will remove the delay the first time an ability is loaded into the game. Vexorian's xe system includes a preload module, but it has not been available as a script until now.

Code: jass
  1. library AbilityPreload
  2. //===========================================================================
  3. // Information:
  4. //==============
  5. //
  6. //      Preloading removes the noticeable delay the first time an ability
  7. //  is loaded in a game. If an ability was not already on a pre-placed unit
  8. //  or a unit that was created during initialization, preloading is needed
  9. //  to prevent a delay.
  10. //
  11. //===========================================================================
  12. // AbilityPreload API:
  13. //=====================
  14. //
  15. //  AbilityPreload(abilityid) :
  16. //        Call this before any time has elapsed to preload a specific
  17. //     ability. If debug mode is enabled, you will see an error message
  18. //     if you call this after initialization, or if you try to preload
  19. //     an ability that does not exist. Will inline to a UnitAddAbility
  20. //     call if debug mode is disabled.
  21. //
  22. //  AbilityRangePreload(start, end) :
  23. //        Same as AbilityPreload, but preloads a range of abilities.
  24. //      It will iterates between the two rawcode values and preload
  25. //      every ability along the way. It will not show an error message
  26. //      for non-existent abilities.
  27. //
  28. //===========================================================================
  29. // Configuration:
  30. //================
  31.  
  32. globals
  33.     private constant integer PreloadUnitRawcode = 'zsmc'
  34.     //This is the rawcode for "Sammy!". It is never used and has no model,
  35.     //which makes an ideal preloading unit. Change it if you want to.
  36. endglobals
  37.  
  38. //===========================================================================
  39.  
  40. globals
  41.     private unit PreloadUnit
  42. endglobals
  43.  
  44. function AbilityPreload takes integer abilityid returns nothing
  45.     static if DEBUG_MODE then
  46.         if GetUnitTypeId(PreloadUnit) == 0 then
  47.             call BJDebugMsg("AbilityPreload error: Can't preload an ability after initialization")
  48.             return
  49.         endif
  50.     endif
  51.     call UnitAddAbility(PreloadUnit, abilityid)
  52.     static if DEBUG_MODE then
  53.         if GetUnitAbilityLevel(PreloadUnit, abilityid) == 0 then
  54.             call BJDebugMsg("AbilityPreload error: Attempted to preload a non-existent ability")
  55.         endif
  56.     endif
  57. endfunction
  58.  
  59. function AbilityRangePreload takes integer start, integer end returns nothing
  60.     local integer i = 1
  61.         static if DEBUG_MODE then
  62.             if GetUnitTypeId(PreloadUnit) == 0 then
  63.                 call BJDebugMsg("AbilityPreload error: Can't preload an ability after initialization")
  64.                 return
  65.             endif
  66.         endif
  67.         if start > end then
  68.             set i = -1
  69.         endif
  70.         loop
  71.             exitwhen start > end
  72.             call UnitAddAbility(PreloadUnit, start)
  73.             set start = start + i
  74.         endloop
  75. endfunction
  76.  
  77. //===========================================================================
  78.  
  79. private struct Init extends array
  80.     private static method onInit takes nothing returns nothing
  81.         set PreloadUnit = CreateUnit(Player(15), PreloadUnitRawcode, 0., 0., 0.)
  82.         call UnitApplyTimedLife(PreloadUnit, 0, .001)
  83.         call ShowUnit(PreloadUnit, false)
  84.         call UnitAddAbility(PreloadUnit, 'Aloc')
  85.     endmethod
  86. endstruct
  87.  
  88. endlibrary
  89.  
  90.  
« Last Edit: January 04, 2018, 11:26:40 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   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)