Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ChargedLightningShield initializer init
globals
// Change this to the number of charges you want the lightning shield to have when it is cast
private constant integer CLS_ONCAST_CHARGES = 3
// Change this to the maximum number of charges the lightning shield can have (-1 for unlimited)
private constant integer CLS_MAX_CHARGES = 10
// Change this to the base damage of the orbs
private constant integer ORB_DAMAGE = 200
// Change this to the damage type of the lightning shield. You might want to make it ATTACK_TYPE_MAGIC
private constant attacktype CLS_DAMAGE_CLASS = ATTACK_TYPE_NORMAL
// Change this to true if you want the shield charges to stack
private constant boolean CLS_STACKS = false
// Change this to the ability code of the lightning shield
private constant integer CLS_ABILITY_CODE = 'A000'
// Change this to the buff code of the lightning shield
private constant integer CLS_BUFF_CODE = 'B000'
private hashtable chargesHashtable = InitHashtable()
private hashtable isAttackedHashtable = InitHashtable()
endglobals
private function unitIsAttacked takes nothing returns nothing
local unit attackee = GetTriggerUnit()
local unit attacker = GetAttacker()
local integer charges = LoadInteger(chargesHashtable, 0, GetHandleId(attackee))
local boolean hasBuff = (GetUnitAbilityLevel(attackee, CLS_BUFF_CODE) > 0)
set charges = charges - 1
if (not hasBuff or charges == 0) then
// The buff was dispelled or expired or it should be dispelled now
call SaveInteger(chargesHashtable, 0, GetHandleId(attackee), 0)
call DestroyTrigger(GetTriggeringTrigger())
call SaveTriggerHandle(isAttackedHashtable, 0, GetHandleId(attackee), null)
endif
if (hasBuff and charges == 0) then
call UnitRemoveAbility(attackee, CLS_BUFF_CODE)
endif
if (hasBuff) then
call UnitDamageTarget(attackee, attacker, ORB_DAMAGE, true, false, CLS_DAMAGE_CLASS, DAMAGE_TYPE_LIGHTNING, WEAPON_TYPE_WHOKNOWS)
endif
if (charges > 0) then
call SaveInteger(chargesHashtable, 0, GetHandleId(attackee), charges)
endif
set attackee = null
set attacker = null
endfunction
private function unitGainsCLS takes nothing returns nothing
local unit u = GetTriggerUnit()
local trigger t
local integer charges = CLS_ONCAST_CHARGES
set t = LoadTriggerHandle(isAttackedHashtable, 0, GetHandleId(u))
if (t == null) then
set t = CreateTrigger()
call TriggerAddAction(t, function unitIsAttacked)
call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ATTACKED)
call SaveTriggerHandle(isAttackedHashtable, 0, GetHandleId(u), t)
endif
if (CLS_STACKS and GetUnitAbilityLevel(u, CLS_BUFF_CODE) > 0) then
set charges = charges + LoadInteger(chargesHashtable, 0, GetHandleId(u))
endif
call SaveInteger(chargesHashtable, 0, GetHandleId(u), charges)
set t = null
set u = null
endfunction
private function unitGainsCLSFilter takes nothing returns boolean
return (GetSpellAbilityId() == CLS_ABILITY_CODE)
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, function unitGainsCLSFilter)
call TriggerAddAction(t, function unitGainsCLS)
set t = null
endfunction
endlibrary