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:
An example of how to use the script:
Without error messages:
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=039;hfoo039;
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(039;AHds039;) then
call BJDebugMsg(" Divine Shield preloaded successfully")
else
call BJDebugMsg(" Divine Shield preload failure ")
endif
if UnitPreload(039;Hpal039;) 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(039;AHds039;)
call UnitPreload(039;Hpal039;)
//call FlushCustomPreloader() to remove the dummy unit used to preload an ability.
endfunction