HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Can someone loop this?

04-23-2006, 01:35 PM#1
Arkidas
You can find my trigger below.( Both GUI and JASS format )
What I want to be done is loop the trigger for "11 - TheAbility'sLevel times"
For example if the level of Snap would be 3 it would loop 8 times, If it would be 6 it would loop 5 times.

Thank you.

GUI:
Trigger:
Snap
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Snap
Collapse Actions
Unit - Cause (Casting unit) to damage (Casting unit), dealing ((Life of (Target unit of ability being cast)) / (-11.00 + (Real((Level of Snap for (Casting unit)))))) damage of attack type Spells and damage type Normal


JASS:
Collapse JASS:
function Trig_Snap_Copy_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Snap_Copy_Actions takes nothing returns nothing
    call UnitDamageTargetBJ( GetSpellAbilityUnit(), GetSpellAbilityUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetSpellTargetUnit()) / ( -11.00 + I2R(GetUnitAbilityLevelSwapped('A004', GetSpellAbilityUnit())) ) ), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
endfunction

//===========================================================================
function InitTrig_Snap_Copy takes nothing returns nothing
    set gg_trg_Snap_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Snap_Copy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Snap_Copy, Condition( function Trig_Snap_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Snap_Copy, function Trig_Snap_Copy_Actions )
endfunction

04-23-2006, 01:39 PM#2
Thunder_Eye
GUI:
Trigger:
Snap
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Snap
Collapse Actions
Collapse For each (Integer A) from 1 to (11 - (Level of Snap for (Casting unit))), do (Actions)
Collapse Loop - Actions
Unit - Cause (Casting unit) to damage (Casting unit), dealing ((Life of (Target unit of ability being cast)) / (-11.00 + (Real((Level of Snap for (Triggering unit)))))) damage of attack type Spells and damage type Normal

JASS:
Collapse JASS:
function Trig_Snap_Copy_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Snap_Copy_Actions takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > ( 11 - GetUnitAbilityLevel( GetTriggerUnit(), 'A004' ) )
        call UnitDamageTarget( GetTriggerUnit(), GetTriggerUnit(), ( GetUnitState(GetSpellTargetUnit(), UNIT_STATE_LIFE ) / ( -11.00 + I2R(GetUnitAbilityLevel( GetTriggerUnit(), 'A004' )) ) ), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Snap_Copy takes nothing returns nothing
    set gg_trg_Snap_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Snap_Copy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Snap_Copy, Condition( function Trig_Snap_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Snap_Copy, function Trig_Snap_Copy_Actions )
endfunction
04-23-2006, 01:43 PM#3
Arkidas
I am actually using this to heal the casting units. As you might have noticed it is a negative damage value. Are you sure that this is possible in GUI and that this is the right way? Will the action you provided simply loop it 11 times - the ability's level?
04-23-2006, 01:51 PM#4
Thunder_Eye
Yes it will work.

note: the JASS version is slightly better
(remember if you change the name of the trigger be sure to change all the "_Snap_Copy" to "_<Newnameoftrigger>"
04-23-2006, 02:49 PM#5
Arkidas
Now the trigger looks like this but for some reason the casting unit is never healed. Why?

Collapse JASS:
function Trig_Snap_Copy_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Snap_Copy_Actions takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > ( 11 - GetUnitAbilityLevel( GetTriggerUnit(), 'A004' ) )
        call UnitDamageTarget( GetTriggerUnit(), GetTriggerUnit(), ( GetUnitState(GetSpellTargetUnit(), UNIT_STATE_LIFE ) / ( -11.00 + I2R(GetUnitAbilityLevel( GetTriggerUnit(), 'A004' )) ) ), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
    call TriggerSleepAction(1)        
    set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Snap_Copy takes nothing returns nothing
    set gg_trg_Snap_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Snap_Copy, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Snap_Copy, Condition( function Trig_Snap_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Snap_Copy, function Trig_Snap_Copy_Actions )
endfunction

04-23-2006, 03:58 PM#6
Thunder_Eye
First of be sure 'A004' is the rawdata of your snap spell.
Second replace call TriggerSleepAction(1) with call TriggerSleepAction(1.00) (not sure it makes any difference)

You can also try changing all the GetTriggerUnit() to GetSpellAbilityUnit()

Else you might have to change the event (EVENT_PLAYER_UNIT_SPELL_FINISH) to any of the following:
EVENT_PLAYER_UNIT_SPELL_CHANNEL
EVENT_PLAYER_UNIT_SPELL_CAST
EVENT_PLAYER_UNIT_SPELL_EFFECT

try them all.
04-23-2006, 04:16 PM#7
Arkidas
Thanks, I will try this.

EDIT:Well not it seems to do work but it only heals once. The ability is at level 5.

Collapse JASS:
function Trig_Snap_Copy_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Snap_Copy_Actions takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > ( 11 - GetUnitAbilityLevel( GetSpellAbilityUnit(), 'A004' ) )
        call UnitDamageTarget( GetSpellAbilityUnit(), GetSpellAbilityUnit(), ( GetUnitState(GetSpellTargetUnit(), UNIT_STATE_LIFE ) / ( -11.00 + I2R(GetUnitAbilityLevel( GetSpellAbilityUnit(), 'A004' )) ) ), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
    call TriggerSleepAction(1.00)        
    set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Snap_Copy takes nothing returns nothing
    set gg_trg_Snap_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Snap_Copy, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
    call TriggerAddCondition( gg_trg_Snap_Copy, Condition( function Trig_Snap_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Snap_Copy, function Trig_Snap_Copy_Actions )
endfunction
04-23-2006, 04:24 PM#8
TaintedReality
Store the Target Unit and the Casting Unit of the spell to variables before looping. If you have TriggerSleepAction() inside a trigger, it forgets who the Casting Unit and Target Unit were unless you stored them earlier.
04-23-2006, 04:27 PM#9
Arkidas
Is this not possible using local variables?
04-23-2006, 04:33 PM#10
TaintedReality
Meh, would be harder without them. Here's the JASS:

Collapse JASS:
function Trig_Snap_Copy_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Snap_Copy_Actions takes nothing returns nothing
    local integer i = 1
    local unit caster = GetSpellAbilityUnit()
    local unit target = GetSpellTargetUnit()
    loop
        exitwhen i > ( 11 - GetUnitAbilityLevel( GetSpellAbilityUnit(), 'A004' ) )
        call UnitDamageTarget(caster,caster, ( GetUnitState(target, UNIT_STATE_LIFE ) / ( -11.00 + I2R(GetUnitAbilityLevel(caster, 'A004' )) ) ), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
        call TriggerSleepAction(1.00)        
        set i = i + 1
    endloop
    set caster = null
    set target = null
endfunction

//===========================================================================
function InitTrig_Snap_Copy takes nothing returns nothing
    set gg_trg_Snap_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Snap_Copy, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
    call TriggerAddCondition( gg_trg_Snap_Copy, Condition( function Trig_Snap_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Snap_Copy, function Trig_Snap_Copy_Actions )
endfunction

And BTW, it seems that you are having the caster heal himself, but it's based on the target's life? Maybe this is what you wanted but it seemed wierd to me =P.
04-23-2006, 04:35 PM#11
Soultaker
Also, if you have Wait/Sleep action in a loop, you should use "For Loop Integer <Variable" (I think it's like that, don't got the editor here..). Else it can mix up with other loops that also have waits in them.

Btw. You might want to use "Set unit HP" instead of dealing negative damage.

- Soultaker
04-23-2006, 04:35 PM#12
Arkidas
Yeah you see it devours the raget and then heals the caster for the amount of health the target has :)
Thanks! I will try this :)
EDIT:Can you possibly do that End Loop with wait for me?
I am not so known with JASS and don't have the required knowledge. :)
04-23-2006, 05:10 PM#13
Thunder_Eye
Quote:
Originally Posted by TaintedReality
Store the Target Unit and the Casting Unit of the spell to variables before looping. If you have TriggerSleepAction() inside a trigger, it forgets who the Casting Unit and Target Unit were unless you stored them earlier.

Hmm doesnt GetTriggerUnit() work after waits?

and btw in tainteds trigger, change

Collapse JASS:
exitwhen i > ( 11 - GetUnitAbilityLevel( GetSpellAbilityUnit(), 'A004' ) )
to
Collapse JASS:
exitwhen i > ( 11 - GetUnitAbilityLevel( caster, 'A004' ) )
04-23-2006, 05:11 PM#14
TaintedReality
Quote:
Can you possibly do that End Loop with wait for me?

What do you mean?

Quote:
Also, if you have Wait/Sleep action in a loop, you should use "For Loop Integer <Variable" (I think it's like that, don't got the editor here..). Else it can mix up with other loops that also have waits in them.

This is in JASS with local variables, so it's not going to get mixed up with other functions.

Edit: Oh, must have missed that one, thanks thunder ^^.
04-23-2006, 05:15 PM#15
Arkidas
Quote:
Originally Posted by TaintedReality
What do you mean?

Please take a look at Soultaker's reply which you just quoted.
As you said though it doesn't mix with local vars :)
So I'm wondering what would be the final trigger?
Should I simply do what Thunder told me and then it's final?

Thanks all of you! :D