Hero Selection Causes Lag

Level 6
Joined
Jul 2, 2008
Messages
156
Hello once again.
I would like to start by saying I've had much success with converting some GUI triggers into JASS, with tons of credit to this forum's help. But, alas, I have a new problem, and for once its not syntax.

My situation: When a player selects a hero in my game, the game freezes briefly for about 2 seconds. I figured the trigger lagged because it was in GUI and using useless BJ's, but after I redid it in JASS, it still has the same lag effect.

I think it may be because I'm adding items to the hero as soon as he is selected, but I'm not entirely sure.

My code:
JASS:
function Trig_Select_Dreadlord_Actions takes nothing returns nothing
    local player p= GetLocalPlayer()
    local integer n= GetPlayerId(p)
    local item i
    set hero[n]= CreateUnit( p, 'U000', 8800, 2400, 275.08 )
    set i= CreateItem( 'I002', GetUnitX(hero[n]), GetUnitY(hero[n]) )
    call UnitAddItem(hero[n], i)
    set i= CreateItem( 'I00P', GetUnitX(hero[n]), GetUnitY(hero[n]) )
    call UnitAddItem(hero[n], i)
    set i= CreateItem( 'I003', GetUnitX(hero[n]), GetUnitY(hero[n]) )
    call UnitAddItem(hero[n], i)
    call MultiboardSetItemIconBJ( udg_Scoreboard, 1, udg_LeaderboardSpotP[GetConvertedPlayerId(GetOwningPlayer(GetEnteringUnit()))], "ReplaceableTextures\\CommandButtons\\BTNHeroDreadLord.blp" )
    if (GetLocalPlayer() == p) then
        call PanCameraTo( GetUnitX(hero[n]), GetUnitY(hero[n]) )
        call ClearSelection()
        call SelectUnit(hero[n], true)
    endif
    if ( p == udg_RulePicker )  then
        call TriggerSleepAction( 1.00 )
        call DialogDisplay( udg_RulePicker, udg_RulesDialogue, true )
    else
    endif
    call RemoveUnit( GetEnteringUnit() )
endfunction

I know its hard to believe it lags.

EDIT: It just occurred to me that one of the items is a spellbook with a ton of spells in it. Anyone know if this could contribute to the lag?

EDIT 2: I commented out the 2 lines regarding the spellbook, and the lag was non existent. So its obvious the problem is the spellbook, any ideas how to get around the lag from picking it up?
 
Level 4
Joined
Apr 16, 2009
Messages
85
EDIT: It just occurred to me that one of the items is a spellbook with a ton of spells in it. Anyone know if this could contribute to the lag?

EDIT 2: I commented out the 2 lines regarding the spellbook, and the lag was non existent. So its obvious the problem is the spellbook, any ideas how to get around the lag from picking it up?

yeah use AbilityPreload (http://www.wc3c.net/showthread.php?t=105279) or xepreload (http://www.wc3c.net/showthread.php?t=101150)

Edit: these functions have to be called on map init and you'll need JNGP o/c

Edit2: if your map got a lot of heroes (so that only a few off all heroes can be choosen at all) you could think about living with that lag because Preloading prolongs the initial loading time and you could save that loadtime/lag altogether if nobody picks that hero
 
Level 6
Joined
Jul 2, 2008
Messages
156
Edit: these functions have to be called on map init and you'll need JNGP o/c

How would I go about calling them on map init?

Edit2: if your map got a lot of heroes (so that only a few off all heroes can be choosen at all) you could think about living with that lag because Preloading prolongs the initial loading time and you could save that loadtime/lag altogether if nobody picks that hero

Well the abilities that cause lag are from a spellbook item that is shared amongst all the heroes, so it sounds like a good idea to load the spells.
 
Level 4
Joined
Apr 16, 2009
Messages
85
How would I go about calling them on map init?

just do something like that

JASS:
scope YourSpell initializer init //initializers are always called at map init
    private function init takes nothing returns nothing
        call XE_PreloadAbility('A000') //your spells here
    endfunction
endscope
 
Top