Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TinkerWorX/f076cc3b531d297af30c2a7e18d16f6f to your computer and use it in GitHub Desktop.
Save TinkerWorX/f076cc3b531d297af30c2a7e18d16f6f to your computer and use it in GitHub Desktop.
unit triggered movement system
globals
unit array UnitMovingPointU
real array UnitMovingPointX
real array UnitMovingPointY
real array UnitMovingPointSp
boolean array UnitMovingPointCo
boolean array UnitMovingPointReach
boolean array UnitMovingPointReachEx
boolean array UnitMovingPointRm
real array UnitMovingPointDm
real array UnitMovingPointDmEnd
real array UnitMovingPointCs
real array UnitMovingPointRn
real array UnitMovingPointDmSz
string array UnitMovingPointSFX
integer UnitMovingPointInd = 0
function array UnitMovingPointfunc
endglobals
function UnitMovingPointRun takes nothing returns nothing
local integer i = 0
local group g = null
local unit u2 = null
local location l = null
local location l2 = null
local real x = 0
local real y = 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],UnitMovingPointRn[i]) then
set UnitMovingPointReach[i] = true
if UnitMovingPointReachEx[i] then
call DestroyEffectTimed(AddSpecialEffect(UnitMovingPointSFX[i], 0, 0), 5)
set g = CreateGroup()
call GroupEnumUnitsInRange(g,x,y,UnitMovingPointDmSz[i],null)
loop
exitwhen BlzGroupGetSize(g) == 0
set u2 = FirstOfGroup(g)
if IsUnitEnemy(u2,GetOwningPlayer(UnitMovingPointU[i])) then
call UnitDamageTarget(UnitMovingPointU[i],u2,UnitMovingPointDmEnd[i],false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null)
endif
call GroupRemoveUnit(g,u2)
endloop
call DestroyGroup(g)
endif
if UnitMovingPointRm[i] then
call RemoveUnit(UnitMovingPointU[i])
set UnitMovingPointU[i] = null
endif
if UnitMovingPointfunc[i] != null then
call UnitMovingPointfunc[i]
endif
else
set l = Location(x,y)
set l2 = Location(UnitMovingPointX[i],UnitMovingPointY[i])
call SetUnitX(UnitMovingPointU[i], x + speed * Cos(AngleBetweenPoints(l,l2) * bj_DEGTORAD))
call SetUnitY(UnitMovingPointU[i]), y + speed * Sin(AngleBetweenPoints(l,l2)) * bj_DEGTORAD)
call RemoveLocation(l)
call RemoveLocation(l2)
if UnitMovingPointDm[i] != 0 then
set g = CreateGroup()
call GroupEnumUnitsInRange(g,GetUnitX(UnitMovingPointU[i]),GetUnitY(UnitMovingPointU[i],UnitMovingPointCs[i],null)
loop
exitwhen BlzGroupGetSize(g) == 0
set u2 = FirstOfGroup(g)
if IsUnitEnemy(u2,GetOwningPlayer(UnitMovingPointU[i])) then
call UnitDamageTarget(UnitMovingPointU[i],u2,UnitMovingPointDm[i],false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null)
if UnitMovingPointCo[i] then
if UnitMovingPointfunc[i] != null then
call UnitMovingPointfunc[i]
endif
if UnitMovingPointRm[i] then
call RemoveUnit(UnitMovingPointU[i])
set UnitMovingPointU[i] = null
endif
call DestroyEffectTimed(AddSpecialEffect(UnitMovingPointSFX[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 runner, real x, real y, real speed, boolean collide, real collision, boolean explodeAtEnd, boolean remove, real damage, real damageEnd, real aoe, real range, string SFX, function func returns integer
set UnitMovingPointU[UnitMovingPointInd] = runner
set UnitMovingPointX[UnitMovingPointInd] = x
set UnitMovingPointY[UnitMovingPointInd] = y
set UnitMovingPointSp[UnitMovingPointInd] = speed
set UnitMovingPointReachEx[UnitMovingPointInd] = explodeAtEnd //controls if unit deals damage at end point in aoe
set UnitMovingPointRm[UnitMovingPointInd] = remove //controls if the unit is removed when finished
set UnitMovingPointDm[UnitMovingPointInd] = damage //damage during path
set UnitMovingPointDmEnd[UnitMovingPointInd] = damageEnd // damage at the end
set UnitMovingPointCo[UnitMovingPointInd] = collide //activate function and checks if remove is allowed when first enemy hit
set UnitMovingPointCs[UnitMovingPointInd] = collision //range of collision during path
set UnitMovingPointDmSz[UnitMovingPointInd] = aoe //aoe of the ending damage
set UnitMovingPointRn[UnitMovingPointInd] = range //distance between target point and the unit
set UnitMovingPointSFX[UnitMovingPointInd] = SFX //activates SFX when colliding or when exploding at end
set UnitMovingPointfunc[UnitMovingPointInd] = func //function that can be activated when colliding or when end xplosion
set UnitMovingPointInd = UnitMovingPointInd + 1
return UnitMovingPointInd - 1
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment