HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Question about enabling triggers, some functions questions and more...

01-01-2009, 12:55 AM#1
Magoiche
1. Is there a way to enable a trigger inside the same script?

Example triggers:

Collapse JASS:
scope lol initializer Initial


private function Actions takes nothing returns nothing
    call EnableTrigger( gg_trg_Untitled_Trigger_002 )
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope

Collapse JASS:
scope lol2 initializer Initial


private function Actions takes nothing returns nothing
    call EnableTrigger( gg_trg_Untitled_Trigger_003 )
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope

But i can only do that is they are in diferent triggers(CTRL + T)
There is a way to do it in the same trigger?

2. GetUnitsInRangeOfLocMatching, CountUnitsInGroup, GroupPickRandomUnit, GetUnitsInRangeOfLocMatching inline or use them?

3. What is a boolexpr? And a pooledwait?

4. This trigger works perfectly. But it execute the actions if i order the unit to hold position or stop. Why?
Collapse JASS:
scope InsanityDeactivation initializer Initial

private function Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local trigger trig = GetTriggeringTrigger()
    if GetIssuedOrderId() == OrderId( "unimmolation" ) then
        set trig = null
        return true
    elseif GetIssuedOrderId() == OrderId( "immolation" ) then
        call TriggerRegisterUnitStateEvent( trig, u, UNIT_STATE_MANA, LESS_THAN_OR_EQUAL, 1.00)
        set trig = null
        return false
    endif
    return true
endfunction
    
private function Actions takes nothing returns nothing
    call UnitRemoveAbility( GetTriggerUnit(), 'A005' )
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope

5. Why those trigger don't work?

Collapse JASS:
scope DarkRageInitial initializer Initial

globals
    integer AttacksNumberCounter = 0
    unit Caster = GetTriggerUnit()
endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A007'
endfunction

private function Actions takes nothing returns nothing
    call EnableTrigger( gg_trg_Untitled_Trigger_002 )
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope

Collapse JASS:
scope DarkRageAttacks initializer Initial

private function TargetAndGroupConditions takes nothing returns boolean
    return IsUnitEnemy( GetFilterUnit(), GetOwningPlayer( Caster ) ) == true and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE ) == false and GetUnitState( GetFilterUnit(), UNIT_STATE_LIFE ) <= 0
endfunction

private function DarkRageAttack takes nothing returns nothing
    local location CasterLoc = GetUnitLoc( Caster )
    local group PossibleTargets = GetUnitsInRangeOfLocMatching(500.00, CasterLoc, Condition( function TargetAndGroupConditions ) )
    local integer NOfPossibleTargets = CountUnitsInGroup(PossibleTargets)
    local unit Target = GroupPickRandomUnit( GetUnitsInRangeOfLocMatching(500.00, CasterLoc, Condition( function TargetAndGroupConditions ) ) )
    local location TargetLoc = GetUnitLoc( Target )
    local real x = GetLocationX( TargetLoc ) + 50.00 * Cos(GetRandomReal(0, 360) * bj_DEGTORAD)
    local real y = GetLocationY( TargetLoc ) + 50.00 * Sin(GetRandomReal(0, 360) * bj_DEGTORAD)
    local location AttackLandingLoc = Location(x,y)
    set AttacksNumberCounter = ( AttacksNumberCounter + 1 )
    if ( NOfPossibleTargets == 0 ) then
    else
        call UnitDamageTarget( Caster, Target, 300.00, true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_METAL_LIGHT_CHOP )
        call SetUnitPositionLoc( Caster, AttackLandingLoc )
    endif
endfunction

private function DarkSlamUse takes nothing returns nothing
    local real x = GetUnitX( Caster )
    local real y = GetUnitY( Caster )
    local unit Dummy = CreateUnit( GetOwningPlayer( Caster ), 'u001', x, y, 0.00 )
    call UnitApplyTimedLife( Dummy, 'BTLF', 5.00 )
    call UnitAddAbility( Dummy, 'A006' )
    call SetUnitAbilityLevel( Dummy, 'A006', 2 )
    call IssueImmediateOrder( Dummy, "thundercalp" )
    call DestroyEffect( AddSpecialEffectLoc( "Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl", GetUnitLoc( Dummy ) ) )
    set Dummy = null
endfunction

private function ZeroAttacksNumberCounter takes nothing returns nothing
    set AttacksNumberCounter = 0
endfunction

private function Actions takes nothing returns nothing
    if (AttacksNumberCounter == ( 1 + ( 2 * GetUnitAbilityLevel( Caster, 'A007' ) ) ) ) then
        call ZeroAttacksNumberCounter()
        if ( GetUnitAbilityLevel( Caster, 'B004' ) > 0 ) then
            call EnableTrigger( gg_trg_Untitled_Trigger_003 )
        endif
        call DarkSlamUse()
    else
        call DarkRageAttack()
    endif
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterTimerEvent( trig, 0.45, true )
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope

Collapse JASS:
scope DarkRageInsanityShout initializer Initial

private function Actions takes nothing returns nothing
    local real x = GetUnitX( Caster )
    local real y = GetUnitY( Caster )
    local unit Dummy = CreateUnit( GetOwningPlayer( Caster ), 'u001', x, y, 0.00 )
    if ( GetUnitAbilityLevel( Caster, 'B004' ) > 0 ) then
    call UnitApplyTimedLife( Dummy, 'BTLF', 5.00 )
    call UnitAddAbility( Dummy, 'A006' )
    call SetUnitAbilityLevel( Dummy, 'A006', 2 )
    call IssueImmediateOrder( Dummy, "stomp" )
    call DestroyEffect( AddSpecialEffectLoc( "Abilities\\Spells\\Other\\HowlOfTerror\\HowlCaster.mdl", GetUnitLoc( Dummy ) ) )
    endif
    set Dummy = null
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterTimerEvent( trig, 0.45, false )
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope

My bet is that there is no TriggerUnit so Caster = null.
But if its realy this i don't know how to make it with out the gettriggerunit. i.i
I was tinking if i make it a loop with wait will be better than a periodic event but not sure.

Sorry if i am asking to much. =/
01-01-2009, 12:58 AM#2
TriggerHappy
Quote:
Is there a way to enable a trigger inside the same script?

You could add a boolean check,

Collapse JASS:
private function test takes nothing returns boolean
    return someboolvar == true
endfunction

TriggerAddCondition(gg_trg_Untitled_Trigger_002 ,Condition(function test))


Just set the boolean to true or false, if you want the trigger on or off.

Quote:
And a pooledwait?

Like TriggerSleepAction().

Quote:
Why those trigger don't work?

I Woudn't initialize this

Collapse JASS:
unit Caster = GetTriggerUnit()

Though i'm a bit busy to look through everything
01-01-2009, 01:08 AM#3
Magoiche
And about the trigger enabling.
If i want to change the name how i do that(Assuming that they all are in the same trigger)?
01-01-2009, 01:21 AM#4
Zerzax
Change the name? I don't understand. If you want to disable or enable a trigger, you need a reference to it, such as a global. Or you could use GetTriggeringTrigger() in an action or condition function.

Collapse JASS:
scope lol initializer Initial


private function Actions takes nothing returns nothing
    call EnableTrigger( gg_trg_Untitled_Trigger_002 )
endfunction

private function Initial takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002 = CreateTrigger()
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Actions )
endfunction

endscope

Or

Collapse JASS:

function Actions takes nothing returns nothing
    call EnableTrigger(GetTriggeringTrigger())
endfunction

function init takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerAddAction(t, function Actions)
endfunction


Is that what you want? Also, you don't have to null a permanent trigger.
01-01-2009, 02:41 AM#5
Magoiche
Oh! I get it.

Thanks Zerzax and TriggerHappy187!

I will use the global way =]

Now with the other things...

Oh and Happy New Year(I am in 2009 already xD)
01-01-2009, 03:26 AM#6
Zerzax
Yep, globals are nice despite the fact that they can be manipulated by people looking at your script. Anyway, Happy New Year! I'm 45 min exactly from midnight.