[trigger=Requeriment]Knockback 2D
Events
Map initialization
Conditions
Actions
Custom script: set udg_KB2D_Hash = InitHashtable()
-------- -------------------------------------------- --------
-------- Creating Tree Cutter --------
-------- -------------------------------------------- --------
Set KB2D_Loc = (Center of (Playable map area))
Unit - Create 1 Peasant for Neutral Passive at KB2D_Loc facing Default building facing degrees
Set KB2D_Cutter = (Last created unit)
Unit - Hide KB2D_Cutter
Custom script: call UnitAddAbility(udg_KB2D_Cutter,'Aloc')
Custom script: call RemoveLocation(udg_KB2D_Loc)
-------- -------------------------------------------- --------
-------- Determines the Knockback Loop --------
-------- -------------------------------------------- --------
Set KB2D_Loop = 0.03
-------- -------------------------------------------- --------
-------- -------------------------------------------- --------
Custom script: call ExecuteFunc("InitKnockback2D")
Custom script: endfunction
-------- -------------------------------------------- --------
-------- This function destroys knockback --------
-------- -------------------------------------------- --------
Custom script: function DestroyKnockback takes nothing returns nothing
Hashtable - Clear all child hashtables of child KB2D_Key in KB2D_Hash
Unit Group - Remove KB2D_U from KB2D_LoopGroup
Custom script: endfunction
-------- -------------------------------------------- --------
-------- This function applies knockback to unit --------
-------- -------------------------------------------- --------
Custom script: function ApplyKnockbackEffect takes nothing returns nothing
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
And - All (Conditions) are true
Conditions
ers (KB2D_Target is A structure) Equal to False
(KB2D_Target is A flying unit) Equal to False
(KB2D_Target is alive) Equal to True
(KB2D_Target is in KB2D_LoopGroup) Equal to False
Then - Actions
Custom script: call SaveReal(udg_KB2D_Hash,udg_KB2D_TempKey,1,udg_KB2D_Angle)
Custom script: call SaveReal(udg_KB2D_Hash,udg_KB2D_TempKey,2,udg_KB2D_Duration)
Custom script: call SaveReal(udg_KB2D_Hash,udg_KB2D_TempKey,3,udg_KB2D_Distance)
Hashtable - Save KB2D_SFX as 5 of KB2D_TempKey in KB2D_Hash
Unit Group - Add KB2D_Target to KB2D_LoopGroup
Else - Actions
Custom script: endfunction
-------- -------------------------------------------- --------
-------- This function applies speed --------
-------- -------------------------------------------- --------
Custom script: function ApplyKnockbackSpeed takes nothing returns real
Custom script: local real velocity = (udg_KB2D_Distance/udg_KB2D_Duration) * (udg_KB2D_Loop * 2)
Custom script: local real friction = (velocity/udg_KB2D_Duration) * (udg_KB2D_Loop * udg_KB2D_Loop)
Custom script: return velocity - friction
Custom script: endfunction
-------- -------------------------------------------- --------
-------- This function applies knockback coordinates --------
-------- -------------------------------------------- --------
Custom script: function ApplyKnockbackCoordinates takes nothing returns nothing
Custom script: local real speed = ApplyKnockbackSpeed()
Custom script: call SetUnitX(udg_KB2D_U, GetUnitX(udg_KB2D_U) + speed * Cos(udg_KB2D_Angle * bj_DEGTORAD))
Custom script: call SetUnitY(udg_KB2D_U, GetUnitY(udg_KB2D_U) + speed * Sin(udg_KB2D_Angle * bj_DEGTORAD))
Custom script: endfunction
-------- -------------------------------------------- --------
-------- This function checks the collision size --------
-------- -------------------------------------------- --------
Custom script: function GetUnitCollisionSize takes nothing returns integer
-------- -------------------------------------------- --------
-------- This is based from tier 3 halls,thanks to Vexorian for this code
--------
-------- -------------------------------------------- --------
Custom script: local integer maxcollision = 196
Custom script: local integer a = 0
Custom script: local integer radius = maxcollision
Custom script: local real x = GetUnitX(udg_KB2D_U)
Custom script: local real y = GetUnitY(udg_KB2D_U)
Custom script: loop
Custom script: if IsUnitInRangeXY(udg_KB2D_U, x + radius, y, 0) then
Custom script: set a = radius
Custom script: else
Custom script: set maxcollision = radius
Custom script: endif
Custom script: exitwhen maxcollision - a <= 1
Custom script: set radius = (maxcollision + a) / 2
Custom script: endloop
Custom script: set radius = radius - maxcollision + a
Custom script: return radius
Custom script: endfunction
-------- -------------------------------------------- --------
-------- This function applies the bouncing angle --------
-------- -------------------------------------------- --------
Custom script: function GetKnockbackAngle takes nothing returns nothing
Custom script: set udg_KB2D_TouchRadius = I2R(GetUnitCollisionSize())
Set KB2D_Offset = (KB2D_Loc offset by KB2D_TouchRadius towards KB2D_Angle degrees)
Set KB2D_TempGroup = (Units within KB2D_TouchRadius of KB2D_Loc matching (((((Matching unit) is A flying unit) Equal to False) and (((Matching unit) is Ethereal) Equal to False)) and ((((Matching unit) is alive) Equal to True) and ((Matching unit) Not equal to KB2D_U))))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Or - Any (Conditions) are true
Conditions
(Number of units in KB2D_TempGroup) Greater than 0
(Terrain pathing at KB2D_Offset of type Walkability is off) Equal to True
Then - Actions
Set KB2D_Angle = (360.00 - KB2D_Angle)
Set KB2D_Offset = (KB2D_Loc offset by KB2D_TouchRadius towards KB2D_Angle degrees)
Set KB2D_TempGroup = (Units within KB2D_TouchRadius of KB2D_Loc matching (((((Matching unit) is A flying unit) Equal to False) and (((Matching unit) is Ethereal) Equal to False)) and ((((Matching unit) is alive) Equal to True) and ((Matching unit) Not equal to KB2D_U))))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Or - Any (Conditions) are true
Conditions
(Number of units in KB2D_TempGroup) Greater than 0
(Terrain pathing at KB2D_Offset of type Walkability is off) Equal to True
Then - Actions
Set KB2D_Angle = ((KB2D_Angle + 180.00) mod 360.00)
Set KB2D_Offset = (KB2D_Loc offset by KB2D_TouchRadius towards KB2D_Angle degrees)
Set KB2D_TempGroup = (Units within KB2D_TouchRadius of KB2D_Loc matching (((((Matching unit) is A flying unit) Equal to False) and (((Matching unit) is Ethereal) Equal to False)) and ((((Matching unit) is alive) Equal to True) and ((Matching unit) Not equal to KB2D_U))))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Or - Any (Conditions) are true
Conditions
(Number of units in KB2D_TempGroup) Greater than 0
(Terrain pathing at KB2D_Offset of type Walkability is off) Equal to True
Then - Actions
Set KB2D_Angle = (360.00 - KB2D_Angle)
Set KB2D_Offset = (KB2D_Loc offset by KB2D_TouchRadius towards KB2D_Angle degrees)
Set KB2D_TempGroup = (Units within KB2D_TouchRadius of KB2D_Loc matching (((((Matching unit) is A flying unit) Equal to False) and (((Matching unit) is Ethereal) Equal to False)) and ((((Matching unit) is alive) Equal to True) and ((Matching unit) Not equal to KB2D_U))))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Or - Any (Conditions) are true
Conditions
(Number of units in KB2D_TempGroup) Greater than 0
(Terrain pathing at KB2D_Offset of type Walkability is off) Equal to True
Then - Actions
Custom script: call DestroyKnockback()
Else - Actions
Custom script: call RemoveLocation(udg_KB2D_Offset)
Custom script: call DestroyGroup(udg_KB2D_TempGroup)
Else - Actions
Custom script: call RemoveLocation(udg_KB2D_Offset)
Custom script: call DestroyGroup(udg_KB2D_TempGroup)
Else - Actions
Custom script: call RemoveLocation(udg_KB2D_Offset)
Custom script: call DestroyGroup(udg_KB2D_TempGroup)
Else - Actions
Custom script: call SaveReal(udg_KB2D_Hash,udg_KB2D_Key,1,udg_KB2D_Angle)
Custom script: call RemoveLocation(udg_KB2D_Offset)
Custom script: call DestroyGroup(udg_KB2D_TempGroup)
Custom script: endfunction
-------- -------------------------------------------- --------
-------- This function will move the unit --------
-------- -------------------------------------------- --------
Custom script: function MoveKnockbackUnit takes nothing returns nothing
Set KB2D_Loc = (Position of KB2D_U)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
KB2D_Timer Less than KB2D_Duration
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(KB2D_U is dead) Equal to True
Then - Actions
Custom script: call DestroyKnockback()
Else - Actions
Custom script: call GetKnockbackAngle()
Custom script: call ApplyKnockbackCoordinates()
Custom script: set udg_KB2D_TouchRadius = I2R(GetUnitCollisionSize())
Destructible - Pick every destructible within KB2D_TouchRadius of KB2D_Loc and do (Actions)
Loop - Actions
Unit - Order KB2D_Cutter to Harvest (Picked destructible)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Current order of KB2D_Cutter) Equal to (Order(harvest))
Then - Actions
Destructible - Kill (Picked destructible)
Else - Actions
Unit - Order KB2D_Cutter to Stop
Custom script: call SaveReal(udg_KB2D_Hash,udg_KB2D_Key,4,udg_KB2D_Timer + udg_KB2D_Loop)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Random integer number between 1 and 5) Less than 2
Then - Actions
Special Effect - Create a special effect at KB2D_Loc using KB2D_SFX
Special Effect - Destroy (Last created special effect)
Else - Actions
Else - Actions
Custom script: call DestroyKnockback()
Custom script: call RemoveLocation(udg_KB2D_Loc)
Custom script: endfunction
-------- -------------------------------------------- --------
-------- This function will be run periodically --------
-------- -------------------------------------------- --------
Custom script: function Knockback2DLoop takes nothing returns nothing
Unit Group - Pick every unit in KB2D_LoopGroup and do (Actions)
Loop - Actions
Set KB2D_U = (Picked unit)
Custom script: set udg_KB2D_Key = GetHandleId(udg_KB2D_U)
-------- -------------------------------------------- --------
-------- Load --------
-------- -------------------------------------------- --------
Set KB2D_Angle = (Load 1 of KB2D_Key from KB2D_Hash)
Set KB2D_Duration = (Load 2 of KB2D_Key from KB2D_Hash)
Set KB2D_Distance = (Load 3 of KB2D_Key from KB2D_Hash)
Set KB2D_Timer = (Load 4 of KB2D_Key from KB2D_Hash)
Set KB2D_SFX = (Load 5 of KB2D_Key from KB2D_Hash)
Custom script: call ExecuteFunc("MoveKnockbackUnit")
Custom script: endfunction
-------- -------------------------------------------- --------
-------- Reset Trigger --------
-------- -------------------------------------------- --------
Custom script: function InitKnockback2D takes nothing returns nothing
Custom script: local trigger t = GetTriggeringTrigger()
Custom script: call TriggerClearActions(t)
Custom script: call TriggerAddAction(t, function Knockback2DLoop)
Trigger - Add to (This trigger) the event (Time - Every KB2D_Loop seconds of game time)
[/trigger]