Andrewgosu
The Silent Pandaren Helper
- Reaction score
- 716
Description:
A modest system which allows you to create missle arcs in-game with specified parameters.
Features:
- Arc appearance is changeable in-game with a single line code unlike unit missle projectile appearances
- Arc speed is changeable in-game
- Ability to attach your own functions (do damage, knockback, whatever) which trigger when the projectile hits its target
- includes 2 GUI-friendlier location versions
Requires:
CSData, CSSafety and Vexorians dummy unit model.
That's about it.
Any questions, bug finds and feedback is appreciated.
Andrewgosu
A modest system which allows you to create missle arcs in-game with specified parameters.
Features:
- Arc appearance is changeable in-game with a single line code unlike unit missle projectile appearances
- Arc speed is changeable in-game
- Ability to attach your own functions (do damage, knockback, whatever) which trigger when the projectile hits its target
- includes 2 GUI-friendlier location versions
Requires:
CSData, CSSafety and Vexorians dummy unit model.
That's about it.
Any questions, bug finds and feedback is appreciated.
JASS:
library DynamicArcs requires CSCache, CSSafety
globals
private constant real TIMER_VAL = .03125
private constant integer DUMMY_ID = 039;e000039;
private constant real DEFAULT_CURVATURE = 4.
endglobals
private struct arc
unit arcEffect
effect attachedEffect
real distSeg
real dist = 0
real cos
real sin
real startX
real startY
real maxDist
real curve
triggeraction tr = null
trigger onHit = null
integer N = 0
integer endN
method onDestroy takes nothing returns nothing
call DestroyEffect(.attachedEffect)
call UnitApplyTimedLife(.arcEffect, 039;BTLF039;, 2.)
endmethod
endstruct
private function arc_callback takes nothing returns nothing
local timer expired = GetExpiredTimer()
local arc data = GetCSData(expired)
local real c = (data.dist * 2) / data.maxDist - 1
set data.dist = data.dist + data.distSeg
set data.N = data.N + 1
if (data.N >= data.endN) then
if (data.onHit != null) then
call TriggerExecute(data.onHit)
call TriggerRemoveAction(data.onHit, data.tr)
call DestroyTrigger(data.onHit)
endif
call ReleaseTimer(expired)
call data.destroy()
endif
call SetUnitPosition(data.arcEffect, data.startX + data.dist * data.cos, data.startY + data.dist * data.sin)
call SetUnitFlyHeight(data.arcEffect, (-c * c + 1) * (data.maxDist / data.curve), 0)
endfunction
private function arc_execute takes string modelName, integer speed, real curve, real x1, real y1, real x2, real y2, code actionFunc returns nothing
local arc whichArc = arc.create()
local real dx = x2 - x1
local real dy = y2 - y1
local real maxDist = SquareRoot(dx * dx + dy * dy)
local real angle = Atan2(y2 - y1, x2 - x1)
local timer t = NewTimer()
set whichArc.endN = R2I((maxDist / speed) / TIMER_VAL + .5)
set whichArc.arcEffect = CreateUnit(Player(0), DUMMY_ID, x1, x2, angle * bj_RADTODEG)
call UnitAddAbility(whichArc.arcEffect, 039;Aloc039;)
set whichArc.attachedEffect = AddSpecialEffectTarget(modelName, whichArc.arcEffect, "origin")
set whichArc.maxDist = maxDist
set whichArc.curve = curve
set whichArc.distSeg = speed * TIMER_VAL
set whichArc.startX = x1
set whichArc.startY = y1
set whichArc.cos = Cos(angle)
set whichArc.sin = Sin(angle)
if (actionFunc != null) then
set whichArc.onHit = CreateTrigger()
set whichArc.tr = TriggerAddAction(whichArc.onHit, actionFunc)
endif
call UnitAddAbility(whichArc.arcEffect, 039;Amrf039;)
call UnitRemoveAbility(whichArc.arcEffect, 039;Amrf039;)
call SetCSData(t, whichArc)
call TimerStart(t, TIMER_VAL, true, function arc_callback)
endfunction
function CreateArc takes string modelPath, integer speed, real x1, real y1, real x2, real y2 returns nothing
call arc_execute.execute(modelPath, speed, DEFAULT_CURVATURE, x1, y1, x2, y2, null)
endfunction
function CreateArcLoc takes string modelPath, integer speed, location startLoc, location targetLoc returns nothing
call arc_execute.execute(modelPath, speed, DEFAULT_CURVATURE, GetLocationX(startLoc), GetLocationY(startLoc), GetLocationX(targetLoc), GetLocationY(targetLoc), null)
endfunction
function CreateArcEx takes string modelPath, integer speed, real curve, real x1, real y1, real x2, real y2, code actionFunc returns nothing
call arc_execute.execute(modelPath, speed, curve, x1, y1, x2, y2, actionFunc)
endfunction
function CreateArcExLoc takes string modelPath, integer speed, real curve, location startLoc, location targetLoc, code actionFunc returns nothing
call arc_execute.execute(modelPath, speed, curve, GetLocationX(startLoc), GetLocationY(startLoc), GetLocationX(targetLoc), GetLocationY(targetLoc), actionFunc)
endfunction
endlibrary
Andrewgosu