• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Perload tips?

Status
Not open for further replies.
Level 10
Joined
Aug 19, 2008
Messages
491
Hey dudes! :grin:
Anyone got any tips for preloading a spell?

Currently I'm using these:
JASS:
    function InitTrig_SomeSpell takes nothing returns nothing
        local trigger SomeSpellTrigger = CreateTrigger()
        local integer ForLoop = 0
        local integer ForLoopEnd = 0
        call TriggerRegisterAnyUnitEventBJ( SomeSpellTrigger , EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( SomeSpellTrigger , Condition( function Conditions ) )
        call TriggerAddAction( SomeSpellTrigger , function Actions )

        //Preload
        set ForLoop = 0
        set ForLoopEnd = 11
        loop
            exitwhen ForLoop > ForLoopEnd
            set SomeGlobalIntegerArray[ForLoop] = 0.
            set ForLoop = ForLoop + 1
        endloop

        set SomeGlobalInteger = 0

        set bj_lastCreatedUnit = CreateUnit( Player( PLAYER_NEUTRAL_PASSIVE ), DUMMY_ID, 0., 0., 0. )
        call UnitAddAbility( bj_lastCreatedUnit, spell_id )
        call KillUnit( bj_lastCreatedUnit )
    endfunction

Anyone got anything more? I still notice some lags with certain spells
Cookie to dude with helpful function :thumbs_up:
 
Level 11
Joined
Feb 22, 2006
Messages
752
Get vJASS and use this:


JASS:
library xebasic
//**************************************************************************
//
// xebasic 0.4
// =======
// XE_DUMMY_UNITID : Rawcode of the dummy unit in your map. It should
//                   use the dummy.mdx model, so remember to import it as
//                   well, just use copy&paste to copy the dummy from the
//                   xe map to yours, then change the rawcode.
//
// XE_HEIGHT_ENABLER: Medivh's raven form ability, you may need to change
//                    this rawcode to another spell that morphs into a flier
//                    in case you modified medivh's spell in your map.
//
// XE_TREE_RECOGNITION: The ancients' Eat tree ability, same as with medivh
//                      raven form, you might have to change it.
//
// XE_ANIMATION_PERIOD: The global period of animation used by whatever
//                      timer that depends on it, if you put a low value
//                      the movement will look good but it may hurt your
//                      performance, if instead you use a high value it
//                      will not lag but will be fast.
//
// XE_MAX_COLLISION_SIZE: The maximum unit collision size in your map, if
//                        you got a unit bigger than 197.0 it would be
//                        a good idea to update this constant, since some
//                        enums will not find it. Likewise, if none of
//                        your units can go bellow X and X is much smaller
//                        than 197.0, it would be a good idea to update
//                        as well, since it will improve the performance
//                        those enums.
//
// Notice you probably don't have to update this library, unless I specify
// there are new constants which would be unlikely. 
//
//**************************************************************************

//===========================================================================
globals
   constant integer XE_DUMMY_UNITID       = 'e000'
   constant integer XE_HEIGHT_ENABLER     = 'Amrf'
   constant integer XE_TREE_RECOGNITION   = 'Aeat'
   constant real    XE_ANIMATION_PERIOD   =  0.025
   constant real    XE_MAX_COLLISION_SIZE =  197.0
endglobals

endlibrary

JASS:
library xepreload initializer init requires xebasic
//************************************************************************
// xepreload 0.4
// ---------
// Ah, the joy of preloading abilities, it is such a necessary evil...
// Notice you are not supposed to use this system in places outside map init
//
// This one does the preloading and tries to minimize the hit on loading time
// for example, it only needs one single native call per ability preloaded.
//
//************************************************************************

//===========================================================================================================
    globals
        private unit dum=null
    endglobals

    //inline friendly
    function XE_PreloadAbility takes integer abilid returns nothing
        call UnitAddAbility(dum, abilid)
    endfunction

    private function kill takes nothing returns nothing
        call RemoveUnit(dum)
        set dum=null
        call DestroyTimer(GetExpiredTimer()) //I do hope this doesn't trigger the apocallypse.  I didn't think
                                             // it was a great idea to make this require a whole timer recycling
                                             // system, so, just destroy. Anyone got a better idea on how to make
                                             // this execute after all the other calls at init?
    endfunction

    private function init takes nothing returns nothing
        set dum=CreateUnit(Player(15),XE_DUMMY_UNITID, 0,0,0)
        call TimerStart(CreateTimer(),0.0,false,function kill)
    endfunction




endlibrary
 
Status
Not open for further replies.
Top