Hello everyone! I am decent at programming but I'm pretty new to jass so I might just have done something stupid! I'm trying to create an auto cast ability, like cold arrow, that deals a scaling dmg, let's say 5 per each level multoplied by the times the target has remained the same, meaning that for example the 4th hit on the same target will deal 20 dmg. I've taken the script from this tutorial and modified it for my cause:
http://world-editor-tutorials.thehelper.net/cat_usersubmit.php?view=41266
I have two main problems:
First, the trigger needs to detect the auto ability either it was auto cast or cast by the user. The code for the second "trigger" in the int_trigger was wrong in the page, I have tried to fix it but it doesn't seem to work.
Second, the script doesn't work as I would like it to. If the target is changed and the ability is used, it works, the counter is reset, but if the target is changed and the ability is not used, the counter on the previous unit, the one hit by the ability, the counter would not reset and start from the number it stopped. I really can't figure out why. I think the problem is somehow in the Auto Attack Detect trigger. If the conditions are not met, meaning that the ability has not been cast, the counter should be reset. Somehow it doesn't! This is weird because the Auto Attack Detect should run every time a unit is hit, if I'm not mistaken! Here is the code:
function Auto_Attack_Detect takes nothing returns boolean
if GetTriggerEventId()==EVENT_PLAYER_UNIT_ATTACKED then
if (GetAttacker() == udg_Emanation) then
set udg_EtherStrikeNextTarget= GetTriggerUnit()
endif
if GetUnitAbilityLevel(GetAttacker(),'A000')>0 then
return true
endif
endif
if GetTriggerEventId()==EVENT_UNIT_SPELL_EFFECT and GetSpellAbilityId()=='A000' then
return true
endif
set udg_EtherStrikeCount = 0
return false
endfunction
function Auto_Attack_Effects takes nothing returns nothing
local real dam
local unit targ = GetTriggerUnit()
local unit cast = GetEventDamageSource()
local texttag t
if GetUnitAbilityLevel(targ,'B000')>0 and GetUnitAbilityLevel(cast,'A000')>0 then
call DisableTrigger(GetTriggeringTrigger())
if (udg_EtherStrikePreviousTarget==udg_EtherStrikeNextTarget) then
set udg_EtherStrikeCount = udg_EtherStrikeCount +1
else
set udg_EtherStrikeCount = 0
endif
set udg_EtherStrikePreviousTarget=udg_EtherStrikeNextTarget
set dam = (GetUnitAbilityLevel(cast,'A000')*5)*(1+(udg_EtherStrikeCount))
set t = CreateTextTag()
call SetTextTagText(t,"+"+I2S(R2I(dam)),.023)
call SetTextTagPosUnit(t,targ,15)
call SetTextTagColor(t,0,0,255,50)
call SetTextTagVelocity(t,.0355 * Cos(90 * bj_DEGTORAD),.0355 * Sin(90 * bj_DEGTORAD))
call SetTextTagLifespan(t,1.)
call UnitDamageTarget(cast,targ,dam,false,false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_COLD,null)
call PolledWait(1.)
call DestroyTextTag(t)
set t = null
endif
set targ = null
set cast = null
endfunction
function Auto_Attack_Detect_Actions takes nothing returns nothing
local trigger trig = CreateTrigger()
local triggeraction ta
local unit u
if GetTriggerEventId()==EVENT_UNIT_SPELL_EFFECT then
set u = GetSpellTargetUnit()
else
set u = GetTriggerUnit()
endif
call TriggerRegisterUnitEvent(trig,u, EVENT_UNIT_DAMAGED)
set ta = TriggerAddAction(trig, function Auto_Attack_Effects)
call PolledWait(2)
call DisableTrigger(trig)
call TriggerRemoveAction(trig,ta)
call DestroyTrigger(trig)
set ta = null
set u = null
set trig = null
endfunction
function InitTrig_Ether_Strike takes nothing returns nothing
set gg_trg_Ether_Strike = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ(gg_trg_Ether_Strike, EVENT_PLAYER_UNIT_ATTACKED)
//call TriggerRegisterAnyUnitEventBJ(gg_trg_Ether_Strike, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerRegisterUnitEvent(gg_trg_Ether_Strike,udg_u, EVENT_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_Ether_Strike, Condition(function Auto_Attack_Detect))
call TriggerAddAction(gg_trg_Ether_Strike, function Auto_Attack_Detect_Actions)
endfunction
Emanation is the caster of the ability, A000 the ability and B000 the effect
In the init trigger you can see my poor attempts to make the trigger work for the ability being cast by the user
Thanks in advance!
http://world-editor-tutorials.thehelper.net/cat_usersubmit.php?view=41266
I have two main problems:
First, the trigger needs to detect the auto ability either it was auto cast or cast by the user. The code for the second "trigger" in the int_trigger was wrong in the page, I have tried to fix it but it doesn't seem to work.
Second, the script doesn't work as I would like it to. If the target is changed and the ability is used, it works, the counter is reset, but if the target is changed and the ability is not used, the counter on the previous unit, the one hit by the ability, the counter would not reset and start from the number it stopped. I really can't figure out why. I think the problem is somehow in the Auto Attack Detect trigger. If the conditions are not met, meaning that the ability has not been cast, the counter should be reset. Somehow it doesn't! This is weird because the Auto Attack Detect should run every time a unit is hit, if I'm not mistaken! Here is the code:
function Auto_Attack_Detect takes nothing returns boolean
if GetTriggerEventId()==EVENT_PLAYER_UNIT_ATTACKED then
if (GetAttacker() == udg_Emanation) then
set udg_EtherStrikeNextTarget= GetTriggerUnit()
endif
if GetUnitAbilityLevel(GetAttacker(),'A000')>0 then
return true
endif
endif
if GetTriggerEventId()==EVENT_UNIT_SPELL_EFFECT and GetSpellAbilityId()=='A000' then
return true
endif
set udg_EtherStrikeCount = 0
return false
endfunction
function Auto_Attack_Effects takes nothing returns nothing
local real dam
local unit targ = GetTriggerUnit()
local unit cast = GetEventDamageSource()
local texttag t
if GetUnitAbilityLevel(targ,'B000')>0 and GetUnitAbilityLevel(cast,'A000')>0 then
call DisableTrigger(GetTriggeringTrigger())
if (udg_EtherStrikePreviousTarget==udg_EtherStrikeNextTarget) then
set udg_EtherStrikeCount = udg_EtherStrikeCount +1
else
set udg_EtherStrikeCount = 0
endif
set udg_EtherStrikePreviousTarget=udg_EtherStrikeNextTarget
set dam = (GetUnitAbilityLevel(cast,'A000')*5)*(1+(udg_EtherStrikeCount))
set t = CreateTextTag()
call SetTextTagText(t,"+"+I2S(R2I(dam)),.023)
call SetTextTagPosUnit(t,targ,15)
call SetTextTagColor(t,0,0,255,50)
call SetTextTagVelocity(t,.0355 * Cos(90 * bj_DEGTORAD),.0355 * Sin(90 * bj_DEGTORAD))
call SetTextTagLifespan(t,1.)
call UnitDamageTarget(cast,targ,dam,false,false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_COLD,null)
call PolledWait(1.)
call DestroyTextTag(t)
set t = null
endif
set targ = null
set cast = null
endfunction
function Auto_Attack_Detect_Actions takes nothing returns nothing
local trigger trig = CreateTrigger()
local triggeraction ta
local unit u
if GetTriggerEventId()==EVENT_UNIT_SPELL_EFFECT then
set u = GetSpellTargetUnit()
else
set u = GetTriggerUnit()
endif
call TriggerRegisterUnitEvent(trig,u, EVENT_UNIT_DAMAGED)
set ta = TriggerAddAction(trig, function Auto_Attack_Effects)
call PolledWait(2)
call DisableTrigger(trig)
call TriggerRemoveAction(trig,ta)
call DestroyTrigger(trig)
set ta = null
set u = null
set trig = null
endfunction
function InitTrig_Ether_Strike takes nothing returns nothing
set gg_trg_Ether_Strike = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ(gg_trg_Ether_Strike, EVENT_PLAYER_UNIT_ATTACKED)
//call TriggerRegisterAnyUnitEventBJ(gg_trg_Ether_Strike, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerRegisterUnitEvent(gg_trg_Ether_Strike,udg_u, EVENT_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_Ether_Strike, Condition(function Auto_Attack_Detect))
call TriggerAddAction(gg_trg_Ether_Strike, function Auto_Attack_Detect_Actions)
endfunction
Emanation is the caster of the ability, A000 the ability and B000 the effect
In the init trigger you can see my poor attempts to make the trigger work for the ability being cast by the user
Thanks in advance!