Issue is, the units spawned don't stay in the 400 range of the hero.
JASS:
scope IceEnergy
globals
private constant gamecache cache = InitGameCache("IceEnergies")
private constant integer SpellID = 039;A004039;
private constant integer DumID = 039;d000039;
private constant integer AbilID = 039;A003039;
private constant integer lvlskip = 1
private constant real frostRange = 600.0
private constant real frostDmg = 20.0
private constant real frostTime = 25.0
private constant real checkTime = 0.03
private constant real dmgAoE = 50.0
private constant real dmg = 0.05
private constant real moveSpeed = 15.0
private constant real moveArea = 400.0
private constant real height = 50.0
private constant real size = 1.00
private constant string energyMdl = "Abilities\\Weapons\\ZigguratFrostMissile\\ZigguratFrostMissile.mdl"
endglobals
private function H2I takes handle h returns integer
return h
return 0
endfunction
private function HS takes handle i returns string
return I2S(H2I(i))
endfunction
private function IsUnitNotImmun takes unit c,unit u returns boolean
return ((c!=u) and not IsUnitType(u,UNIT_TYPE_STRUCTURE) and not IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) and (IsUnitEnemy(u, GetOwningPlayer(c))==true) and (GetUnitState(u,UNIT_STATE_LIFE)>0.00))
endfunction
//=================== The struct =========================\\
private struct Missile
unit missile
unit caster
real angle
real dist
real tdist
integer special
real stime
real ttime
real lvl
effect mdl
timer t
method make takes real x, real y, real a,real h, real s, string m, player p, real l, unit c, real d returns nothing
set this.missile = CreateUnit(p,DumID,x,y,a)
call UnitAddAbility(this.missile,AbilID)
call SetUnitFlyHeight(this.missile,h,0)
set this.mdl = AddSpecialEffectTarget(m,this.missile,"chest")
call SetUnitScale(this.missile,s,s,s)
set this.angle = a
set this.caster = c
set this.dist = 0
set this.tdist = d
set this.stime = 0
set this.ttime = 0
set this.lvl = l
set this.t = CreateTimer()
call StoreInteger(cache,HS(this.t),"missile",this)
endmethod
method attack takes nothing returns nothing
local group g = CreateGroup()
local unit u
local unit t
local integer c = 0
local real x = GetUnitX(this.missile)
local real y = GetUnitY(this.missile)
if (GetUnitState(this.caster,UNIT_STATE_LIFE)>0) then
call GroupEnumUnitsInRange(g,x,y,dmgAoE,null)
loop
exitwhen (CountUnitsInGroup(g)<1)
set u = FirstOfGroup(g)
if IsUnitNotImmun(this.missile,u) then
call UnitDamageTarget(this.missile,u,(this.lvl*dmg),false,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_COLD,null)
endif
call GroupRemoveUnit(g,u)
endloop
call DestroyGroup(g)
if (this.ttime>=this.stime) then
call GroupEnumUnitsInRange(g,x,y,frostRange,null)
loop
exitwhen (CountUnitsInGroup(g)<1)
set u = FirstOfGroup(g)
if IsUnitNotImmun(this.missile,u) then
set c = c + 1
if (GetRandomInt(1,c)==1) then
set t = u
endif
endif
call GroupRemoveUnit(g,u)
endloop
if (t!=null) then
call SetUnitAbilityLevel(this.missile,AbilID,R2I(this.lvl))
call IssueTargetOrder(this.missile,"shadowstrike",t)
set this.ttime = this.ttime - this.stime
endif
else
set this.ttime = this.ttime + checkTime
endif
endif
call DestroyGroup(g)
set g = null
set u = null
set t = null
endmethod
method turn takes nothing returns nothing
local real x1 = GetUnitX(this.caster)
local real y1 = GetUnitY(this.caster)
local real x2 = GetRandomReal(x1-(moveArea*0.50),x1+(moveArea*0.50))
local real y2 = GetRandomReal(y1-(moveArea*0.50),y1+(moveArea*0.50))
set this.angle = bj_RADTODEG*Atan2(y2-y1,x2-x1)
set this.tdist = SquareRoot(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)))
set this.dist = 0
endmethod
method move takes real speed returns nothing
local real x1 = GetUnitX(this.missile)
local real y1 = GetUnitY(this.missile)
local real x2 = x1+speed*Cos(this.angle*bj_DEGTORAD)
local real y2 = y1+speed*Sin(this.angle*bj_DEGTORAD)
if ((RectContainsCoords(bj_mapInitialPlayableArea,x2,y2)==false) or (this.dist>=this.tdist)) then
call this.turn()
else
call SetUnitX(this.missile,x2)
call SetUnitY(this.missile,y2)
set this.dist = this.dist+speed
endif
call this.attack()
endmethod
method remove takes nothing returns nothing
call RemoveUnit(this.missile)
set this.missile = null
set this.caster = null
call DestroyEffect(this.mdl)
set this.mdl = null
call PauseTimer(this.t)
call FlushStoredMission(cache,HS(this.t))
call DestroyTimer(this.t)
set this.t = null
call this.destroy()
endmethod
endstruct
private function Conditions takes nothing returns boolean
return (GetLearnedSkill()==SpellID)
endfunction
private function MissileMotion takes nothing returns nothing
local timer t = GetExpiredTimer()
local Missile energy = GetStoredInteger(cache,HS(t),"missile")
set energy.lvl = I2R(GetUnitAbilityLevel(energy.caster,SpellID))
call energy.move(moveSpeed)
call TimerStart(t,checkTime,false,function MissileMotion)
set t = null
endfunction
private function CreateEnergy takes real x, real y, real a,real h, real s, string m, player p, real l, unit c, real d returns nothing
local Missile energy = Missile.create()
call energy.make(x,y,a,h,s,m,p,l,c,d)
set energy.stime = frostTime
call TimerStart(energy.t,checkTime,false,function MissileMotion)
endfunction
private function IceEnergiesActions takes nothing returns nothing
local real cx
local real cy
local real nx
local real ny
local real a
local real d
local player p
local unit u
local integer l
set u = GetTriggerUnit()
set p = GetOwningPlayer(u)
set l = GetUnitAbilityLevel(u,SpellID)
if ((l==1) or (ModuloInteger(l,lvlskip)==0)) then
set cx = GetUnitX(u)
set cy = GetUnitY(u)
set nx = GetRandomReal(cx-moveArea*0.50,cx+moveArea*0.50)
set ny = GetRandomReal(cy-moveArea*0.50,cy+moveArea*0.50)
set a = (bj_RADTODEG*Atan2(ny-cy,nx-cx))
set d = SquareRoot((nx-cx)*(nx-cx)+(ny-cy)*(ny-cy))
call CreateEnergy(cx,cy,a,height,size,energyMdl,p,I2R(l),u,d)
endif
set u = null
set p = null
endfunction
//===========================================================================
public function InitTrig takes nothing returns nothing
local trigger IceEnergy = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(IceEnergy,EVENT_PLAYER_HERO_SKILL)
call TriggerAddCondition(IceEnergy,Condition(function Conditions))
call TriggerAddAction(IceEnergy,function IceEnergiesActions)
endfunction
endscope