sephiroth482
New Member
- Reaction score
- 0
This spell lags when casted too often, can someone please tell me where it is lagging? because im not sure how to fix it, here is the code:
Thanks
JASS:
scope ChargedArrow
globals
private constant integer SpellAbilityId=039;A006039;
private constant integer ArrowUnitId=039;e001039;
private constant real TimerInterval=0.03
private constant real ArrowMoveSpeed=30
private constant real MaxArrowDist=1800
private constant real ArrowAOE=200
private constant string DamageEffectString="Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl"
endglobals
private struct data
unit Caster
unit Arrow
location CasterLoc
location TargetLoc
real FacingAngle
endstruct
private function PickedUnitConditions takes nothing returns boolean
local timer t=GetExpiredTimer()
local data d=data(GetAttachedInt(t,"d"))
local boolean b1 = IsUnitAliveBJ(GetFilterUnit()) == true
local boolean b2 = IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(d.Caster)) == true
local boolean b3 = IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false
local boolean b4 = IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false
set t=null
return b1 and b2 and b3 and b4
endfunction
private function MoveArrow takes nothing returns nothing
local timer t=GetExpiredTimer()
local data d=data(GetAttachedInt(t,"d"))
local unit Target
local group g
local location ArrowLoc=GetUnitLoc(d.Arrow)
call CS_MoveUnitLoc(d.Arrow, PolarProjectionBJ(ArrowLoc, ArrowMoveSpeed, d.FacingAngle))
set g=GetUnitsInRangeOfLocMatching(ArrowAOE,ArrowLoc,Condition(function PickedUnitConditions))
loop
set Target = FirstOfGroup(g)
exitwhen Target == null
call UnitDamageTargetBJ(d.Caster,Target,GetRandomReal(400.00, 1200.00), ATTACK_TYPE_HERO, DAMAGE_TYPE_MAGIC)
call RemoveUnit(d.Arrow)
call GroupRemoveUnit(g, Target)
call DestroyGroup(g)
set Target=null
endloop
call RemoveLocation(GetUnitLoc(d.Arrow))
call RemoveLocation(ArrowLoc)
call DestroyGroup(g)
set Target=null
set ArrowLoc=null
set g=null
set t=null
endfunction
private function ChargedArrowActions takes nothing returns nothing
local timer t=CreateTimer()
local data d=data.create()
local location ArrowOrigin
local location ArrowLoc
local real ArrowCurrentDist
set d.Caster=GetTriggerUnit()
set d.CasterLoc=GetUnitLoc(d.Caster)
set d.TargetLoc=GetSpellTargetLoc()
set d.FacingAngle=AngleBetweenPoints(d.CasterLoc,d.TargetLoc)
set d.Arrow=CreateUnitAtLoc(GetOwningPlayer(d.Caster),ArrowUnitId,d.CasterLoc,d.FacingAngle)
set ArrowOrigin=GetUnitLoc(d.Caster)
call AttachInt(t,"d",d)
call TimerStart(t, TimerInterval,true,function MoveArrow)
loop
set ArrowLoc=GetUnitLoc(d.Arrow)
set ArrowCurrentDist=DistanceBetweenPoints(ArrowOrigin,ArrowLoc)
call RemoveLocation(GetUnitLoc(d.Arrow))
call RemoveLocation(ArrowLoc)
exitwhen ArrowCurrentDist>=MaxArrowDist or d.Arrow==null
call TriggerSleepAction(0)
endloop
call RemoveUnit(d.Arrow)
call RemoveLocation(GetUnitLoc(d.Caster))
call RemoveLocation(GetSpellTargetLoc())
call RemoveLocation(ArrowOrigin)
call CleanAttachedVars(t)
call DestroyTimer(t)
call data.destroy(d)
set ArrowOrigin=null
set ArrowLoc=null
set t=null
endfunction
function ChargedArrowConditions takes nothing returns boolean
return GetSpellAbilityId()==SpellAbilityId
endfunction
function InitTrig_Charged_Arrow takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition( t, Condition( function ChargedArrowConditions))
call TriggerAddAction(t, function ChargedArrowActions)
endfunction
endscope
Thanks