How can I catch the ID of the used spell?
I have a trigger that activates if any of the 4 spells had been casted. However, I want to have different effects, depending on the spell casted. Therefore, I need to catch the spell ID in my conditions for if/then. I tried to do it like this, but it didn't work:
I have a trigger that activates if any of the 4 spells had been casted. However, I want to have different effects, depending on the spell casted. Therefore, I need to catch the spell ID in my conditions for if/then. I tried to do it like this, but it didn't work:
JASS:
function Trig_Viper_Mirage_R_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A00L' or GetSpellAbilityId() == 'A00O' or GetSpellAbilityId() == 'A00N' or GetSpellAbilityId() == 'A00P'
endfunction
function moveToTarget takes nothing returns nothing
timer t = GetExpiredTimer()
integer id = GetHandleId(t)
unit caster = LoadUnitHandle(Hash, id, StringHash("caster"))
unit dummy = LoadUnitHandle(Hash, id, StringHash("dummy"))
unit target = LoadUnitHandle(Hash, id, StringHash("target"))
real dummyX = GetUnitX(dummy)
real dummyY = GetUnitY(dummy)
real targetX = GetUnitX(target)
real targetY = GetUnitY(target)
real distance = GetDistanceBetweenCoordinates(dummyX, targetX, dummyY , targetY)
real dummyExp = LoadReal(Hash, id, StringHash("dummyExp")) + 1
call SaveReal(Hash, id, StringHash("dummyExp"), dummyExp)
boolean isNeedDestroyFunction = false
if dummyExp >= LoadReal(Hash, id, StringHash("MaxDummyLife"))/0.03125 then
KillUnit(dummy)
RemoveUnit(dummy)
isNeedDestroyFunction = true
elseif distance > 80 then
real angle = GetAngleBetweenPoints(dummyX, targetX, dummyY, targetY)
real xWithOffset = GetXWithOffset(dummyX, LoadReal(Hash, id, StringHash("speed")), angle)
real yWithOffset = GetYWithOffset(dummyY, LoadReal(Hash, id, StringHash("speed")), angle)
setUnitPosition(dummy, xWithOffset, yWithOffset)
else
KillUnit(dummy)
UnitDamageTarget(caster, target, 50, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_PLANT, null)
isNeedDestroyFunction = true
if LoadInteger(Hash, id, StringHash("spellid")) == 'A00L' then
BJDebugMsg("abilities")
elseif LoadInteger(Hash, id, StringHash("spellid")) == 'A00N' then
BJDebugMsg("move")
elseif LoadInteger(Hash, id, StringHash("spellid")) == 'A00P' then
BJDebugMsg("items")
elseif LoadInteger(Hash, id, StringHash("spellid")) == 'A00O' then
BJDebugMsg("attack")
endif
endif
caster = null
dummy = null
target = null
if isNeedDestroyFunction then
PauseTimer(t)
DestroyTimer(t)
FlushChildHashtable(Hash, id)
endif
t = null
endfunction
function startMove takes unit caster, unit dummy, unit target returns nothing
timer t = CreateTimer()
integer id = GetHandleId(t)
//Configurations
real dummyExp = 0.0
real MaxDummyLife = 4.0
real speed = 10.0
//
integer spellid = LoadInteger(Hash, id, StringHash("spellid"))
SaveInteger(Hash, id, StringHash("spellid"), spellid)
SaveReal(Hash, id, StringHash("MaxDummyLife"), MaxDummyLife)
SaveReal(Hash, id, StringHash("speed"), speed)
SaveReal(Hash, id, StringHash("dummyExp"), dummyExp)
SaveUnitHandle(Hash, id, StringHash("caster"), caster)
SaveUnitHandle(Hash, id, StringHash("dummy"), dummy)
SaveUnitHandle(Hash, id, StringHash("target"), target)
TimerStart(t, 0.03125, true, function moveToTarget)
caster = null
dummy = null
target = null
t = null
endfunction
function prepareMassAttack takes nothing returns nothing
timer t = GetExpiredTimer()
integer id = GetHandleId(t)
unit caster = LoadUnitHandle(Hash, id, StringHash("caster"))
player p = GetOwningPlayer(caster)
real x = GetUnitX(caster)
real y = GetUnitY(caster)
GroupEnumUnitsInRange(g, x, y, LoadReal(Hash, id, StringHash("aoe")), Base)
loop
E = FirstOfGroup(g)
exitwhen E == null
if Condition_Base(p, E) then
real targetX = GetUnitX(E)
real targetY = GetUnitY(E)
real angle = GetAngleBetweenPoints(x, targetX, y, targetY)
real xWithOffset = GetXWithOffset(x, LoadReal(Hash, id, StringHash("speed")), angle)
real yWithOffset = GetYWithOffset(y, LoadReal(Hash, id, StringHash("speed")), angle)
bj_lastCreatedUnit = CreateUnit(p, 'h004', xWithOffset, yWithOffset, angle)
call SetUnitPathing(bj_lastCreatedUnit, false)
startMove(caster, bj_lastCreatedUnit, E)
endif
GroupRemoveUnit(g, E)
endloop
caster = null
p = null
PauseTimer(t)
DestroyTimer(t)
FlushChildHashtable(Hash, id)
t = null
endfunction
function Trig_Viper_Mirage_R_Actions takes nothing returns nothing
timer t = CreateTimer()
integer id = GetHandleId(t)
unit caster = GetTriggerUnit()
integer spellid = GetSpellAbilityId()
//Configurations
real aoe = 1000
//
SaveReal(Hash, id, StringHash("aoe"), aoe)
SaveInteger(Hash, id, StringHash("spellid"), spellid)
SaveUnitHandle(Hash, id, StringHash("caster"), caster)
TimerStart(t, 0.1, false, function prepareMassAttack)
caster = null
t = null
endfunction
//===========================================================================
function InitTrig_Viper_Mirage_R takes nothing returns nothing
local trigger t = CreateTrigger()
local integer index = 0
loop
call TriggerRegisterPlayerUnitEvent(t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition( t, Condition( function Trig_Viper_Mirage_R_Conditions ) )
call TriggerAddAction( t, function Trig_Viper_Mirage_R_Actions )
set t = null
endfunction