JASS help - Converting to native

B

Beider

Guest
Code:
function Trig_Deadly_Fire_Star_Effect_Actions takes nothing returns nothing
    local location LocalPointVariable=udg_PointVar
    local effect LocalTempEffect
    call TriggerSleepAction( GetRandomReal(0, 3.00) )
    // wait random delay (another trigger is another thread)
    call AddSpecialEffectLocBJ( LocalPointVariable, "Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeEmbers.mdl" )
    set LocalTempEffect = GetLastCreatedEffectBJ()

    call TriggerSleepAction( 10.00 )
    call RemoveLocation( LocalPointVariable )
    call DestroyEffect( LocalTempEffect )
    // Remove the point so it doesn't leak
    set LocalPointVariable = null
    set LocalTempEffect = null
    // Local variables leak if you don't set them to null
endfunction

//===========================================================================
function InitTrig_Deadly_Fire_Star_Effect takes nothing returns nothing
    set gg_trg_Deadly_Fire_Star_Effect = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Deadly_Fire_Star_Effect, function Trig_Deadly_Fire_Star_Effect_Actions )
endfunction


I read that using native functions instead of BJ functions is faster. I tried to convert it to use natives instead of the two BJ functions it uses now but I had no luck with it. The problem is when I make my effect everyone in the game DC even if they can't see it, but it single it works fine. (It creates 65 effects in less than 5 sec ^^) I was hoping converting to native functions might help.
 

SFilip

Gone but not forgotten
Reaction score
634
we have a jass help zone you know ;)
anyway i dont see anything wrong here. however since you mentioned that you create 65 special effects...that could really be the problem. you are removing them after 10 seconds which is long enough to leak lots of memory (enough for a server split perhaps).
and replacing bj functions is a good idea, but you probably wont even notice the diffrence.
 
B

Beider

Guest
well actually i just tried it with that function and it worked ok in a game with 65 effects. What used to disconnect was when i used vexorian for it.
 

SFilip

Gone but not forgotten
Reaction score
634
you mean his map optimizer? what options did you use?
 
B

Beider

Guest
no i mean his casting system. I used his default example for a firestar in his map. Everyone disconnected. So I converted it into just using effects and removing them and now some people just lagg.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Code:
function Trig_Deadly_Fire_Star_Effect_Actions takes nothing returns nothing
    local location LocalPointVariable=udg_PointVar
    local effect LocalTempEffect
    call PolledWait( GetRandomReal(0, 3.00) )
    // wait random delay (another trigger is another thread)
    set LocalTempEffect = AddSpecialEffectLoc( "Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeEmbers.mdl", LocalPointVariable )

    call PolledWait( 10.00 )
    call RemoveLocation( LocalPointVariable )
    call DestroyEffect( LocalTempEffect )
    // Remove the point so it doesn't leak
    set LocalPointVariable = null
    set LocalTempEffect = null
    // Local variables leak if you don't set them to null
endfunction

//======================================================================  =====
function InitTrig_Deadly_Fire_Star_Effect takes nothing returns nothing
    set gg_trg_Deadly_Fire_Star_Effect = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Deadly_Fire_Star_Effect, function Trig_Deadly_Fire_Star_Effect_Actions )
endfunction

The only thing that isn't native there is PolledWait, however PolledWait is better to use if you have lagg problems with the function.
The best solution to this is to not create so many effects at the same time.
 
B

Beider

Guest
Ok thanks for the help. I will try the function you posted now and also try to piff up the loop that initiate these spell effects. Hopefully it will speed up slightly more, and yeah i guess if this doesn't work i will reduce the amount of effects again.


Anyone know how many effects one maximum should use for a spell, to avoid for lagg i mean. I guess 65 is a bit much, but 30-40 should be fine?
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
There is always someone with 56k, 128MB ram and integrated gcard that is going to lag as soon there is one effect on the screen. Actually it's more important to choose the right effects, fire effects are laggy. Most projectiles are not so laggy.

Also, don't use alot of effects just to make the ability 'look cool', lagg isn't very funny. If you want a 'cool' ability on each hero make sure that it's only one on each hero and also make it the ultimate so it won't be cast as often as the others.

I think the most effects I ever had on a triggered spell was 1 per unit in an area + one earthquake effect. That was not very often above 15 effects in total.
 
B

Beider

Guest
Well it's an hero ultimate, and all effects are fire effects :p

But still, people used to disconnect even if they couldn't see the effect so it wasn't because of graphics being to laggy. Well i optimized it as much as i could myself so will test it.


If anyone is interested here is the code for the effect.

Code:
function Trig_Infernal_Nuke_org_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A016' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Infernal_Nuke_org_Func006C takes nothing returns boolean
    if ( not ( GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetTriggerUnit()) == 2 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Infernal_Nuke_org_Func014Func002C takes nothing returns boolean
    if ( not ( ModuloInteger(GetForLoopIndexA(), 24) == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Infernal_Nuke_org_Func015Func002C takes nothing returns boolean
    if ( not ( ModuloInteger(GetForLoopIndexA(), 24) == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Infernal_Nuke_org_Func015Func003C takes nothing returns boolean
    if ( not ( ModuloInteger(GetForLoopIndexA(), 72) == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Infernal_Nuke_org_Actions takes nothing returns nothing
    local location LocalPointVariable=GetUnitLoc(GetTriggerUnit())
    call PauseUnitBJ( true, GetTriggerUnit() )
    call CreateNUnitsAtLoc( 1, 'h00B', GetTriggerPlayer(), GetUnitLoc(GetTriggerUnit()), bj_UNIT_FACING )
    call UnitApplyTimedLifeBJ( 5.00, 'BTLF', GetLastCreatedUnit() )
    call UnitAddAbilityBJ( 'A007', GetLastCreatedUnit() )
    if ( Trig_Infernal_Nuke_org_Func006C() ) then
        call SetUnitAbilityLevelSwapped( 'A007', GetLastCreatedUnit(), 2 )
        set udg_RealVar = 1200.00
    else
        set udg_RealVar = 800.00
    endif
    call IssuePointOrderLocBJ( GetLastCreatedUnit(), "flamestrike", GetUnitLoc(GetTriggerUnit()) )
    call PlaySoundAtPointBJ( gg_snd_FlameStrikeBirth1, 100, GetUnitLoc(GetTriggerUnit()), 0 )
    call TriggerSleepAction( 1.00 )
    // RealVar determines the area of effect
    set udg_RealVar2 = 20.00
    // RealVar2 determines the area damage
    set udg_PointVar = OffsetLocation(LocalPointVariable, -50.00, -100.00)
    set bj_forLoopAIndex = -360
    set bj_forLoopAIndexEnd = -1
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        // For is Negative so the star appars inverted
        if ( Trig_Infernal_Nuke_org_Func014Func002C() ) then
            set udg_PointVar = PolarProjectionBJ(OffsetLocation(LocalPointVariable, -50.00, -100.00), ( udg_RealVar / 2.00 ), I2R(GetForLoopIndexA()))
            call ConditionalTriggerExecute( gg_trg_Deadly_Fire_Star_Effect2 )
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = -360
    set bj_forLoopAIndexEnd = -1
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        // For is Negative so the star appars inverted
        if ( Trig_Infernal_Nuke_org_Func015Func002C() ) then
            set udg_PointVar = PolarProjectionBJ(OffsetLocation(LocalPointVariable, -50.00, -100.00), ( udg_RealVar / 2.00 ), I2R(GetForLoopIndexA()))
            call ConditionalTriggerExecute( gg_trg_Deadly_Fire_Star_Effect )
        else
        endif
        if ( Trig_Infernal_Nuke_org_Func015Func003C() ) then
            set udg_PointVar2 = PolarProjectionBJ(OffsetLocation(LocalPointVariable, -50.00, -100.00), ( udg_RealVar / 2.00 ), I2R(GetForLoopIndexA()))
            set bj_forLoopBIndex = 1
            set bj_forLoopBIndexEnd = 7
            loop
                exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                set udg_PointVar = PolarProjectionBJ(udg_PointVar2, ( I2R(GetForLoopIndexB()) * ( udg_RealVar / 8.00 ) ), ( I2R(GetForLoopIndexA()) + 162.00 ))
                call ConditionalTriggerExecute( gg_trg_Deadly_Fire_Star_Effect )
                set bj_forLoopBIndex = bj_forLoopBIndex + 1
            endloop
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call TriggerSleepAction( 1.80 )
    call PauseUnitBJ( false, GetTriggerUnit() )
    call RemoveLocation( LocalPointVariable )
    set LocalPointVariable = null
endfunction

//===========================================================================
function InitTrig_Infernal_Nuke_org takes nothing returns nothing
    set gg_trg_Infernal_Nuke_org = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Infernal_Nuke_org, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Infernal_Nuke_org, Condition( function Trig_Infernal_Nuke_org_Conditions ) )
    call TriggerAddAction( gg_trg_Infernal_Nuke_org, function Trig_Infernal_Nuke_org_Actions )
endfunction


And here are the two spell effect functions.

Code:
function Trig_Deadly_Fire_Star_Effect_Actions takes nothing returns nothing
    local location LocalPointVariable=udg_PointVar
    // To make the fire star appearance faster, I made it so there is a random delay,
    // each part of the star will have its own moment to appear,
    local effect LocalTempEffect
    call PolledWait( GetRandomReal(0, 3.00) )
    // wait random delay (another trigger is another thread)
    set LocalTempEffect = AddSpecialEffectLoc( "Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeEmbers.mdl", LocalPointVariable )
    call PolledWait( 10.00 )
    call RemoveLocation( LocalPointVariable )
    call DestroyEffect( LocalTempEffect )
    // Remove the point so it doesn't leak
    set LocalPointVariable = null
    set LocalTempEffect = null
    // Local variables leak if you don't set them to null
endfunction

//===========================================================================
function InitTrig_Deadly_Fire_Star_Effect takes nothing returns nothing
    set gg_trg_Deadly_Fire_Star_Effect = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Deadly_Fire_Star_Effect, function Trig_Deadly_Fire_Star_Effect_Actions )
endfunction


Code:
function Trig_Deadly_Fire_Star_Effect2_Actions takes nothing returns nothing
    local location LocalPointVariable=udg_PointVar
    // To make the fire star appearance faster, I made it so there is a random delay,
    // each part of the star will have its own moment to appear,
    local effect LocalTempEffect
    call PolledWait( GetRandomReal(0, 1.00) )
    // wait random delay (another trigger is another thread)
    set LocalTempEffect = AddSpecialEffectLoc( "Objects\\Spawnmodels\\Human\\SmallFlameSpawn\\SmallFlameSpawn.mdl", LocalPointVariable )
    call PolledWait( 10.00 )
    call RemoveLocation( LocalPointVariable )
    call DestroyEffect( LocalTempEffect )
    // Remove the point so it doesn't leak
    set LocalPointVariable = null
    set LocalTempEffect = null
    // Local variables leak if you don't set them to null
endfunction

//===========================================================================
function InitTrig_Deadly_Fire_Star_Effect2 takes nothing returns nothing
    set gg_trg_Deadly_Fire_Star_Effect2 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Deadly_Fire_Star_Effect2, function Trig_Deadly_Fire_Star_Effect2_Actions )
endfunction
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Beider said:
But still, people used to disconnect even if they couldn't see the effect so it wasn't because of graphics being to laggy.
That is probably because the TriggerSleepAction, it can cause desyncs if a player laggs. Well, someone told me that once. I have never encountered it myself, mainly because I almost never uses TriggerSleepAction.

Here is 2 things that will help you optimize that alot more
http://www.thehelper.net/forums/showthread.php?t=28321
http://www.thehelper.net/forums/showthread.php?t=28217
 
B

Beider

Guest
well i decided to just strip out the burning pentagram on the ground. Even though it looked awesome it used 50 fire effects ^^

So now it's just the first loop and 15 fire effects and it works quite well. At least I don't think anyone disconnect or lagg from it anymore.

Thanks for all the help.
 

Vexorian

Why no custom sig?
Reaction score
187
Code:
set udg_PointVar = PolarProjectionBJ(OffsetLocation(LocalPointVariable, -50.00, -100.00), ( udg_RealVar / 2.00 ), I2R(GetForLoopIndexA()))
...
set udg_PointVar2 = PolarProjectionBJ(OffsetLocation(LocalPointVariable, -50.00, -100.00), ( udg_RealVar / 2.00 ), I2R(GetForLoopIndexA()))
...
set udg_PointVar = PolarProjectionBJ(udg_PointVar2, ( I2R(GetForLoopIndexB()) * ( udg_RealVar / 8.00 ) ), ( I2R(GetForLoopIndexA()) + 162.00 ))

those 3 memory leaks happen in very periodic parts of the spell, so just using it once would eat all the memory.

- The caster system map's samples are not meant to be actually used.
- I only made the pentagram because in those times the only spells that got into the top downloads in wc3search were pentagram spells.

You have to be crazy to use the pentagram spell in multiplayer
 
B

Beider

Guest
Well I did remove over half the effects the original used, but well, never made a spell before so didn't know how many effects you could have. And the pentagram fit the theme of the map / hero very well, but oh well.

At least I learned something about jass and spell making ^^
 

Vexorian

Why no custom sig?
Reaction score
187
If you really want a pentagram you can easily draw one with lightning effects, you can use semi transparent aerial shackles lightning effect to make it look like fire.
 

SFilip

Gone but not forgotten
Reaction score
634
probably not because you wouldn't need as many lightning effect.
and btw functions like this
Code:
function Trig_Infernal_Nuke_org_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A016' ) ) then
        return false
    endif
    return true
endfunction
should be
Code:
function Trig_Infernal_Nuke_org_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A016'
endfunction
 
B

Beider

Guest
I see, thanks. Well actually I didn't convert that function to JASS, it's just made from the UI. I guess i will see if i can do it with a few lightning effects then.
 

SFilip

Gone but not forgotten
Reaction score
634
yeah i know...the problem is that gui usually makes more code than you need. thats why its a good idea to convert to jass and "do it yourself" ;)
 
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