HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Reduce the lag?

10-20-2007, 01:08 PM#1
Tiku
Umm so yeah i made a spell that when a missle collides into a unit, its armor is cut in half. and i used the faerie fire ability and a caster to use it, it works fine, but whenever it first collides it has a like 2 second lag spike, then the next time it collides its perfect... i was wondering how to get ride of it...

if i need to post the spell that has the lag i will :D
10-20-2007, 01:19 PM#2
moyack
Ahh!!! first lag issue.... You can solve it by creating a unit at map initialization, add the dummy abilities to that unit, and remove the unit.

If you put the code, I can show you how to do that.
10-20-2007, 01:49 PM#3
Tiku
well heres the code:
Collapse JASS:
constant function arrowpid takes nothing returns integer
    return 'h004'
endfunction

function dmgpsfx takes nothing returns string
    return "Objects\\Spawnmodels\\Naga\\NagaBlood\\NagaBloodWindserpent.mdl"
endfunction

function Trig_Shootp_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A008'
endfunction

function alivep takes nothing returns boolean
    return IsUnitAliveBJ(GetFilterUnit()) == true and IsUnitType(GetFilterUnit(), UNIT_TYPE_ANCIENT) != true
endfunction

function arrowpmove takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t, "hunter")
    local unit arrow = GetHandleUnit(t, "arrow")
    local real face = GetHandleReal(t, "face")
    local real mx = GetUnitX(arrow) + 50*Cos(face*bj_DEGTORAD)
    local real my = GetUnitY(arrow) + 50*Sin(face*bj_DEGTORAD)
    local group g = CreateGroup()
    local boolean hit = false
    local integer dist = GetUnitUserData(arrow)
    local boolexpr check = Condition(function alivep)
    local unit dmg
    local real dmgamm
    local unit caster 
    local integer lvl 
    
    call SetUnitUserData(arrow, dist+50)
    call SetUnitX(arrow, mx)
    call SetUnitY(arrow, my)
    call GroupEnumUnitsInRange(g, mx, my, 75.0, check)
     loop
     set dmg = FirstOfGroup(g)
     exitwhen dmg == null or hit == true
     if dmg != u then
      set lvl = udg_ArcherArmor[GetConvertedPlayerId(GetOwningPlayer(u))]/2
      set dmgamm = udg_ArrowDamage[GetConvertedPlayerId(GetOwningPlayer(u))] + udg_BowStrength[GetConvertedPlayerId(GetOwningPlayer(u))] - 0.01*dist - udg_ArcherArmor[GetConvertedPlayerId(GetOwningPlayer(dmg))] 
      call DestroyEffect(AddSpecialEffectTarget(dmgpsfx(), dmg, "origin"))
      call UnitDamageTarget(u, dmg, dmgamm, true, false, ATTACK_TYPE_PIERCE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
      set caster = CreateUnit(GetOwningPlayer(u), 'h006', mx, my, 0.0)
      call UnitAddAbility(caster, 'A007')
      call SetUnitAbilityLevel(caster, 'A007', lvl)
      call IssueTargetOrder(caster, "faeriefire", dmg)
      set hit = true
     endif
     call GroupRemoveUnit(g, dmg)
     endloop
     if hit == true or dist >= udg_BowRange[GetConvertedPlayerId(GetOwningPlayer(u))] then
      call RemoveUnit(arrow)
      call FlushHandleLocals(t)
      call DestroyGroup(g)
     endif
     
     set u = null
     set arrow = null
     set g = null
     set dmg = null      
endfunction

function Trig_Shootp_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player up = GetOwningPlayer(u)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real face = GetUnitFacing(u)
    local unit arrow = CreateUnit(up, arrowpid(), x, y, face)
    local timer t = CreateTimer()
    
    call SetHandleHandle(t, "arrow", arrow)
    call SetHandleHandle(t, "hunter", u)
    call SetHandleReal(t, "face", face)
    
    call TimerStart(t, 0.035, true, function arrowpmove)

    set u = null
    set up = null
    set arrow = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Shootp takes nothing returns nothing
    set gg_trg_Shootp = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Shootp, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Shootp, Condition( function Trig_Shootp_Conditions ) )
    call TriggerAddAction( gg_trg_Shootp, function Trig_Shootp_Actions )
endfunction


lol yeah im not sure exacly why it lags.. its just a caster ability, and it only lags the first time its used..
10-20-2007, 02:36 PM#4
cohadar
dmgpsfx should be preloaded
10-20-2007, 02:44 PM#5
Tiku
preloading wasnt the problem, it is the caster casting, when i removed that part, it was lagless, and when i add it on, it has a first time lagg :/
lame :P

well moyack i tryied the unit adding ability at map init, but it still first time lagged :(
10-20-2007, 03:36 PM#6
moyack
You did this??
Collapse JASS:
function InitTrig_Shootp takes nothing returns nothing
    // this part is to preload the abilities
    local unit d = CreateUnit(Player(15), 'hpeo', 0,0,0) // creates a unit, in this case a human peasant
    call UnitAddAbility(d, 'A007') // adds the dummy ability
    call RemoveUnit(d) // removes the unit from the game
    set d = null
    call Preload(dmgpsfx()) // preload the effect FX
    // end ability preload
    set gg_trg_Shootp = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Shootp, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Shootp, Condition( function Trig_Shootp_Conditions ) )
    call TriggerAddAction( gg_trg_Shootp, function Trig_Shootp_Actions )
endfunction

BTW, it would be nice to add constant functions with the abilities rawcodes in order to allow easier customization.
10-20-2007, 03:54 PM#7
Tiku
oh no, not that xD i made a new trigger and did the whole thing... xD

but for reason, i implemented the stuff you gave me into the spell, and it still does the lag spike... i dont understand, oh and this happened before with another spell... have any clues what it might be? im pretty sure its the caster part
10-20-2007, 04:29 PM#8
cohadar
As Far as I know Local Handle Vars create gamecache when you first time use them so it might be that.

I don't know why people get exited about first cast lag,
it only happens once and then everybody forget about it...
10-20-2007, 04:30 PM#9
Tiku
hmm well i guess so, but i mean, it can cause someone irritation when they die xD lol w/e i guess