- Reaction score
- 456
_ __ ___ ____ _____ ____ ___ __ _
Knockback System v2.0
¯ ¯¯ ¯¯¯ ¯¯¯¯ ¯¯¯¯¯ ¯¯¯¯ ¯¯¯ ¯¯ ¯
by Überplayer
Knockback System v2.0
¯ ¯¯ ¯¯¯ ¯¯¯¯ ¯¯¯¯¯ ¯¯¯¯ ¯¯¯ ¯¯ ¯
by Überplayer
I didn't see anyone submitting a system like this, so I decided to create one. I hope that you all know
what is the basic idea of a knockback system?
Instruction Trigger:
JASS:
v.2.0
Made by: Überplayer
Credits: Cohadar - for ABC, BorderSafety and help
Requirements:
¯¯¯¯¯¯¯¯¯¯¯¯¯
-NewGen editor (required)
-ABC (required)
-BorderSafety (required)
Importing:
¯¯¯¯¯¯¯¯¯¯
If you don039;t already have ABC v5.1 and BorderSafety v1.0 in your map, then
copy the "ABC" and "BorderSafety" triggers to your map. Finally, you can copy
the "Knockback System" trigger to your map.
How to use?:
¯¯¯¯¯¯¯¯¯¯¯¯
whichUnit = the unit which knocks a unit back and deals damage
target = the unit which is knocked back
direction = the direction where the unit is knocked back
distance = the distance how far the unit is knocked back
damage = the damage which is dealt during the knockback
duration = the duration of the knock back
effectPath = model string of the effect
attachPoint = where the effect is attached
_____________________________
function UnitKnockTarget takes unit whichUnit, unit target, real direction, real distance, real damage, real duration returns nothing
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_____________________________
function UnitKnockTargetEx takes unit whichUnit, unit target, real direction, real distance, real damage, real duration, real effectPath, real attachPoint returns nothing
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
KnockbackUnit(..) function uses the default strings from the
systems configuration menu.
System Trigger:
JASS:
library Knockback uses ABC, BorderSafety
globals
private constant real INTERVAL = 0.035
private constant string EFFECT_STRING = "Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl"
private constant string ATTACH_POINT = "origin"
endglobals
private struct KBdata
unit whichUnit
unit target
string effectPath
string attachPoint
effect knockEffect
real dx
real dy
real periodDamage
timer clock = CreateTimer()
integer ticks
static method create takes unit whichUnit, unit target, real direction, real distance, real damage, real duration, string effectPath, string attachPoint returns KBdata
local KBdata dat = KBdata.allocate()
set dat.whichUnit = whichUnit
set dat.target = target
set dat.effectPath = effectPath
set dat.attachPoint = attachPoint
set dat.dx = ((distance / duration) * INTERVAL) * Cos(direction * bj_DEGTORAD)
set dat.dy = ((distance / duration) * INTERVAL) * Sin(direction * bj_DEGTORAD)
set dat.periodDamage = ((damage / duration) * INTERVAL)
set dat.ticks = R2I(duration / INTERVAL)
call SetTimerStructA(dat.clock, dat)
return dat
endmethod
method onDestroy takes nothing returns nothing
call ClearTimerStructA(.clock)
call PauseTimer(.clock)
call DestroyTimer(.clock)
call DestroyEffect(.knockEffect)
call SetUnitPathing(.target, true)
endmethod
endstruct
private function KnockbackUnit_Handler takes nothing returns nothing
local timer exprTimer = GetExpiredTimer()
local KBdata dat = GetTimerStructA(exprTimer)
local real x
local real y
if (dat.ticks <= 0) then
call dat.destroy()
else
set dat.ticks = dat.ticks - 1
set x = GetUnitX(dat.target) + dat.dx
set y = GetUnitY(dat.target) + dat.dy
call DestroyEffect(dat.knockEffect)
set dat.knockEffect = AddSpecialEffectTarget(dat.effectPath, dat.target, dat.attachPoint)
call SetUnitPosition(dat.target, x, y)
call UnitDamageTarget(dat.whichUnit, dat.target, dat.periodDamage, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNKNOWN, WEAPON_TYPE_WHOKNOWS)
call SetUnitPathing(dat.target, false)
endif
set exprTimer = null
endfunction
function UnitKnockTargetEx takes unit whichUnit, unit target, real direction, real distance, real damage, real duration, string effectPath, string attachPoint returns nothing
local KBdata dat = KBdata.create(whichUnit, target, direction, distance, damage, duration, effectPath, attachPoint)
call SetUnitPathing(dat.target, false)
call TimerStart(dat.clock, INTERVAL, true, function KnockbackUnit_Handler)
set dat.knockEffect = AddSpecialEffectTarget(dat.effectPath, dat.target, dat.attachPoint)
endfunction
function UnitKnockTarget takes unit whichUnit, unit target, real direction, real distance, real damage, real duration returns nothing
call UnitKnockTargetEx(whichUnit, target, direction, distance, damage, duration, EFFECT_STRING, ATTACH_POINT)
endfunction
endlibrary
(thanks Cohadar x).. the code was shortened alot)
The Map: