Preloading an spell/s

Crusher

You can change this now in User CP.
Reaction score
121
Hi, I have a question, hope you can answer me efficient.

I want to load my spell before the game starts (the map is showing 2 seconds of black mask since it says about credits and all).

Some spells lag on the first cast, so that's the reason of preloading.

How would I make an preload? Any suggestion?
 

Summoned

New Member
Reaction score
51
You can also pre-place one dummy unit with negative health regeneration (so it dies by itself) and put all your dummy spells on it.
 

Viikuna

No Marlo no game.
Reaction score
265
Add all your abilities to one dummy, like that one guy suggested. It preloads those object editor abilities.

Also create and destroy all different special effects in map init, so they dont lagg when first used.

Also, if you use some dummy units for example some triggered projectiles, you should create those units at map init too.
 

Crusher

You can change this now in User CP.
Reaction score
121
And how would I preload this spell?

JASS:
// Version 1.02.
scope FirePillar initializer Init //requires KT, KBS, xefx
globals
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //   OBJECT RAWCODE
    //   UPDATE HERE! CTRL + D
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private constant integer SPELL_ID = 'A00D'
    private constant integer DUMMY_ID = 'e002'
    
    private constant integer BUFF_ID = 'B028'
    
    private constant integer LICH_SFX_ID = 'A00H'
    private constant integer WYRM_SFX_ID = 'A028'
    
    private constant integer STUN_ID = 'A00Z'
    private constant string STUN_STRING = "thunderbolt"
        
    private constant boolean IS_ULTIMATE = true    // - Is this ability ultimate? Target immune.

    
    private constant real TIMER_INTERVAL = 0.03125
    private constant real ROTATE_SPEED = 10.

    private constant attacktype ATK_TYPE = ATTACK_TYPE_NORMAL
    private constant damagetype DMG_TYPE = DAMAGE_TYPE_MAGIC
    private constant weapontype WPN_TYPE = null

    private constant real MAX_HEIGHT = 1000// - Height the pillar will reach.

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //  COSMETICS
    //  If you want to edit the model of the pillar, go to Object Editor Abilities and modify the SFX.
    //  To disable FLASH_SFX or TRIAL_SFX just put " ".
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private constant real PILLAR_SCALE = 1.00   // SCALE of the parts of the pillar
    private constant real TRAIL_SCALE = 1.00    // Scale of the trail.
    private constant string FLASH_SFX = ""//"Abilities\\Weapons\\FrostWyrmMissile\\FrostWyrmMissile.mdx"
    private constant string TRAIL_SFX = ""//"Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdx"
    private constant boolean FREEZE_ANIMATION = true// Enemy units freeze animation when frozen?
    private constant real HEIGHT_VISIBILITY = 1100  // Cannot see usually above here.
                                                    // Units won't be created if height > this.
endglobals

private function SPELL_AOE takes integer level returns real
    return 350. + ( level * 0. )
endfunction

private function SPELL_DURATION takes integer level returns real
    return 2. + ( level * 0. )
endfunction

// Distance of the knockback? Add levels as necessary, level being in [x]
private function SPELL_KB_DISTANCE takes integer level returns real
    return 250. * level
endfunction

private function SPELL_DAMAGE takes integer level returns real
    return 250. * level
endfunction

/*------------------------------------------------------------
    !!! <>< FISHY TRIAL ><> !!! Fish Pillar begins here.
-------------------------------------------------------------*/
globals
    private constant group Group = CreateGroup() // For instant enum. NO DYNAMIC-STABILITY! ??? lolwut.

    private unit DUMMY_CASTER   // Have 1 dummy unit cast all Storm Bolts.
    
    // Unit Filtering.
    private boolexpr G_UFilter = null   // Save 1 call.
    private unit TempUnit     = null    // Save a fe calls.
    private player TempPlayer = null    // Passing.
    private integer TempInt = 0

    private unit TempCaster = null
    private real KBDist
    private real Damage
    private real TempX
    private real TempY
    private boolean array BA
endglobals

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                          ANIMATION FREEZING
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private struct BFData
    unit Target

    static method create takes unit u returns BFData
        local BFData d = BFData.allocate()
        
        set d.Target = u
        
        return d
    endmethod
    
    method onDestroy takes nothing returns nothing
        call SetUnitTimeScale( .Target, 1.00 )
    endmethod
    
    static method Update takes nothing returns boolean
        local BFData d  = KT_GetData()
        
        call SetUnitTimeScale( d.Target, 0 )
        // If they somehow lose the bugg, or they become magic immune and the spell is not an ultimate, or they die.
        if (GetUnitAbilityLevel( d.Target, BUFF_ID ) == 0) or (IsUnitType( d.Target, UNIT_TYPE_MAGIC_IMMUNE ) and not IS_ULTIMATE ) /*
        */ or ( IsUnitType( d.Target, UNIT_TYPE_DEAD )) then
            call d.destroy()
            return true
        endif
    
        return false
    endmethod
endstruct

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                          I C E  P I L L A R
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private function Destroy_trees takes nothing returns nothing
    call KillDestructable(GetEnumDestructable()) // Used to destroy destructables.
endfunction

// Thanks to PitzerMike for this function. (Modified Slightly).
private function Check_trees takes nothing returns boolean
    local destructable dest   = GetFilterDestructable()
    local boolean      result = false
    
    if GetDestructableLife(dest) > 0.405 then
        call ShowUnit(DUMMY_CASTER,true)
        call SetUnitX(DUMMY_CASTER,GetWidgetX(dest))
        call SetUnitY(DUMMY_CASTER,GetWidgetY(dest))
        
        set result = IssueTargetOrder(DUMMY_CASTER,"harvest",dest)
        call IssueImmediateOrder(DUMMY_CASTER,"stop")
        call ShowUnit(DUMMY_CASTER,false)
        
        set dest = null
        return result
    endif
    
    set dest = null
    return result
endfunction

private struct IPData
    unit Caster

    
    player Owner
    real TX
    real TY
    
    real Height = 0.00
    integer Counter = 0

    integer LevelX
    
    real AoE
    real angle = 0
    real SECONDS = 0.00
    real Damage
    real HeightModifier
    real Duration
    
    real a2n = 0
    
    group IcePillar = CreateGroup()
    
    xefx fx

    static method UFilter takes nothing returns boolean
        local real angle = 0.00
        local boolean b
        set TempUnit = GetFilterUnit()

        if IsUnitEnemy( TempUnit, TempPlayer ) and not IsUnitType( TempUnit, UNIT_TYPE_DEAD ) then
            call SetUnitAbilityLevel( DUMMY_CASTER, STUN_ID, TempInt )
            call SetUnitPosition( DUMMY_CASTER, TempX , TempX )
            call SetUnitOwner( DUMMY_CASTER, TempPlayer, false )
            
            // If this spell is not an ultimate, and the target is a magic immune, yes, let them be hurt.
            if IsUnitType( TempUnit, UNIT_TYPE_MAGIC_IMMUNE ) and not IS_ULTIMATE then
                debug call BJDebugMsg ("THIS SPELL IS NOT AN ULTIMATE, DOES NOT HURT " + GetUnitName( TempUnit ) )
                return false
            endif
            
                set angle = Atan2( GetUnitY( TempUnit ) - TempY, GetUnitX( TempUnit ) - TempX  ) * bj_RADTODEG

                call UnitDamageTarget( TempCaster, TempUnit, Damage, true, false, ATK_TYPE, DMG_TYPE, WPN_TYPE )
                set b = IssueTargetOrder( DUMMY_CASTER, STUN_STRING, TempUnit )

                call KBS_BeginCommon( TempUnit, KBDist,.8,angle) 
                if FREEZE_ANIMATION then
                    call KT_Add( function BFData.Update, BFData.create( TempUnit ), TIMER_INTERVAL )
                endif
                if not b then
                    debug call BJDebugMsg( &quot;Target cannot be stunned <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown    :(" loading="lazy" data-shortname=":(" />&quot;)
                endif
        endif

        return false
    endmethod
    


     method onDestroy takes nothing returns nothing
        local unit u
        local real angle
        local BFData d
        local real x = .TX
        local real y = .TY

        // Initial dummy death.
        loop
            set u = FirstOfGroup( .IcePillar )
            exitwhen u == null
            call GroupRemoveUnit( .IcePillar, u )
            call UnitRemoveAbility( u, LICH_SFX_ID )
        
            call UnitAddAbility( u, WYRM_SFX_ID )
            call UnitRemoveAbility( u, WYRM_SFX_ID )
            call KillUnit( u )
            set u = null
        endloop
        
 
        call EnumDestructablesInRect( Rect( x - .AoE, y - .AoE, x + .AoE, y + .AoE ), Condition( function Check_trees), function Destroy_trees )
        call SetWidgetLife( GetEnumDestructable(), 0 )
        
        set TempX = .TX
        set TempY = .TY
        set TempPlayer = .Owner
        set TempInt = .LevelX
        set TempCaster = .Caster
        set Damage = SPELL_DAMAGE( .LevelX )
        debug call BJDebugMsg( &quot;Damage: &quot; + R2S( Damage ) )
        set KBDist = SPELL_KB_DISTANCE( .LevelX )
        call GroupEnumUnitsInRange( Group, .TX, .TY, .AoE, G_UFilter )        
        call GroupClear( .IcePillar )
        call .fx.destroy()
    endmethod
    
    static method create takes nothing returns IPData
        local IPData d = IPData.allocate()
                
        set d.Caster = GetTriggerUnit()
        set d.Owner = GetOwningPlayer( d.Caster )
        set d.TX = GetSpellTargetX()
        set d.TY = GetSpellTargetY()
        
        set d.LevelX = GetUnitAbilityLevel( d.Caster, SPELL_ID )
        set d.AoE = SPELL_AOE( d.LevelX )
        set d.Duration = SPELL_DURATION( d.LevelX )
        set d.HeightModifier = MAX_HEIGHT / ( d.Duration / TIMER_INTERVAL )
        set d.a2n = 90
        debug call BJDebugMsg( &quot;LevelX: &quot; + R2S( d.LevelX ) )
        debug call BJDebugMsg( &quot;AoE: &quot; + R2S( d.AoE ) )
        debug call BJDebugMsg( &quot;Duration: &quot; + R2S( d.Duration ) )

        set d.fx = xefx.create( d.TX, d.TY, bj_UNIT_FACING )
        set d.fx.fxpath = TRAIL_SFX
        set d.fx.scale = TRAIL_SCALE
        
        return d
    endmethod
endstruct

    private function Callback takes nothing returns boolean
        local IPData d = KT_GetData()
        local integer i = 0
        local real x
        local real y
        local real angle = 0
        local unit u = null
        
        set d.SECONDS = d.SECONDS + TIMER_INTERVAL
        set d.angle = d.angle + ROTATE_SPEED
        set d.Height = d.Counter * d.HeightModifier
        
        //set d.ZANGLE = d.ZANGLE - 7
        //if d.ZANGLE &lt; -360 then
            //set d.ZANGLE = d.ZANGLE + 360
        //endif

            set x = d.TX + d.AoE * Cos( d.angle * bj_DEGTORAD )
            set y = d.TY + d.AoE * Sin( d.angle * bj_DEGTORAD )
            call d.fx.flash( FLASH_SFX )
            set d.a2n = d.a2n + ROTATE_SPEED
            if d.Height &lt; HEIGHT_VISIBILITY then
                set u = CreateUnit( d.Owner, DUMMY_ID, x, y, d.a2n )
                call SetUnitFlyHeight( u, d.Height, 0 )
                call GroupAddUnit( d.IcePillar, u )
                call SetUnitScale( u, PILLAR_SCALE,PILLAR_SCALE,PILLAR_SCALE)
                
                set d.fx.x=x
                set d.fx.y=y
                set d.fx.z=d.Height

                // NORMAL PILLAR
                set u = CreateUnit( d.Owner, DUMMY_ID, d.TX, d.TY, bj_UNIT_FACING )
                call SetUnitFlyHeight( u, d.Height, 0 )
                call GroupAddUnit( d.IcePillar, u )
            endif
        set d.Counter = d.Counter + 1
        set u = null
        if d.SECONDS &gt;= d.Duration then
            call d.destroy()
            return true
        endif
        return false
    endfunction
    
    private function Cond takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction

    private function Actions takes nothing returns nothing
        call KT_Add( function Callback, IPData.create(), TIMER_INTERVAL )
    endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Cond ) )
    call TriggerAddAction( t, function Actions )
    
    set G_UFilter = Condition( function IPData.UFilter )
    
    set DUMMY_CASTER = CreateUnit( Player(12), DUMMY_ID, 0, 0, bj_UNIT_FACING )
    call UnitRemoveAbility( DUMMY_CASTER, &#039;Amov&#039; )
    call UnitRemoveAbility( DUMMY_CASTER, LICH_SFX_ID )
    call UnitAddAbility( DUMMY_CASTER, STUN_ID )
endfunction

endscope
 

Viikuna

No Marlo no game.
Reaction score
265
Well, it works unless your spell does something that you dont really wanna do during that black mask time.

Just use your imagination and you can think plenty of examples.
 

Crusher

You can change this now in User CP.
Reaction score
121
Well, it works unless your spell does something that you dont really wanna do during that black mask time.

Just use your imagination and you can think plenty of examples.

Okay, everything is almost fixed, except this 'small' thing:

Trigger:
  • Champion Mark
    • Events
      • Unit - A unit Gains a level
    • Conditions
      • (Level of (Leveling Hero)) Equal to 21
    • Actions
      • Set TempUnitType = (Unit-type of (Leveling Hero))
      • Game - Display to (All players) for 12.00 seconds the text: (PlayerColourNames[(Player number of (Owner of (Leveling Hero)))] + has just reached level 21!)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • TempUnitType Equal to |c00ff0000Holy Warrior|r
              • TempUnitType Equal to |c00ff0000Mountain King|r
              • TempUnitType Equal to Corher
              • TempUnitType Equal to |c00ff0000Cursed Knight|r
              • TempUnitType Equal to |c0000ff00Vampire|r
              • TempUnitType Equal to |c00ff0000Beastmaster|r
              • TempUnitType Equal to |c00ff0000Pit Lord|r
              • TempUnitType Equal to |c00ff0000Cow King|r
              • TempUnitType Equal to |c00ff0000Berserker|r
        • Then - Actions
          • Unit - Add Champion of Strength to (Leveling Hero)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • TempUnitType Equal to |c000080ffWizard|r
                  • TempUnitType Equal to |c000080ffArcane Apprentice|r
                  • TempUnitType Equal to |c000080ffNecromancer|r
                  • TempUnitType Equal to |c000080ffWitch|r
                  • TempUnitType Equal to |c000080ffLightning Spirit|r
            • Then - Actions
              • Unit - Add Champion of Intelligence to (Leveling Hero)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • TempUnitType Equal to |c0000ff00Night Elf Blademaster|r
                      • TempUnitType Equal to |c0000ff00Moon Ranger|r
                      • TempUnitType Equal to |c0000ff00Light Ranger|r
                      • TempUnitType Equal to |c0000ff00Dark Rogue|r
                      • TempUnitType Equal to |c0000ff00Deadeye|r
                      • TempUnitType Equal to |c0000ff00Tremble Lord|r
                • Then - Actions
                  • Unit - Add Champion of Agility to (Leveling Hero)
                • Else - Actions


Is there any way to preload this? It lags when heroes gain level 21 because it addds a spellbook when max. level acomplished.
 
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