/*
Guerded Attack v 1.0 made by 'KhaosMachine'
Original idea by 'En_Tropy'
IF YOU WANT TO IMPORT THIS SPELL INTO YOUR MAP YOU HAVE TO COPY THE NEXT THINGS:
*********************************************************************************
TRIGGER EDITOR:
FOLDERS: NONE
TRIGGERS: Guarded Attack
OBJECT EDITOR:
UNITS: Dummy ('u000')
ABILITIES: Guarded Attack ('A000')
Guarded Attack ('A001')
Invisibility ('A002')
BUFFS: Guarded Attack ('B001')
*********************************************************************************
THEN YOU HAVE TO CONFIGURE THE SPELL:
OBVIOUSLY THINGS:
ABILITY_ID = RAWCODE OF THE SPELL
REDUCE_ABILITY_ID = RAWCODE OF THE SLOW SPELL
BUFF_ID = RAWCODE OF THE REDUCE ABILITY ABILITY BUFF
REDUCE_ABILITY_ORDER = STRING ORDER OF THE REDUCE ABILITY
ABILITY_INVISIBLE_ID = RAWCODE OF THE INVISIBILITY ABILITY
DUMMY_ID = RAWCODE OF THE DUMMY
*/
scope guardedAttack initializer init
/****************************************************/*************************************************************
|*** ***|
|** **|
|* *|
|====> ¡¡¡START OF THE CONFIGURATION!!! <====|
|* *|
|** **|
|*** ***|
|************************************************************/
globals
private constant integer ABILITY_ID = 'A000' //HERO ABILITY ID
private constant integer REDUCE_ABILITY_ID = 'A001' //REDUCE DAMAGE ABILITY ID
private constant integer BUFF_ID = 'B001' //REDUCE DAMAGE BUFF ID
private constant string REDUCE_ABILITY_ORDER = "innerfire" //REDUCE DAMAGE ABILITY ORDER
private constant integer ABILITY_INVISIBLE_ID = 'A002' //PERMANENT INVISIBILITY ID
private constant integer DUMMY_ID = 'u000' //DUMMY UNIT ID
private real FPS = 32 //FRAMES PER SECOND
endglobals
private constant function DURATION takes integer level returns real
return 6. + 2. * level//SPELL DURATION
endfunction
/****************************************************/*************************************************************
|*** ***|
|** **|
|* *|
|====> ¡¡¡END OF THE CONFIGURATION!!! <====|
|* *|
|** **|
|*** ***|
|************************************************************/
private struct DATA
unit target
real duration
endstruct
globals
private constant timer TIMER = CreateTimer()
private DATA array ARRAY
private integer TOTAL = 0
endglobals
private function action takes nothing returns nothing
local DATA D
local boolean DESTROY_DATA
local integer i = 0
loop
exitwhen i >= TOTAL
set D = ARRAY[i]
set D.duration = D.duration - FPS
set DESTROY_DATA = D.duration <= 0
if DESTROY_DATA then
call IssueImmediateOrder(D.target, "stop")
call UnitRemoveAbility(D.target, ABILITY_INVISIBLE_ID)
call UnitRemoveAbility(D.target, BUFF_ID)
set ARRAY[i] = ARRAY[TOTAL - 1]
set TOTAL = TOTAL - 1
call D.destroy()
endif
set i = i + 1
endloop
if TOTAL == 0 then
call PauseTimer(TIMER)
endif
endfunction
private function run takes nothing returns boolean
local DATA D
local unit caster
local unit dummy
local integer level
if GetSpellAbilityId() == ABILITY_ID then
set D = DATA.create()
set caster = GetTriggerUnit()
set level = GetUnitAbilityLevel(caster, ABILITY_ID)
call UnitAddAbility(caster, ABILITY_INVISIBLE_ID)
set D.target = caster
set D.duration = DURATION(level)
set dummy = CreateUnit(GetOwningPlayer(caster), DUMMY_ID, GetUnitX(caster), GetUnitY(caster), 0)
call UnitAddAbility(dummy, REDUCE_ABILITY_ID)
call SetUnitAbilityLevel(dummy, REDUCE_ABILITY_ID, level)
call IssueTargetOrder(dummy, REDUCE_ABILITY_ORDER, caster)
call UnitApplyTimedLife(dummy, 'BTLF', 0.5)
if TOTAL == 0 then
call TimerStart(TIMER, FPS, true, function action)
endif
set TOTAL = TOTAL + 1
set ARRAY[TOTAL - 1] = D
set caster = null
set dummy = null
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
local unit d
loop
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition(t, Condition(function run))
set FPS = 1 / FPS
set d = CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), DUMMY_ID, 0, 0, 0)
call UnitAddAbility(d, ABILITY_ID)
call UnitAddAbility(d, BUFF_ID)
call UnitAddAbility(d, REDUCE_ABILITY_ID)
call UnitAddAbility(d, ABILITY_INVISIBLE_ID)
call RemoveUnit(d)
set d = null
set t = null
endfunction
endscope