• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Snippet] Ability Preload

Level 7
Joined
Apr 30, 2011
Messages
359
JASS:
//========================================================================================
//      
//      Ability Preload
//      -*- overcold_ice -*-
//      
//     -[*] Requirements:
//          - JNGP
//          - latest version of JassHelper
//      
//          Simple ability preloading functions
//      
//     -[*] API:
//      
//      function PreloadAbility takes integer abilid returns nothing
//      function PreloadAbilityRange takes integer start, integer end returns nothing
//      
//========================================================================================
library AbilityPreload
    
    globals
        // your dummy unit id
        private constant integer DUMMY_ID     = 'dumy'
        // here if you want to change the preloader unit's position/owner
        private constant unit    PRELOADER    = CreateUnit(Player(15), DUMMY_ID, 0, 0, 0)
    endglobals
    
    //====================================================================================
    //  A P I
    //====================================================================================
    function PreloadAbility takes integer abilid returns nothing
        call UnitAddAbility(PRELOADER, abilid)
        call UnitRemoveAbility(PRELOADER, abilid)
    endfunction
    
    function PreloadAbilityRange takes integer aids, integer aide returns nothing
        local integer i
        
        if aids < aide then
            set i = aids
        else
            set i = aide
        endif
        
        loop
            call UnitAddAbility(PRELOADER, i)
            call UnitRemoveAbility(PRELOADER, i)
            
            exitwhen i == aide
            set i = i + 1
        endloop
    endfunction
    
    module InitM
        static method onInit takes nothing returns nothing
            call ShowUnit(PRELOADER, false)
            call UnitAddAbility(PRELOADER, 'Aloc')
            call UnitAddAbility(PRELOADER, 'Avul')
        endmethod
    endmodule
    
    struct InitS
        implement InitM
    endstruct
endlibrary

can anyone tell me the maximum number of ability id that can be reached?
i want to make a PreloadAbilityAll function . . .
 
Last edited:
xepreload already supports this.

You shouldn't preload "all" abilities because you will quickly reach the operation limit. People have tried to do this before and it's generally not a good idea because it will add a good amount to the initialization process as well.

Instead of this resource, you can also make use of "The Widgetizer" which will convert all object editor data to .slk files, and this makes it get preloaded during the map initialization phase, skipping the need to preload abilities to prevent that first-cast lag.
 
Oh, you wouldn't want to do that, the process would freeze Warcraft III and take several weeks or even months to finish o_O

Tips:
- Struct InitS should extend an array:
struct InitS extends array

- You don't need to add 'Avul' to the unit and you don't need to hide it.
'Aloc' is also not needed (The dummy is expected to have it by default)

- You don't have to make PreloadAbilityRange support (high, low) input, the users have to be careful not to input the data in the wrong order :p

- PreloadAbilityRange crashes the game in some cases because you forgot to do something crucial to the loop: You only have one exitwhen statement that depens on aide which might actually be the lower value.
That's why it's better to have 0-safety in stuff like this :3


By the way, this is what the Preloader from my map looks like:

JASS:
//! zinc

library Preload requires WorldBounds, Player {
    
    module Init {
        private static method onInit() {
            dummy = CreateUnit(Player[15], 'hpea', WorldBounds.maxX, WorldBounds.maxY, 0);
            TimerStart(CreateTimer(), 1, false, function thistype.remove);
        }
    }
    
    public struct Preloader[] {
        private static unit dummy;
        
        public static method ability(integer id) { UnitAddAbility(dummy, id); }
        public static method unit(integer id) { RemoveUnit(CreateUnit(Player[15], id, WorldBounds.maxX, WorldBounds.maxY, 0)); }
        public static method file(string path) { Preload(path); }
        static method remove() { RemoveUnit(dummy); }
        
        module Init;
    }
}

//! endzinc
 
Level 10
Joined
May 27, 2009
Messages
495
then you may combo it with an Optimizer to compress the SLK files

LOL

anyways
I guess, i'm not really using this thing since not all abilities aren't allowed to be preloaded, or maybe bugs if preloaded like the Engineering Upgrade ability (which may cause Fatal Error) if you do so

we'll go for widgetizer
but nice snippet btw, even though there's tons of this thing already
 
Top