Snippet Ability Preloader Library

chobibo

Level 1 Crypt Lord
Reaction score
48
Custom Preloader Library

Since the old one was uselss, I've updated the old script so that it's not just an ability preloader but it can now also preload units. I would like to clarify that you use this during Map Initialization, not when the game has already started. I hope it's clear to all, now here is the script:
JASS:
//========================================================================================
//  *** SCRIPT ***
// Custom Preloader v1.00 by Chobibo
//
//  Description: A Script that preloads a dummy ability or unit,
//      during Map Initialization. 
//      Dummy units and abilities are preloaded during Map Ini-
//      tialization to prevent the first use lag.
//
//  Requires: Jass NewGen pack's vJass
//
//  Implementation instructions: Create a new trigger and convert
//      it to custom text, then copy and paste this script.
//
//  How to use:
//
//      Configuration:
//
//      -- Coordinates: You can specify where to create the Dummy
//      unit by changing X and Y values.
//
//      Library Function:
//
//      To Preload an Ability
//      -- call AbilityPreload('AHds') returns boolean
//
//      To Preload a Unit
//      -- call UnitPreload('Hpal') returns boolean
//
//      To Remove the UNIT preloader used in abilities
//      -- call FlushCustomPreloader() 
//      remember to only use it once, it will be executed
//      after Map Initialization.
//
//      *Use this during Map Initialization
//      Example:
//      
//      function InitTrig_Test takes nothing returns nothing
//          local trigger t=CreateTrigger()
//          // do stuff
//          call UnitPreload(DummyId)
//          call AbilityPreload(DummyAbilityId)
//          call FlushCustomPreloader()
//      endfunction
//========================================================================================

library CustomPreloader
globals
    private unit UNIT=null
    
    private constant integer ID='hfoo'
    private constant real X    =0
    private constant real Y    =0
endglobals

function AbilityPreload takes integer abilId returns boolean
    local boolean b
    if UNIT==null then
        set UNIT=CreateUnit(Player(15), ID, X, Y, 0)
        call ShowUnit(UNIT, false)
    endif
    set b=UnitAddAbility(UNIT, abilId)
    call UnitRemoveAbility(UNIT, abilId)
    return b
endfunction

function UnitPreload takes integer unitId returns boolean
    local unit who=CreateUnit(Player(15), unitId, X, Y, 0)
    local integer n=GetUnitTypeId(who)
    call ShowUnit(who, false)
    call KillUnit(who)
    call RemoveUnit(who)
    set who=null
    return n!=0
endfunction

function FlushCustomPreloader takes nothing returns nothing
    local timer t=GetExpiredTimer()
    if t==null then
        call TimerStart(CreateTimer(), 0., false, function FlushCustomPreloader)
    else
        call KillUnit(UNIT)
        call RemoveUnit(UNIT)
        set UNIT=null
        call DestroyTimer(t)
        debug call BJDebugMsg(" Cleanup done. ")
    endif
    set t=null
endfunction
endlibrary


An example of how to use the script:
JASS:
function InitTrig_Sample takes nothing returns nothing
    set gg_trg_Sample = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Sample, function Trig_Sample_Actions )
    
    if AbilityPreload('AHds') then
        call BJDebugMsg(" Divine Shield preloaded successfully")
    else
        call BJDebugMsg(" Divine Shield preload failure ")
    endif
    
    if UnitPreload('Hpal') then
        call BJDebugMsg(" Paladin preloaded successfully")
    else
        call BJDebugMsg(" Paladin preload failure ")
    endif
    //call FlushCustomPreloader() to remove the dummy unit used to preload an ability.
endfunction


Without error messages:
JASS:
function InitTrig_Sample takes nothing returns nothing
    set gg_trg_Sample = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Sample, function Trig_Sample_Actions )
    
    call AbilityPreload('AHds')
    call UnitPreload('Hpal')
    //call FlushCustomPreloader() to remove the dummy unit used to preload an ability.
endfunction
 

Hatebreeder

So many apples
Reaction score
381
Can you also use this in Map Init?
SInce it is just plain stupid to preload abilities in-Game..
 

chobibo

Level 1 Crypt Lord
Reaction score
48
Yes you're supposed to use it during Map Initialization, I just added a configuration to make it usable after Map Initialization becuase someone might want to use it after initialization.

UPDATED the Snippet
 

Trollvottel

never aging title
Reaction score
262
magentix made a wonderful preloading system which preloaded everything automatically, so why use this?
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
> --> Got sent to the graveyard

NOOOOOOOOOOOOOOOOO! Why? I'm gonna support it to go in the systems' index! It really helped me alot with my maps!

EDIT:
In this snippet I have to add my spells/units one by one, just like AMHS?! I find Magentix' preloader hundred times useful than this (if it works that way I mean). ^^
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top