Name | Type | is_array | initial_value |
unit | unit | No | |
UnitMovingPointActiveInd | integer | No | |
UnitMovingPointReached | boolean | Yes | |
X | real | No | |
Y | real | No |
library TimedHandles uses optional TimerUtils
/**************************************************************
*
* v1.0.5 by TriggerHappy
* ----------------------
*
* Use this to destroy a handle after X amount seconds.
*
* It's useful for things like effects where you may
* want it to be temporary, but not have to worry
* about the cleaning memory leak. By default it supports
* effects, lightning, weathereffect, items, ubersplats, and units.
*
* If you want to add your own handle types copy a textmacro line
* at the bottom and add whichever handle you want along with it's destructor.
*
* Example: //! runtextmacro TIMEDHANDLES("handle", "DestroyHandle")
*
* Installation
----------------------
* 1. Copy this script and over to your map inside a blank trigger.
* 2. If you want more efficiency copy TimerUtils over as well.
*
* API
* ----------------------
* call DestroyEffectTimed(AddSpecialEffect("effect.mdx", 0, 0), 5)
* call DestroyLightningTimed(AddLightning("CLPB", true, 0, 0, 100, 100), 5)
*
* Credits to Vexorian for TimerUtils and his help on the script.
*
**************************************************************/
globals
// If you don't want a timer to be ran each instance
// set this to true.
private constant boolean SINGLE_TIMER = true
// If you chose a single timer then this will be the speed
// at which the timer will update
private constant real UPDATE_PERIOD = 0.05
endglobals
// here you may add or remove handle types
//! runtextmacro TIMEDHANDLES("effect", "DestroyEffect")
//! runtextmacro TIMEDHANDLES("lightning", "DestroyLightning")
//! runtextmacro TIMEDHANDLES("weathereffect", "RemoveWeatherEffect")
//! runtextmacro TIMEDHANDLES("item", "RemoveItem")
//! runtextmacro TIMEDHANDLES("unit", "RemoveUnit")
//! runtextmacro TIMEDHANDLES("ubersplat", "DestroyUbersplat")
// Do not edit below this line
//! textmacro TIMEDHANDLES takes HANDLE,DESTROY
struct $HANDLE$Timed
$HANDLE$ $HANDLE$_var
static integer index = -1
static thistype array instance
static real REAL=UPDATE_PERIOD
static if SINGLE_TIMER then
static timer timer = CreateTimer()
real duration
real elapsed = 0
else static if not LIBRARY.TimerUtils then
static hashtable table = InitHashtable()
endif
method destroy takes nothing returns nothing
call $DESTROY$(this.$HANDLE$_var)
set this.$HANDLE$_var = null
static if SINGLE_TIMER then
set this.elapsed = 0
endif
call this.deallocate()
endmethod
private static method remove takes nothing returns nothing
static if SINGLE_TIMER then
local integer i = 0
local thistype this
loop
exitwhen i > thistype.index
set this = instance[i]
set this.elapsed = this.elapsed + UPDATE_PERIOD
if (this.elapsed >= this.duration) then
set instance[i] = instance[index]
set i = i - 1
set index = index - 1
call this.destroy()
if (index == -1) then
call PauseTimer(thistype.timer)
endif
endif
set i = i + 1
endloop
else
local timer t = GetExpiredTimer()
static if LIBRARY.TimerUtils then
local $HANDLE$Timed this = GetTimerData(t)
call ReleaseTimer(t)
call this.destroy()
else
local $HANDLE$Timed this = LoadInteger(table, 0, GetHandleId(t))
call DestroyTimer(t)
set t = null
call this.destroy()
endif
endif
endmethod
static method create takes $HANDLE$ h, real timeout returns $HANDLE$Timed
local $HANDLE$Timed this = $HANDLE$Timed.allocate()
static if SINGLE_TIMER then
set index = index + 1
set instance[index] = this
if (index == 0) then
call TimerStart(thistype.timer, UPDATE_PERIOD, true, function thistype.remove)
endif
set this.duration = timeout
else
static if LIBRARY.TimerUtils then
call TimerStart(NewTimerEx(this), timeout, false, function $HANDLE$timed.remove)
else
local timer t = CreateTimer()
call SaveInteger(thistype.table, 0, GetHandleId(t), this)
call TimerStart(t, timeout, false, function $HANDLE$Timed.remove)
set t = null
endif
endif
set this.$HANDLE$_var = h
return this
endmethod
endstruct
function $DESTROY$Timed takes $HANDLE$ h, real duration returns $HANDLE$Timed
return $HANDLE$Timed.create(h, duration)
endfunction
//! endtextmacro
endlibrary
//system made by deadreyo. have fun!
library UnitMovingPointSystem initializer Unit_Movement_SystemInit
globals
unit array UnitMovingPointU
real array UnitMovingPointX
real array UnitMovingPointY
real array UnitMovingPointSpeed
real array UnitMovingPointRangeCheck
real array UnitMovingPointHeight
real array UnitMovingPointDistance
boolean array UnitMovingPointFirstTarget
real array UnitMovingPointDamageDuringPath
real array UnitMovingPointCollisionSize
trigger array UnitMovingPointCollisionTrig
boolean array UnitMovingPointExplodeInEnd
real array UnitMovingPointExplodeDamage
real array UnitMovingPointExplodeAoE
trigger array UnitMovingPointEndingTrig
string array UnitMovingPointExplodeSFX
boolean array UnitMovingPointRemove
boolean array UnitMovingPointEnd
boolean array UnitMovingPointReached
integer UnitMovingPointInd = 0
integer UnitMovingPointActiveInd = 0
endglobals
function UnitMovingPointRun takes nothing returns nothing
local integer i2 = 0
local integer i = 0
local group g = null
local unit u2 = null
local location l = null
local location l2 = null
local boolean bo = false
local real x = 0
local real y = 0
local real d = 0
loop
exitwhen i > UnitMovingPointInd
if UnitMovingPointU[i] != null then
set x = GetUnitX(UnitMovingPointU[i])
set y = GetUnitY(UnitMovingPointU[i])
if IsUnitInRangeXY(UnitMovingPointU[i],UnitMovingPointX[i],UnitMovingPointY[i],UnitMovingPointRangeCheck[i]) then
set UnitMovingPointReached[i] = true
if UnitMovingPointExplodeInEnd[i] then
call DestroyEffectTimed(AddSpecialEffect(UnitMovingPointExplodeSFX[i], x, y), 5)
set g = CreateGroup()
call GroupEnumUnitsInRange(g,x,y,UnitMovingPointExplodeAoE[i],null)
loop
exitwhen BlzGroupGetSize(g) == 0
set u2 = FirstOfGroup(g)
if IsUnitEnemy(u2,GetOwningPlayer(UnitMovingPointU[i])) and GetUnitState(u2,UNIT_STATE_LIFE) > 0 then
call UnitDamageTarget(UnitMovingPointU[i],u2,UnitMovingPointExplodeDamage[i],false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null)
endif
call GroupRemoveUnit(g,u2)
endloop
call DestroyGroup(g)
endif
if UnitMovingPointEndingTrig[i] != null then
set UnitMovingPointActiveInd = i
call TriggerExecute(UnitMovingPointEndingTrig[i])
endif
if UnitMovingPointRemove[i] then
call RemoveUnit(UnitMovingPointU[i])
set UnitMovingPointU[i] = null
endif
if UnitMovingPointEnd[i] then
set UnitMovingPointU[i] = null
endif
loop
exitwhen i2 > UnitMovingPointInd
if UnitMovingPointU[i2] != null then
set bo = true
endif
set i2 = i2 + 1
endloop
if bo == false then
set UnitMovingPointInd = 0
endif
else
set l = Location(x,y)
set l2 = Location(UnitMovingPointX[i],UnitMovingPointY[i])
call SetUnitX(UnitMovingPointU[i], x + UnitMovingPointSpeed[i] * Cos(AngleBetweenPoints(l,l2) * bj_DEGTORAD))
call SetUnitY(UnitMovingPointU[i], y + UnitMovingPointSpeed[i] * Sin(AngleBetweenPoints(l,l2) * bj_DEGTORAD))
set d = SquareRoot(Pow((GetUnitX(UnitMovingPointU[i])-UnitMovingPointX[i]),2)+Pow((GetUnitY(UnitMovingPointU[i])-UnitMovingPointY[i]),2))
call SetUnitFlyHeight(UnitMovingPointU[i],UnitMovingPointHeight[i]*Sin(bj_PI*d/UnitMovingPointDistance[i]),0.0)
call RemoveLocation(l)
call RemoveLocation(l2)
if UnitMovingPointCollisionSize[i] != 0 then
set g = CreateGroup()
call GroupEnumUnitsInRange(g,GetUnitX(UnitMovingPointU[i]),GetUnitY(UnitMovingPointU[i]),UnitMovingPointCollisionSize[i],null)
loop
exitwhen BlzGroupGetSize(g) == 0
set u2 = FirstOfGroup(g)
if IsUnitEnemy(u2,GetOwningPlayer(UnitMovingPointU[i])) and GetUnitState(u2,UNIT_STATE_LIFE) > 0 then
call UnitDamageTarget(UnitMovingPointU[i],u2,UnitMovingPointDamageDuringPath[i],false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null)
if UnitMovingPointFirstTarget[i] then
if UnitMovingPointCollisionTrig[i] != null then
set UnitMovingPointActiveInd = i
call TriggerExecute(UnitMovingPointCollisionTrig[i])
endif
if UnitMovingPointRemove[i] then
call RemoveUnit(UnitMovingPointU[i])
set UnitMovingPointU[i] = null
endif
if UnitMovingPointEnd[i] then
set UnitMovingPointU[i] = null
endif
call DestroyEffectTimed(AddSpecialEffect(UnitMovingPointExplodeSFX[i], 0, 0), 5)
endif
endif
call GroupRemoveUnit(g,u2)
endloop
call DestroyGroup(g)
endif
endif
endif
set i = i + 1
endloop
set g = null
set u2 = null
set l = null
set l2 = null
endfunction
function UnitMovingPointInit takes unit u, real x, real y, real speed, real height, real CheckRange, boolean FirstTarget, real DamageDuringPath, real CollisionSize, trigger CollisionTrig, boolean ExplodeInEnd, real ExplodeDamage, real ExplodeAoE, trigger EndingTrig, string ExplodeSFX, boolean Remove, boolean End returns integer
set UnitMovingPointU[UnitMovingPointInd] = u
set UnitMovingPointX[UnitMovingPointInd] = x
set UnitMovingPointY[UnitMovingPointInd] = y
set UnitMovingPointSpeed[UnitMovingPointInd] = speed //speed of the projectile
set UnitMovingPointHeight[UnitMovingPointInd] = height
set UnitMovingPointRangeCheck[UnitMovingPointInd] = CheckRange //IsUnitInRange, the distance needed between unit and point
set UnitMovingPointDistance[UnitMovingPointInd] = SquareRoot(Pow((x-GetUnitX(u)),2)+Pow((y-GetUnitY(u)),2))
set UnitMovingPointFirstTarget[UnitMovingPointInd] = FirstTarget //activate function and checks if remove is allowed when first enemy hit
set UnitMovingPointDamageDuringPath[UnitMovingPointInd] = DamageDuringPath //damage during path
set UnitMovingPointCollisionSize[UnitMovingPointInd] = CollisionSize //range of collision during path
set UnitMovingPointCollisionTrig[UnitMovingPointInd] = CollisionTrig //a trigger that runs when the unit collides with an enemy unit. Only works if FirstTarget is on
set UnitMovingPointExplodeInEnd[UnitMovingPointInd] = ExplodeInEnd //controls if unit deals damage at end point in aoe
set UnitMovingPointExplodeDamage[UnitMovingPointInd] = ExplodeDamage // damage of that ending aoe
set UnitMovingPointExplodeAoE[UnitMovingPointInd] = ExplodeAoE //aoe of the ending damage
set UnitMovingPointEndingTrig[UnitMovingPointInd] = EndingTrig //trigger that is activated at the end
set UnitMovingPointExplodeSFX[UnitMovingPointInd] = ExplodeSFX //creates SFX with this string. Only works if ExplodeDamage is more than 0
set UnitMovingPointRemove[UnitMovingPointInd] = Remove //controls if the unit is removed from the index and the game when finished.
set UnitMovingPointEnd[UnitMovingPointInd] = End //controls if the unit is removed from the index, but not removed from game
set UnitMovingPointInd = UnitMovingPointInd + 1
return UnitMovingPointInd - 1
endfunction
function Unit_Movement_SystemInit takes nothing returns nothing
call TimerStart(CreateTimer(),0.03,true,function UnitMovingPointRun)
endfunction
endlibrary