Just a function that I worked hard on. When you call it, it creates a locust-like unit that follows its master and attacks only when the master attacks something. The locust unit is invulnerable and has a duration.
It's not a spell on its own, but can be used to make interesting spells. I'm using it on a passive spell that creates spiders when the hero kills a unit. It can also be used to make a Locust Swarm spell, with locusts only attacking the target of the attacks of their master.
Every locust unit is 100% independant of other locust units, but not independant of it's master. They die when the master dies.
A locust unit moves to some random place between 50 and 250 range of it's master, every 1.5 seconds. It stops attacking after 2 seconds of the last attack of it's master.
It don't steals any life, and when the duration ends, it just dies.
Pre-requisites:
KaTTaNa's Local Handle Variables
A unit, duplicated from the original locust unit, with 0 acquisition range.
Actually you can make any modifications to the unit, but it MUST have the locust ability and 0 acquisition range. Workarounds are possible (like not giving it the locust ability, but then somehow you must prevent order giving). They are not in this function. A similar function is Vexorian's Indie Summons.
Usage:
owner (unit): the master of the unit
'UNITID' (integer): the id (like 'u001') of the unit. The locust unit will be this unit
x (real): the x coordinate where the locust will be created
y (real): the y coordinate where the locust will be created
duration (real): the duration of the unit
If you have suggestions or tips on how to improve this function they will be welcomed.
You can use this function modified in any way, without giving credit (but credit is always welcomed), as long as you don't claim it as your own.
Changelog:
· Added spaces and breaks to make a more easy to understand code. Comments are also added in the commonly editable parts so it's even easier.
· Optimized a few things (thanks to SFilip).
· Made it so that it returns a unit, to make tracking a single locust unit outside the function possible.
It's not a spell on its own, but can be used to make interesting spells. I'm using it on a passive spell that creates spiders when the hero kills a unit. It can also be used to make a Locust Swarm spell, with locusts only attacking the target of the attacks of their master.
Every locust unit is 100% independant of other locust units, but not independant of it's master. They die when the master dies.
A locust unit moves to some random place between 50 and 250 range of it's master, every 1.5 seconds. It stops attacking after 2 seconds of the last attack of it's master.
It don't steals any life, and when the duration ends, it just dies.
Pre-requisites:
KaTTaNa's Local Handle Variables
A unit, duplicated from the original locust unit, with 0 acquisition range.
Actually you can make any modifications to the unit, but it MUST have the locust ability and 0 acquisition range. Workarounds are possible (like not giving it the locust ability, but then somehow you must prevent order giving). They are not in this function. A similar function is Vexorian's Indie Summons.
Usage:
JASS:
call Locust(owner,039;UNITID039;,x,y,duration)
owner (unit): the master of the unit
'UNITID' (integer): the id (like 'u001') of the unit. The locust unit will be this unit
x (real): the x coordinate where the locust will be created
y (real): the y coordinate where the locust will be created
duration (real): the duration of the unit
If you have suggestions or tips on how to improve this function they will be welcomed.
You can use this function modified in any way, without giving credit (but credit is always welcomed), as long as you don't claim it as your own.
JASS:
function LocMove takes nothing returns nothing
local timer t=GetExpiredTimer()
local unit o=GetHandleUnit(t,"powner")
local unit p=GetHandleUnit(t,"punit")
local location l=PolarProjectionBJ(GetUnitLoc(o),GetRandomReal(50,250),GetRandomReal(1,360)) //edit the first 'GetRandomReal' to change the locations around the master where the locust will wander
local real x=GetLocationX(l)
local real y=GetLocationY(l)
if GetUnitState(o,UNIT_STATE_LIFE)<0.405 then
call KillUnit(p)
else
call IssuePointOrder(p,"move",x,y)
call TimerStart(t,1.5,false,function LocMove) //edit the number to change how often (in seconds) the locust will refresh it's position.
endif
set t=null
set o=null
set p=null
call RemoveLocation(l)
set l=null
endfunction
function LocAttack takes nothing returns nothing
local unit p=GetHandleUnit(GetTriggeringTrigger(),"punit")
local timer t=GetHandleTimer(p,"ptimer")
local unit g=GetAttacker()
local unit r=GetTriggerUnit()
local unit o=GetHandleUnit(GetTriggeringTrigger(),"powner")
if g==o then
call PauseTimer(t)
call TimerStart(t,2,false,function LocMove) //edit the number to change how many seconds after the last master's attack the locusts will keep attacking
call IssueTargetOrder(p,"attack",r)
endif
set p=null
set t=null
set g=null
set r=null
set o=null
endfunction
function LocDeath takes nothing returns nothing
local unit u=GetTriggerUnit()
local trigger s=GetTriggeringTrigger()
local trigger a=GetHandleTrigger(s,"ptratt")
local timer t=GetHandleTimer(s,"ptrtim")
call SetHandleHandle(t,"powner",null)
call SetHandleHandle(t,"punit",null)
call SetHandleHandle(a,"punit",null)
call SetHandleHandle(u,"ptimer",null)
call SetHandleHandle(a,"powner",null)
call DestroyTrigger(a)
call PauseTimer(t)
call DestroyTimer(t)
call DestroyTrigger(s)
set u=null
set s=null
set a=null
set t=null
endfunction
function Locust takes unit o, integer unitid, real x, real y, real d returns unit
local player p=GetOwningPlayer(o)
local unit u
local trigger t
local timer ti
local trigger tr
set u=CreateUnit(p,unitid,x,y,0)
call UnitApplyTimedLife(u,039;BTLF039;,d) //you can remove this line if you want the locusts to be permanent
set ti=CreateTimer()
call TimerStart(ti,0,false,function LocMove)
call SetHandleHandle(u,"ptimer",ti)
call SetHandleHandle(ti,"punit",u)
call SetHandleHandle(ti,"powner",o)
set t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddAction(t,function LocAttack)
call SetHandleHandle(t,"punit",u)
call SetHandleHandle(t,"powner",o)
set tr=CreateTrigger()
call TriggerAddAction(tr,function LocDeath)
call TriggerRegisterUnitEvent(tr,u,EVENT_UNIT_DEATH)
call SetHandleHandle(tr,"ptratt",t)
call SetHandleHandle(tr,"ptrtim",ti)
return u
endfunction
Changelog:
· Added spaces and breaks to make a more easy to understand code. Comments are also added in the commonly editable parts so it's even easier.
· Optimized a few things (thanks to SFilip).
· Made it so that it returns a unit, to make tracking a single locust unit outside the function possible.