JASS:
scope mark
globals
private constant integer ABIL_ID = 'A001'
private constant integer BUFF_ID = 'A003'
private constant string EFFECT = "Abilities\\Spells\\Human\\MagicSentry\\MagicSentryCaster.mdl"
endglobals
struct Target
unit targ
real level
static method create takes unit targ, real level returns Target
local Target t = Target.allocate()
set t.targ = target
set t.level= level
return t
endmethod
method onDestroy takes nothing returns nothing
call Target.destroy(targ)
call Target.destroy(level)
endmethod
endstruct
function Trig_Mark_Conditions takes nothing returns boolean
return GetSpellAbilityId() == ABIL_ID
endfunction
function remove takes nothing returns nothing
local real getlev = GetUnitAbilityLevel(trig,ABIL_ID)
local unit sptarg = GetSpellTargetUnit()
local Target t = Target.create(sptarg,getlev)
set t = GetExpiredTimer()
call UnitRemoveAbility(t.targ,BUFF_ID)
call Target.destroy()
call DestroyTimer(t)
set sptarg = null
endfunction
function Trig_Mark_Actions takes nothing returns nothing
local unit sptarg = GetSpellTargetUnit()
local unit trig = GetTriggerUnit()
local real getlev = GetUnitAbilityLevel(trig,ABIL_ID)
local timer time = CreateTimer()
local Target t = Target.create(sptarg,getlev)
if GetUnitAbilityLevel(t.targ, BUFF_ID) < 1 then
call UnitAddAbility(t.targ,BUFF_ID)
call TimerStart(t, t.level*10,false,function remove)
endif
set sptarg = null
call Target.destroy()
set trig = null
endfunction
//===========================================================================
function InitTrig_Mark takes nothing returns nothing
set gg_trg_Mark = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Mark, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Mark, Condition( function Trig_Mark_Conditions ) )
call TriggerAddAction( gg_trg_Mark, function Trig_Mark_Actions )
endfunction
endscope
The spell is supposed to first check if the unit has a certain buff, if not, then apply one.
Anyway I'm trying to learn structs and timers but obviously I still have a lot to learn because this got a lot of errors.