Trigger Help

Toriad

New Member
Reaction score
4
JASS:
function Trig_Crippling_Shot_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(),'A00R') > 0
endfunction

function CripplingShot takes nothing returns boolean
    local real Random = GetRandomReal(0.,100.)
    local integer Agility = GetHeroAgi(GetEventDamageSource(), true)
    local real ChanceToHit = .25 * Agility
    local unit Victim = GetTriggerUnit()
    
    
    if (100 >= Random) then //ChanceToHit
        call Debug("Test")
        call CreateNUnitsAtLoc(1, 'n000', GetOwningPlayer(GetEventDamageSource()), GetUnitLoc(Victim), 0)
        call UnitAddAbilityBJ('A00S', GetLastCreatedUnit())
        call TimeLife(GetLastCreatedUnit())
        call IssueTargetOrderBJ(GetLastCreatedUnit(), "slow", Victim)
        call CreateNUnitsAtLoc(1, 'n000', GetOwningPlayer(GetEventDamageSource()), GetUnitLoc(Victim), 0)
        call TimeLife(GetLastCreatedUnit())
        call UnitAddAbilityBJ('A00T', GetLastCreatedUnit())
        call IssueTargetOrderBJ(GetLastCreatedUnit(), "unholyfrenzy", Victim)
    endif
    return false
endfunction

function Trig_Crippling_Shot_Actions takes nothing returns nothing
    local trigger t = CreateTrigger()
    local triggercondition tc = TriggerAddCondition(t, Condition( function CripplingShot))
    call TriggerRegisterUnitEvent(t, GetTriggerUnit(), EVENT_UNIT_DAMAGED)
    call PolledWait(1.)
    call TriggerRemoveCondition(t,tc)
    call DestroyTrigger(t)
    set t = null
    
endfunction

//===========================================================================
function InitTrig_Crippling_Shot takes nothing returns nothing
    set gg_trg_Crippling_Shot = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Crippling_Shot, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Crippling_Shot, Condition( function Trig_Crippling_Shot_Conditions))
    call TriggerAddAction( gg_trg_Crippling_Shot, function Trig_Crippling_Shot_Actions )
endfunction


Anyone know why That crashes wheni attack a enemy but works fine when I attack a ally?
 

AceLegend90

New Member
Reaction score
6
You need to disable 'CripplingShot' and re-enable it whenever you use the event 'EVENT_UNIT_DAMAGED'. So add the following:

JASS:
function Trig_Crippling_Shot_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(),'A00R') > 0
endfunction

function CripplingShot takes nothing returns boolean
    local real Random = GetRandomReal(0.,100.)
    local integer Agility = GetHeroAgi(GetEventDamageSource(), true)
    local real ChanceToHit = .25 * Agility
    local unit Victim = GetTriggerUnit()
    
    call DisableTrigger(GetTriggeringTrigger()) // This line needs to be added.
    if (100 >= Random) then //ChanceToHit
        call Debug("Test")
        call CreateNUnitsAtLoc(1, 'n000', GetOwningPlayer(GetEventDamageSource()), GetUnitLoc(Victim), 0)
        call UnitAddAbilityBJ('A00S', GetLastCreatedUnit())
        call TimeLife(GetLastCreatedUnit())
        call IssueTargetOrderBJ(GetLastCreatedUnit(), "slow", Victim)
        call CreateNUnitsAtLoc(1, 'n000', GetOwningPlayer(GetEventDamageSource()), GetUnitLoc(Victim), 0)
        call TimeLife(GetLastCreatedUnit())
        call UnitAddAbilityBJ('A00T', GetLastCreatedUnit())
        call IssueTargetOrderBJ(GetLastCreatedUnit(), "unholyfrenzy", Victim)
    endif
    call EnableTrigger(GetTriggeringTrigger()) // This line needs to be added.
    return false
endfunction

function Trig_Crippling_Shot_Actions takes nothing returns nothing
    local trigger t = CreateTrigger()
    local triggercondition tc = TriggerAddCondition(t, Condition( function CripplingShot)) // Not sure if the condition leaks after use.
    call TriggerRegisterUnitEvent(t, GetTriggerUnit(), EVENT_UNIT_DAMAGED)
    call PolledWait(1.)
    call TriggerRemoveCondition(t,tc)
    call DestroyTrigger(t) // You need to destroy the trigger 15 seconds later to avoid a certain bug I believe.
    set t = null
    
endfunction

//===========================================================================
function InitTrig_Crippling_Shot takes nothing returns nothing
    set gg_trg_Crippling_Shot = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Crippling_Shot, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Crippling_Shot, Condition( function Trig_Crippling_Shot_Conditions))
    call TriggerAddAction( gg_trg_Crippling_Shot, function Trig_Crippling_Shot_Actions )
endfunction
 
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