• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Trigger problem on timers not functioning well

Status
Not open for further replies.
Level 4
Joined
Dec 30, 2006
Messages
72
i have 4 jass trigger for just 1 spell, i used global variables for them, and i dont have an idea on combining them

thats why i need some help on combining these 4 jass triggers and change the global variables to structs or private globals

Ill post the description of the spell
Creates an illusion of Ohm on the targeted area, while channeling the ability, when Ohm successfully finishes channeling the ability, she instantly moves to the illusion, and removing the illusion.
NOTE: when the caster stops channeling the spell, the illusion is removed, or when the caster finishes channeling the spell, the illusion is also removed

Triggers:
This trigger creates the illusion
JASS:
function Trig_MODStart_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A033'
endfunction

function Trig_MODStart_Actions takes nothing returns nothing
    set udg_MODunit = GetTriggerUnit()
    set udg_MODloc = GetSpellTargetLoc()
    call CasterCastAbility(GetOwningPlayer(GetTriggerUnit()), 'A034', "852274", GetTriggerUnit(), false)
endfunction

//===========================================================================
function InitTrig_MODStart takes nothing returns nothing
    set gg_trg_MODStart = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MODStart, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_MODStart, Condition( function Trig_MODStart_Conditions ) )
    call TriggerAddAction( gg_trg_MODStart, function Trig_MODStart_Actions )
endfunction

This trigger moves the illusion to the target area
note that i used the orc campaign hero Rokhan with the unit id 'Orkn'
JASS:
function Trig_MODMove_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetSummonedUnit()) == 'Orkn' and IsUnitIllusion(GetSummonedUnit())
endfunction

function Trig_MODMove_Actions takes nothing returns nothing
    set udg_MODfake = GetSummonedUnit()
    call CS_MoveUnitLoc(udg_MODfake, udg_MODloc)
endfunction

//===========================================================================
function InitTrig_MODMove takes nothing returns nothing
    set gg_trg_MODMove = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MODMove, EVENT_PLAYER_UNIT_SUMMON )
    call TriggerAddCondition( gg_trg_MODMove, Condition( function Trig_MODMove_Conditions ) )
    call TriggerAddAction( gg_trg_MODMove, function Trig_MODMove_Actions )
endfunction

This trigger moves the caster and removes the illusion, IF it finishes channeling the ability
JASS:
function Trig_MODRemove_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A033'
endfunction

function Trig_MODRemove_Actions takes nothing returns nothing
    call CS_MoveUnit(udg_MODunit, GetUnitX(udg_MODfake), GetUnitY(udg_MODfake))
    call RemoveUnit(udg_MODfake)
    call RemoveLocation(udg_MODloc)
endfunction

//===========================================================================
function InitTrig_MODRemove takes nothing returns nothing
    set gg_trg_MODRemove = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MODRemove, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_MODRemove, Condition( function Trig_MODRemove_Conditions ) )
    call TriggerAddAction( gg_trg_MODRemove, function Trig_MODRemove_Actions )
endfunction

This trigger removes the illusion IF the caster stops channeling the spell
JASS:
function Trig_MODEnd_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A033'
endfunction

function Trig_MODEnd_Actions takes nothing returns nothing
    call RemoveUnit(udg_MODfake)
endfunction

//===========================================================================
function InitTrig_MODEnd takes nothing returns nothing
    set gg_trg_MODEnd = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MODEnd, EVENT_PLAYER_UNIT_SPELL_ENDCAST )
    call TriggerAddCondition( gg_trg_MODEnd, Condition( function Trig_MODEnd_Conditions ) )
    call TriggerAddAction( gg_trg_MODEnd, function Trig_MODEnd_Actions )
endfunction

==========================================================
heres another spell trigger problem, the spell is based on invisibility, and can be targeted to allied unit or self, then the trigger runs a timer that checks if the targeted unit is still near a tree for 150 range, if not, then the trigger removes the invisibility buff, and stops the timer

but the problem is, it wont work, please help me with this

heres the trigger
i used ABC for attaching structs

JASS:
scope DarkStrike

globals
    private integer count = 0
endglobals

struct DarkStriker
    unit target
endstruct

private function CheckTrees takes nothing returns nothing
    set count = count + 1
endfunction

private function HideStart takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local DarkStriker d = GetTimerStructA(t)
    local location loc = GetUnitLoc(d.target)
    call EnumDestructablesInCircleBJ(150, loc, function CheckTrees)
    if count == 0 then
        call UnitRemoveAbility(d.target, 'B016')
        call d.destroy()
        call ReleaseTimer(t)
        call RemoveLocation(loc)
    endif
    set loc = null
    set t = null
endfunction

private function EternalForest takes nothing returns nothing
    local DarkStriker d = DarkStriker.create()
    local timer t = NewTimer()
    set d.target = GetSpellTargetUnit()
    call TimerStart(t, 1, true, function HideStart)
    call SetTimerStructA(t, d)
endfunction

public function InitTrig takes nothing returns nothing
    // a special event made by vex, actually this works just like
    // unit starts the effect of an ability event combined with a spell id condition
    // this event has no errors
    call OnAbilityEffect('A032', SCOPE_PRIVATE + "EternalForest")
endfunction

endscope

+rep for helpers
and credits to them for my map RotG Reborn
 
Level 9
Joined
Mar 25, 2005
Messages
252
Code:
[COLOr=White][B][COLOr=Wheat]scope[/COLOr][/B] MOD [B][COLOr=Wheat]initializer[/COLOr][/B] [COLOr=Silver]init[/COLOr]
    
    [B][COLOr=Wheat]globals[/COLOr][/B]
        [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Teal]unit[/COLOr][/B] Unit
        [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Teal]location[/COLOr][/B] Loc
        [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Teal]unit[/COLOr][/B] Fake
    [B][COLOr=Wheat]endglobals[/COLOr][/B]
    
    [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]StartRemoveEnd_Conditions[/COLOr] [COLOr=Gray]takes[/COLOr] [B][COLOr=Teal]nothing[/COLOr][/B] [B][COLOr=Wheat]returns[/COLOr][/B] [B][COLOr=Teal]boolean[/COLOr][/B]
        [B][COLOr=Wheat]return[/COLOr][/B] [COLOr=LightBlue]GetSpellAbilityId[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B] [B][COLOr=SandyBrown]==[/COLOr][/B] 'A033'
    [B][COLOr=Wheat]endfunction[/COLOr][/B]
    
    [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]Start_Actions[/COLOr] [COLOr=Gray]takes[/COLOr] [B][COLOr=Teal]nothing[/COLOr][/B] [B][COLOr=Wheat]returns[/COLOr][/B] [B][COLOr=Teal]nothing[/COLOr][/B]
        [COLOr=Gray]set[/COLOr] Unit [B][COLOr=SandyBrown]=[/COLOr][/B] [COLOr=LightBlue]GetTriggerUnit[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]set[/COLOr] Loc [B][COLOr=SandyBrown]=[/COLOr][/B] [COLOr=LightBlue]GetSpellTargetLoc[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] CasterCastAbility[B][COLOr=SandyBrown]([/COLOr][/B][COLOr=LightBlue]GetOwningPlayer[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][COLOr=LightBlue]GetTriggerUnit[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B][B][COLOr=SandyBrown],[/COLOr][/B] 'A034'[B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=MediumTurquoise]"852274"[/COLOr][B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=LightBlue]GetTriggerUnit[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B][B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=MediumTurquoise]false[/COLOr][B][COLOr=SandyBrown])[/COLOr][/B]
    [B][COLOr=Wheat]endfunction[/COLOr][/B]
    
    [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]Move_Conditions[/COLOr] [COLOr=Gray]takes[/COLOr] [B][COLOr=Teal]nothing[/COLOr][/B] [B][COLOr=Wheat]returns[/COLOr][/B] [B][COLOr=Teal]boolean[/COLOr][/B]
        [B][COLOr=Wheat]return[/COLOr][/B] [COLOr=LightBlue]GetUnitTypeId[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][COLOr=LightBlue]GetSummonedUnit[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B] [B][COLOr=SandyBrown]==[/COLOr][/B] 'Orkn' and [COLOr=LightBlue]IsUnitIllusion[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][COLOr=LightBlue]GetSummonedUnit[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B]
    [B][COLOr=Wheat]endfunction[/COLOr][/B]
    
    [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]Move_Actions[/COLOr] [COLOr=Gray]takes[/COLOr] [B][COLOr=Teal]nothing[/COLOr][/B] [B][COLOr=Wheat]returns[/COLOr][/B] [B][COLOr=Teal]nothing[/COLOr][/B]
        [COLOr=Gray]set[/COLOr] Fake [B][COLOr=SandyBrown]=[/COLOr][/B] [COLOr=LightBlue]GetSummonedUnit[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] CS_MoveUnitLoc[B][COLOr=SandyBrown]([/COLOr][/B]Fake[B][COLOr=SandyBrown],[/COLOr][/B] Loc[B][COLOr=SandyBrown])[/COLOr][/B]
    [B][COLOr=Wheat]endfunction[/COLOr][/B]
    
    [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]Remove_Actions[/COLOr] [COLOr=Gray]takes[/COLOr] [B][COLOr=Teal]nothing[/COLOr][/B] [B][COLOr=Wheat]returns[/COLOr][/B] [B][COLOr=Teal]nothing[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] CS_MoveUnit[B][COLOr=SandyBrown]([/COLOr][/B]Unit[B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=LightBlue]GetUnitX[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B]Fake[B][COLOr=SandyBrown])[/COLOr][/B][B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=LightBlue]GetUnitY[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B]Fake[B][COLOr=SandyBrown])[/COLOr][/B][B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]RemoveUnit[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B]Fake[B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]RemoveLocation[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B]Loc[B][COLOr=SandyBrown])[/COLOr][/B]
    [B][COLOr=Wheat]endfunction[/COLOr][/B]
    
    [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]End_Actions[/COLOr] [COLOr=Gray]takes[/COLOr] [B][COLOr=Teal]nothing[/COLOr][/B] [B][COLOr=Wheat]returns[/COLOr][/B] [B][COLOr=Teal]nothing[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]RemoveUnit[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B]Fake[B][COLOr=SandyBrown])[/COLOr][/B]
    [B][COLOr=Wheat]endfunction[/COLOr][/B]
    
    [B][COLOr=Wheat]private[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]init[/COLOr] [COLOr=Gray]takes[/COLOr] [B][COLOr=Teal]nothing[/COLOr][/B] [B][COLOr=Wheat]returns[/COLOr][/B] [B][COLOr=Teal]nothing[/COLOr][/B]
        [COLOr=Green]// InitTrig_MODStart[/COLOr]
        [COLOr=Gray]local[/COLOr] [B][COLOr=Teal]trigger[/COLOr][/B] t [B][COLOr=SandyBrown]=[/COLOr][/B] [COLOr=LightBlue]CreateTrigger[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=Red]TriggerRegisterAnyUnitEventBJ[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=MediumTurquoise]EVENT_PLAYER_UNIT_SPELL_EFFECT[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]TriggerAddCondition[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=LightBlue]Condition[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]StartRemoveEnd_Conditions[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]TriggerAddAction[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]Start_Actions[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B]
        
        [COLOr=Green]// InitTrig_MODMove[/COLOr]
        [COLOr=Gray]set[/COLOr] t [B][COLOr=SandyBrown]=[/COLOr][/B] [COLOr=LightBlue]CreateTrigger[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=Red]TriggerRegisterAnyUnitEventBJ[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] EVENT_PLAYER_UNIT_SUMMON [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]TriggerAddCondition[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=LightBlue]Condition[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]Move_Conditions[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]TriggerAddAction[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]Move_Actions[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B]
        
        [COLOr=Green]// InitTrig_MODRemove[/COLOr]
        [COLOr=Gray]set[/COLOr] t [B][COLOr=SandyBrown]=[/COLOr][/B] [COLOr=LightBlue]CreateTrigger[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=Red]TriggerRegisterAnyUnitEventBJ[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=MediumTurquoise]EVENT_PLAYER_UNIT_SPELL_FINISH[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]TriggerAddCondition[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=LightBlue]Condition[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]StartRemoveEnd_Conditions[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]TriggerAddAction[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]Remove_Actions[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B]
        
        [COLOr=Green]// InitTrig_MODEnd[/COLOr]
        [COLOr=Gray]set[/COLOr] t [B][COLOr=SandyBrown]=[/COLOr][/B] [COLOr=LightBlue]CreateTrigger[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=Red]TriggerRegisterAnyUnitEventBJ[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=MediumTurquoise]EVENT_PLAYER_UNIT_SPELL_ENDCAST[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]TriggerAddCondition[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [COLOr=LightBlue]Condition[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]StartRemoveEnd_Conditions[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B] [B][COLOr=SandyBrown])[/COLOr][/B]
        [COLOr=Gray]call[/COLOr] [COLOr=LightBlue]TriggerAddAction[/COLOr][B][COLOr=SandyBrown]([/COLOr][/B] t[B][COLOr=SandyBrown],[/COLOr][/B] [B][COLOr=Wheat]function[/COLOr][/B] [COLOr=Silver]End_Actions[/COLOr] [B][COLOr=SandyBrown])[/COLOr][/B]
    [B][COLOr=Wheat]endfunction[/COLOr][/B]
    
[B][COLOr=Wheat]endscope[/COLOr][/B][/COLOr]
I didn't test this ingame but pjass seemed to pass it (only errors I got were the CS functions that I don't have in the map that I tested this in)



I'm guessing that this should solve your second problem:
JASS:
private function HideStart takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local DarkStriker d = GetTimerStructA(t)
    local location loc = GetUnitLoc(d.target)
    set count = 0 // new
    call EnumDestructablesInCircleBJ(150, loc, function CheckTrees)
    if count == 0 then
        call UnitRemoveAbility(d.target, 'B016')
        call d.destroy()
        call ReleaseTimer(t)
        call RemoveLocation(loc)
    endif
    set loc = null
    set t = null
endfunction
 
Status
Not open for further replies.
Top