// Death Coil \\
// by: Carnerox \\
// credits to: \\
//Jesus4Lyf for SpellStruct, Damage, AIDS, and Event\\
// How to use import this spell:
// 1) Copy this trigger
// 2) Open your map, create a new trigger with the name "Death Coil".
// 3) Click Edit, and convert the trigger to custom text.
// 4) Copy the trigger, and paste it into the trigger.
// 5) Add all the systems that the spell uses.
// 6) Change the ABIL_ID, and DUMMY_ID to the correct rawcodes, and customize the spell to what you want.
scope DeathCoil
////////////////////////////////CONFIGURATION DATA!\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
globals
private constant integer ABIL_ID = 'A000' // Rawcode of the ability.
private constant integer DUMMY_ID = 'h000' // Rawcode of the obelisk.
private constant real PERIODIC = 0.01 // How often the timer will run the function.
private constant real COLOR_R = 100.00 // Lightning red
private constant real COLOR_G = 0.00 // Lightning green
private constant real COLOR_B = 0.00 // Lightning blue
private constant real COLOR_A = 10.00 // Lightning alpha
private constant real FLOAT = 45.00 // Lightning height
private constant string LIGHTNING_ID = "MFPB" // Lightning type - Mana Flare
private constant string EFFECT = "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl" //Effect when link snaps
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL //Attack type dealt
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_MAGIC //Damage type dealt
private constant boolean DAMAGE_MELEE = true //Is the damage melee?
private constant boolean DAMAGE_RANGED = false //Is the damage ranged?
private constant boolean SHARED_VISION = true //Is there shared vision of the Target?
endglobals
///////////////////// Do not change anything in this struct!\\\\\\\\\\\\\\\\\
private struct DeathCoil
static unit Caster
static unit Target
static unit Dummy
static player Owner
static lightning Lightning
static timer Timer=CreateTimer()
static integer Level
static real x
static real y
static real x1
static real x2
static real y1
static real y2
static real z1
static real z2
//How much damage is dealt to the Target
private static method Damage takes integer level returns real
return 50.00*level+25.00
endmethod
//Distance of how far the unit can move away from the Obelisk
private static method Distance takes integer level returns real
return 100*level+400.00
endmethod
//Duration of the Obelisk
private static method Duration takes integer level returns real
return 5.00*level+10.00
endmethod
//The z of the Obelisk, and Target
private static method GetUnitZ takes unit u returns real
local location Point=Location(GetUnitX(u),GetUnitY(u))
local real Real=GetLocationZ(Point)+GetUnitFlyHeight(u)
call RemoveLocation(Point)
set Point=null
return Real
endmethod
///////////////////////////END OF CONFIGURATION DATA!\\\\\\\\\\\\\\\\\\\\\\\
private static method periodic takes nothing returns nothing
set DeathCoil.x2=GetUnitX(DeathCoil.Target)
set DeathCoil.y2=GetUnitY(DeathCoil.Target)
set DeathCoil.z2=DeathCoil.GetUnitZ(DeathCoil.Target)+FLOAT
set DeathCoil.x=DeathCoil.x2-DeathCoil.x1
set DeathCoil.y=DeathCoil.y2-DeathCoil.y1
call MoveLightningEx(DeathCoil.Lightning,true,DeathCoil.x1,DeathCoil.y1,DeathCoil.z1,DeathCoil.x2,DeathCoil.y2,DeathCoil.z2)
if (SquareRoot(DeathCoil.x*DeathCoil.x+DeathCoil.y*DeathCoil.y)>=DeathCoil.Distance(DeathCoil.Level)) then
call PauseTimer(DeathCoil.Timer)
call DestroyTimer(DeathCoil.Timer)
call DestroyLightning(DeathCoil.Lightning)
call DestroyEffect(AddSpecialEffect(EFFECT,DeathCoil.x1,DeathCoil.y1))
call DestroyEffect(AddSpecialEffect(EFFECT,DeathCoil.x2,DeathCoil.y2))
call RemoveUnit(DeathCoil.Dummy)
call SetUnitX(DeathCoil.Target,DeathCoil.x1)
call SetUnitY(DeathCoil.Target,DeathCoil.y1)
static if (LIBRARY_Damage) then
call Damage_Spell(DeathCoil.Caster,DeathCoil.Target,DeathCoil.Damage(DeathCoil.Level))
else
call UnitDamageTarget(DeathCoil.Caster,DeathCoil.Target,DeathCoil.Damage(DeathCoil.Level),DAMAGE_MELEE,DAMAGE_RANGED,ATTACK_TYPE,DAMAGE_TYPE,null)
endif
if (SHARED_VISION==true) then
call UnitShareVision(DeathCoil.Target,DeathCoil.Owner,false)
endif
set DeathCoil.Caster=null
set DeathCoil.Target=null
set DeathCoil.Dummy=null
set DeathCoil.Lightning=null
set DeathCoil.Timer=null
elseif (IsUnitType(DeathCoil.Dummy,UNIT_TYPE_DEAD)==true) or (IsUnitType(DeathCoil.Target,UNIT_TYPE_DEAD)==true) then
call PauseTimer(DeathCoil.Timer)
call DestroyTimer(DeathCoil.Timer)
call DestroyLightning(DeathCoil.Lightning)
call DestroyEffect(AddSpecialEffect(EFFECT,DeathCoil.x1,DeathCoil.y1))
call RemoveUnit(DeathCoil.Dummy)
if (SHARED_VISION==true) then
call UnitShareVision(DeathCoil.Target,DeathCoil.Owner,false)
endif
set DeathCoil.Caster=null
set DeathCoil.Target=null
set DeathCoil.Dummy=null
set DeathCoil.Lightning=null
set DeathCoil.Timer=null
endif
endmethod
static method onCreate takes nothing returns nothing
local thistype dc=thistype.allocate()
set dc.Caster=GetTriggerUnit()
set dc.Target=GetSpellTargetUnit()
set dc.Owner=GetTriggerPlayer()
set dc.Level=GetUnitAbilityLevel(dc.Caster,ABIL_ID)
set dc.x2=GetUnitX(dc.Target)
set dc.y2=GetUnitY(dc.Target)
set dc.z2=GetUnitZ(dc.Target)+FLOAT
set dc.Dummy=CreateUnit(dc.Owner,DUMMY_ID,dc.x2,dc.y2,0.00)
set dc.x1=GetUnitX(dc.Dummy)
set dc.y1=GetUnitY(dc.Dummy)
set dc.z1=GetUnitZ(dc.Dummy)+FLOAT
set dc.Lightning=AddLightningEx(LIGHTNING_ID,true,dc.x1,dc.y1,dc.z1,dc.x2,dc.y2,dc.z2)
call UnitApplyTimedLife(dc.Dummy,'BTLF',DeathCoil.Duration(dc.Level))
call SetLightningColor(dc.Lightning,COLOR_R,COLOR_G,COLOR_B,COLOR_A)
if (SHARED_VISION==true) then
call UnitShareVision(dc.Target,dc.Owner,true)
endif
call TimerStart(dc.Timer,PERIODIC,true,function DeathCoil.periodic)
endmethod
endstruct
private function onCast takes nothing returns boolean
if (GetSpellAbilityId()==ABIL_ID) then
call DeathCoil.onCreate()
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger trig=CreateTrigger()
local integer index=0
loop
exitwhen index == bj_MAX_PLAYER_SLOTS
call TriggerRegisterPlayerUnitEvent(trig,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
set index=index+1
endloop
call TriggerAddCondition(trig,Condition(function onCast))
set trig=null
endfunction
endscope