14 years
edited 8 years
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.
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.
1 2 library AbilityPreload3 //===========================================================================4 // Information:5 //==============6 //7 // Preloading removes the noticeable delay the first time an ability8 // is loaded in a game. If an ability was not already on a pre-placed unit9 // or a unit that was created during initialization, preloading is needed10 // to prevent a delay.11 //12 //===========================================================================13 // AbilityPreload API:14 //=====================15 //16 // AbilityPreload(abilityid) :17 // Call this before any time has elapsed to preload a specific18 // ability. If debug mode is enabled, you will see an error message19 // if you call this after initialization, or if you try to preload20 // an ability that does not exist. Will inline to a UnitAddAbility21 // call if debug mode is disabled.22 //23 // AbilityRangePreload(start, end) :24 // Same as AbilityPreload, but preloads a range of abilities.25 // It will iterates between the two rawcode values and preload26 // every ability along the way. It will not show an error message27 // for non-existent abilities.28 // 29 //===========================================================================30 // Configuration:31 //================32 33 globals34 private constant integer PreloadUnitRawcode = 'zsmc'
35 //This is the rawcode for "Sammy!". It is never used and has no model,36 //which makes an ideal preloading unit. Change it if you want to.37 endglobals38 39 //===========================================================================40 41 globals42 private unit PreloadUnit
43 endglobals44 45 function AbilityPreload takes integer abilityid returns nothing
46 static if DEBUG_MODE then
47 if GetUnitTypeId(PreloadUnit) == 0 then
48 call BJDebugMsg("AbilityPreload error: Can't preload an ability after initialization")
49 return50 endif51 endif52 call UnitAddAbility(PreloadUnit, abilityid)
53 static if DEBUG_MODE then
54 if GetUnitAbilityLevel(PreloadUnit, abilityid) == 0 then
55 call BJDebugMsg("AbilityPreload error: Attempted to preload a non-existent ability")
56 endif57 endif58 endfunction59 60 function AbilityRangePreload takes integer start, integer end returns nothing
61 local integer i = 1
62 static if DEBUG_MODE then
63 if GetUnitTypeId(PreloadUnit) == 0 then
64 call BJDebugMsg("AbilityPreload error: Can't preload an ability after initialization")
65 return66 endif67 endif68 if start > end then
69 set i = -1
70 endif71 loop72 exitwhen start > end
73 call UnitAddAbility(PreloadUnit, start)
74 set start = start + i
75 endloop76 endfunction77 78 //===========================================================================79 80 private struct Init extends array
81 private static method onInit takes nothing returns nothing
82 set PreloadUnit = CreateUnit(Player(15), PreloadUnitRawcode, 0., 0., 0.)
83 call UnitApplyTimedLife(PreloadUnit, 0, .001)
84 call ShowUnit(PreloadUnit, false)
85 call UnitAddAbility(PreloadUnit, 'Aloc')
86 endmethod87 endstruct88 89 endlibrary90 91