Improve my trigger

Roku

New Member
Reaction score
3
Hey, well i have this trigger of mine, which is basically a spell. The problem is i get delays on some of the actions, and this causes my spell to look weird. I read about avoiding BJ's, and i tried avoiding as many as possible. So here is the trigger:

JASS:
scope FB

globals
    private unit array u
    private integer p
endglobals

private function CA takes nothing returns boolean
    return GetSpellAbilityId() == 'A00B'
endfunction

private function Buffcond takes nothing returns boolean
    return GetUnitTypeId(GetEventDamageSource()) == 'h001'
endfunction


private function Act takes nothing returns nothing
    local location casterpos
    local unit d
    set p = GetUnitIndex(GetTriggerUnit())
    set u[p] = GetTriggerUnit()
    set casterpos = GetUnitLoc(u[p])
    call CreateNUnitsAtLoc( 1, 'h001', GetOwningPlayer(u[p]), casterpos, bj_UNIT_FACING )
    set d = bj_lastCreatedUnit
    call IssueTargetOrder( d, "attack", GetSpellTargetUnit() )
    call UnitApplyTimedLife(d, 'BTLF', 2.00)
    call RemoveLocation(casterpos)
    set d = null
    set casterpos = null
endfunction

//---------------------------------------

private function Buffapply takes nothing returns nothing
    local unit FBdummy = GetEventDamageSource()
    local location FBdummypos = GetUnitLoc(FBdummy)
    local unit d
    local integer s = GetHeroAgi(u[p],true)
    local real cr = I2R(s)
    local real r = GetRandomReal(0.95,1.05)
    call CreateNUnitsAtLoc( 1, 'h005', GetOwningPlayer(FBdummy), FBdummypos, bj_UNIT_FACING )
    set d = bj_lastCreatedUnit
    call UnitAddAbility( d,'A00C')
    call IssueTargetOrder( d, "slow", GetTriggerUnit() )
    call UnitApplyTimedLife(d, 'BTLF', 2.00)
    call UnitDamageTarget(u[p], GetTriggerUnit(), (1500 + cr) * r, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL , WEAPON_TYPE_WHOKNOWS)
    call RemoveLocation(FBdummypos)
    set FBdummy = null
    set FBdummypos = null
    set d = null
endfunction

private function Add takes unit u returns nothing
    local trigger t2 = CreateTrigger()
    call TriggerRegisterUnitEvent(t2, u, EVENT_UNIT_DAMAGED)
    call TriggerAddCondition (t2, Condition(function Buffcond))
    call TriggerAddAction(t2, function Buffapply)
    set t2 = null
endfunction

private function calladd takes nothing returns nothing
    local unit un = GetTriggerUnit()
    call Add(un)
    set un = null
endfunction

//===========================================================================
function InitTrig_FB takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger t3 = CreateTrigger()
    local rect map = GetPlayableMapRect()
    call TriggerRegisterEnterRectSimple( t3, map )
    call TriggerAddAction (t3, function calladd)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Condition(function CA)) 
    call TriggerAddAction( t, function Act )
    set map = null
    set t = null
    set t3 = null
endfunction

endscope


I know its not that advanced and maybe uses too many functions, but i'm happy it works. The thing is, my frostbolt has 2.5 sec cast, and when it finishes casting, i have like a half sec delay before my actual bolt is fired. Same thing goes for when the frostbolt hits, there is also a half sec delay before my buff is applied to the unit that is hit and thus it causes some unit coloring issues. (targets that have frostbolt buff turn blue)
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
Hmm let's see whether I can help a bit.
I will probably not find your *delay* problem but at least I can help you improving^^

JASS:
function InitTrig_FB takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger t3 = CreateTrigger()
    local rect map = GetPlayableMapRect()
    call TriggerRegisterEnterRectSimple( t3, map )
    call TriggerAddAction (t3, function calladd)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Condition(function CA)) 
    call TriggerAddAction( t, function Act )
    set map = null
    set t = null
    set t3 = null 
endfunction


Nulling triggers you add per InitTrig is somewhat unnecessary since I doubt you'll ever destroy them and hence the pointing variable will never leak as well.
You can simple use "bj_mapInitialPlayableArea" instead of creating an extra rect variable which you null as well. Since this rect is always there it wouldn't be leaking anyway... and also because it is bj_ I think.

You also use locations, which will end up slower then coordinates.
Instead of GetUnitLocation() use GetUnitX() and GetUnitY() [ or GetLocationX/Y]for the coordinates. And then better use something like this


To the delay, did you check whether the dummy abilities have 0 sec casting time and missle speed and so on is correct as well?
 

Roku

New Member
Reaction score
3
Ah thanks alot for helping, +rep, yes i kinda solved the delay by setting some values in object editor (art - cast backswing, combat - animation backswing etc.) to 0, so the i kinda removed all the casting and attack animation and gained speed.
 

Joker(Div)

Always Here..
Reaction score
86
@Roku
Don't create unnecessary trigger variables. One is sufficient.
JASS:
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegister...
    call TriggerAddAction...

    set trig = CreateTrigger()
    ...

Works fine. Also, notice the public suffix, and the name InitTrig, not InitTrig_FB.

Don't set triggers to null. No point.

Use EVENT_PLAYER_UNIT_SPELL_EFFECT, not EVENT_PLAYER_UNIT_SPELL_CAST.

JASS:
private function calladd takes nothing returns nothing
    local unit un = GetTriggerUnit()
    call Add(un)
    set un = null
endfunction

No point with that local. just do
JASS:
call Add( GetTriggerUnit() )


change
JASS:
    local unit d
    call CreateNUnitsAtLoc( 1, 'h005', GetOwningPlayer(FBdummy), FBdummypos, bj_UNIT_FACING )
    set d = bj_lastCreatedUnit

to
JASS:
local unit d = CreateUnitAtLoc( GetOwningPlayer(FBdummy), 'h005', FBdummypos, bj_UNIT_FACING )
    //Proly better to use CreateUnit(), but w/e


This is only a part of it. I finish maybe when I got more time.
 
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