Moderator
M
Moderator
Trap Lightning v1.2 | Reviewed by Maker | 11th Oct 2013 | ||||
APPROVED | ||||
|
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
// T R A P L I G H T N I N G
// - Spell Create By:
// + Elphis
//*************************************************************************************
library TrapLightning /*
*/ requires /*
// -*/ TimerUtils /* http://www.wc3c.net/showthread.php?t=101322
// -*/ SpellEffectEvent /* http://www.hiveworkshop.com/forums/jass-resources-412/snippet-spelleffectevent-187193/
// -*/ xedamage /* http://www.wc3c.net/showthread.php?t=101150
// -*/ AbilityPreload /* http://www.wc3c.net/showthread.php?t=101150 */
// Optional:
// GreatLightning.mdx - http://www.hiveworkshop.com/forums/models-530/great-lightning-66381/?prev=search%3DGreat%2520L%26d%3Dlist%26r%3D20
// BoundSentinel - http://www.wc3c.net/showthread.php?t=102576 (You must adding it, this library help you prevent crash the game when lightning outside XY of map.
//*************************************************************************************
// - Spell Information:
// - Use power of lightning call Globe Electric fall out the sky, when it hit a ground,it explore
// explosion caused a power deals 40/80/120/160 damage to enemies unit in 500 range
// and stun them in 1/1.5/2/2.5|r seconds
// it'll create 2 magnetic balls, it will absorb the force of the ground and launched an intense power
// when enemies inside that AOE
// electric current will deals 20/40/60/80 damage to them and when those balls go 1 round
// it caused explotion again and deals 40/80/120/160 damage to enemies unit and stun them 1/1.5/2/2.5 seconds
//*************************************************************************************
// - Installation:
// - Import/copy the required libraries and Trap Lightning code to your map
// - Import/copy the custom ability and unit to your map and change the SPELL_ID, SPELL_STUN if needed
// - You may view the raw ID of the objects by pressing CTRL+D in the object editor
// - You may play with the configurables below
//*************************************************************************************
//
globals
//Periodic for this spell
private constant real PERIODIC = 0.031250000
//Spell rawcode, change if needed
private constant integer SPELL_ID = 'A000'
//Spell stun rawcode, change if needed
private constant integer SPELL_STUN = 'A001'
//Dummy Lightning rawcode, change if needed
private constant integer LIGHTNING_DUMMY = 'e000'
//Ability allow unit fly
private constant integer ABI_FLY = 'Amrf'
//Size of lightning
private constant real TRAP_SIZE = 2.
//Value effect and damage between 2 orb of lightning, this value must be divisible by two
private constant integer DATA_COUNT = 6
//Height of lightning
private constant real HEIGHT = 800.
//Circle max distance
private constant real CIRCLE_DISTANCE = 700.
//Max distance of trap
private constant real MAX_DIS_BASE = 500.
//Base damage of trap
private constant real DAMAGE_BASE = 20.
//Damage radius of trap when enemies inside, do not increase too much because it's very powerful, you know ?
private constant real DAMAGE_RADIUS = 50.
//Damage radius when lightning hit a ground and lightning disapear
private constant real EXPIRE_RADIUS = 500.
//Trap fall out speed
private constant real TRAP_SPEED = 50.
//Trap sort speed
private constant real TRAP_SORT = 20.
//Min height of lightning
private constant real MIN_HEIGHT = 50.
//Trap angle
private constant real TRAP_ANGLE = -90.
//Trap max rotation angle (Spell expire when reach this value also, if you increase it, this spell will go many round
//For Example:
//1 round = 360. => spell expire when go 1 round, 720 = 2 round => spell expire when go 2 round :)
private constant real TRAP_MAX_ROT = 360.
//Damage and effect intevar
private constant real TRAP_INTEVAR = 0.15
//Trap rotation speed.
private constant real TRAP_ROTATION = 2.
//Lightning Model
private constant string MODEL = "Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl"
//Lightning flush when the trap moving
private constant string FLUSH_MODEL = "Abilities\\Weapons\\Bolt\\BoltImpact.mdl"
//Lighning effect when spell expire
private constant string EFFECT_EXPIRE = "war3mapImported\\Great Lightning.mdx"
//Attachment of Trap
private constant string ATTACH = "origin"
//Lightning model
private constant string LIGHTNING_MODEL = "CLPB"
//Order of ability stun
private constant string ORDER_SLAM = "stomp"
//
private constant boolean DAMAGE_TREE = true
// =ATTACK DAMAGE WEAPON TYPE SETTINGHS=
private constant attacktype ATTACKTYPE = ATTACK_TYPE_HERO
private constant damagetype DAMAGETYPE = DAMAGE_TYPE_COLD
private constant weapontype WEAPONTYPE = WEAPON_TYPE_METAL_HEAVY_BASH
//
endglobals
//
private struct TrapLightning
//
//
//lightning
lightning ll
lightning lr
//unit
unit caster
unit dummy
unit dummyleft
unit dummyright
//player
player p
//real
real xx
real yy
real h
real r = 0.
real al = 0.
real ar = 0.
real in = 0.
real maxdis
real dam
//xedamage installing
xedamage xed
//
static method onDamage takes unit caster returns real
return DAMAGE_BASE*GetUnitAbilityLevel(caster,SPELL_ID) //Damage of spell
endmethod
//
static method distanceInc takes unit caster returns real
return 100.*GetUnitAbilityLevel(caster,SPELL_ID)+MAX_DIS_BASE //Max distance of trap lightning effective
endmethod
//
static method onPeriodic takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
//
local real logic
local real di = 0.
//
local real x
local real y
//
local integer i = 1
//
if h > MIN_HEIGHT then
//
//Decrease height of lightning fall out the sky
//
set h = h - TRAP_SPEED
//
call SetUnitFlyHeight(dummy,h,0.)
//
elseif dummyleft == null then
//
//Slam ground
call IssueImmediateOrder(dummy,ORDER_SLAM)
//This line deals damage to enemies unit when lightning hit ground
call xed.damageAOE(caster,xx,yy,EXPIRE_RADIUS,dam*2)
//Begin create a mini lightning
set dummyleft = CreateUnit(p,LIGHTNING_DUMMY,xx,yy,0.)
call SetUnitScale(dummyleft,TRAP_SIZE/2,0.,0.)
set ll = AddLightning(LIGHTNING_MODEL,true,xx,yy,xx,yy)
//Begin create a mini lightning
set dummyright = CreateUnit(p,LIGHTNING_DUMMY,xx,yy,0.)
call SetUnitScale(dummyright,TRAP_SIZE/2,0.,0.)
set lr = AddLightning(LIGHTNING_MODEL,true,xx,yy,xx,yy)
//
else
if r < maxdis and ar < TRAP_MAX_ROT then
set r = r + TRAP_SORT
//
set x = GetWidgetX(dummyleft) + TRAP_SORT * Cos(.01747*TRAP_ANGLE)
set y = GetWidgetY(dummyleft) + TRAP_SORT * Sin(.01747*TRAP_ANGLE)
//
call SetUnitX(dummyleft,x)
call SetUnitY(dummyleft,y)
call MoveLightning(ll,true,x,y,xx,yy)
call SetUnitX(dummyright,x)
call SetUnitY(dummyright,y)
call MoveLightning(lr,true,x,y,xx,yy)
else
if ar < TRAP_MAX_ROT then
//
//
set ar = ar + TRAP_ROTATION
set al = al - TRAP_ROTATION
//
set x = GetWidgetX(dummy) + maxdis * Cos((TRAP_ANGLE-ar)*.01747)
set y = GetWidgetY(dummy) + maxdis * Sin((TRAP_ANGLE-ar)*.01747)
//
call SetUnitX(dummyleft,x)
call SetUnitY(dummyleft,y)
call MoveLightning(ll,true,x,y,xx,yy)
//
set x = GetWidgetX(dummy) + maxdis * Cos((TRAP_ANGLE-al)*.01747)
set y = GetWidgetY(dummy) + maxdis * Sin((TRAP_ANGLE-al)*.01747)
//
call SetUnitX(dummyright,x)
call SetUnitY(dummyright,y)
call MoveLightning(lr,true,x,y,xx,yy)
//
if in < TRAP_INTEVAR then
set in = in + PERIODIC
else
set in = 0.
//
set logic = maxdis/DATA_COUNT
//
loop
exitwhen i > DATA_COUNT
//
set x = xx + di * Cos((TRAP_ANGLE-ar)*.01747)
set y = yy + di * Sin((TRAP_ANGLE-ar)*.01747)
//
call DestroyEffect(AddSpecialEffect(FLUSH_MODEL,x,y))
//
//This line deals damage to enmies unit (Left)
call xed.damageAOE(caster,x,y,DAMAGE_RADIUS,dam)
//
set x = xx + di * Cos((TRAP_ANGLE-al)*.01747)
set y = yy + di * Sin((TRAP_ANGLE-al)*.01747)
//
call DestroyEffect(AddSpecialEffect(FLUSH_MODEL,x,y))
//
//This line deals damage to enmies unit (Right)
call xed.damageAOE(caster,x,y,DAMAGE_RADIUS,dam)
//
set di = di + logic
//
set i = i + 1
endloop
endif
//
else
if r > 0. then
set r = r - TRAP_SORT
//
set x = GetWidgetX(dummyleft) - TRAP_SORT * Cos(.01747*TRAP_ANGLE)
set y = GetWidgetY(dummyleft) - TRAP_SORT * Sin(.01747*TRAP_ANGLE)
//
call SetUnitX(dummyleft,x)
call SetUnitY(dummyleft,y)
call MoveLightning(ll,true,x,y,xx,yy)
call SetUnitX(dummyright,x)
call SetUnitY(dummyright,y)
call MoveLightning(lr,true,x,y,xx,yy)
else
//Clean data
call xed.damageAOE(caster,xx,yy,EXPIRE_RADIUS,dam*2)
//Slam ground
call IssueImmediateOrder(dummy,ORDER_SLAM)
call ReleaseTimer(t)
call DestroyEffect(AddSpecialEffect(EFFECT_EXPIRE,xx,yy))
call DestroyLightning(ll)
call DestroyLightning(lr)
call RemoveUnit(dummyleft)
call RemoveUnit(dummyright)
call RemoveUnit(dummy)
//
set caster = null
set dummy = null
set dummyright = null
set dummyleft = null
set p = null
set ll = null
set lr = null
//
call xed.destroy()
call destroy()
endif
endif
endif
endif
//
set t = null
//
endmethod
//
static method onCast takes nothing returns nothing
local thistype this = allocate()
//
set caster = GetTriggerUnit()
set p = GetTriggerPlayer()
set h = HEIGHT
set xed = xedamage.create()
//Damage settings
set xed = xedamage.create()
set xed.dtype = DAMAGETYPE
set xed.atype = ATTACKTYPE
set xed.wtype = WEAPONTYPE
set xed.exception = UNIT_TYPE_STRUCTURE
set xed.damageEnemies = true
set xed.damageTrees = DAMAGE_TREE
//
//Max distance configuration
set maxdis = distanceInc(caster)
//Damage configuration
set dam = onDamage(caster)
//
set dummy = CreateUnit(p,LIGHTNING_DUMMY,GetSpellTargetX(),GetSpellTargetY(),0.)
if UnitAddAbility(dummy,ABI_FLY) then
call UnitRemoveAbility(dummy,ABI_FLY)
endif
call SetUnitScale(dummy,TRAP_SIZE,0.,0.)
//Add ability stun to this dummy and also set ability level = ability caster
call SetUnitAbilityLevel(dummy,SPELL_STUN,GetUnitAbilityLevel(caster,SPELL_ID))
//
set xx = GetWidgetX(dummy)
set yy = GetWidgetY(dummy)
//Calling Periodic
call TimerStart(NewTimerEx(this),PERIODIC,true,function thistype.onPeriodic)
endmethod
static method onInit takes nothing returns nothing
call Preload(FLUSH_MODEL)
call AbilityPreload(SPELL_ID)
call RegisterSpellEffectEvent(SPELL_ID,function thistype.onCast)
endmethod
endstruct
//
endlibrary[/HIDDEN]