[JASS] Code Not Working

Level 33
Joined
Apr 24, 2012
Messages
5,120
There seems to be wrong here,but i cant found:
[trigger=]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
(KB2D_Target is A structure) Equal to False
(KB2D_Target is A flying unit) Equal to False
(KB2D_Target is alive) Equal to True
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: local real x = GetUnitX(udg_KB2D_U) + speed * Cos(udg_KB2D_Angle * bj_DEGTORAD)
Custom script: local real y = GetUnitY(udg_KB2D_U) + speed * Sin(udg_KB2D_Angle * bj_DEGTORAD)
Custom script: call SetUnitPosition(udg_KB2D_U,x,y)
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 :D --------
-------- -------------------------------------------- --------
Custom script: local integer maxcollision = 172
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 real
Custom script: local real speed = ApplyKnockbackSpeed()
Custom script: local real kbangle
Custom script: set udg_KB2D_TouchRadius = GetUnitCollisionSize()
For each (Integer KB2D_Integer) from 1 to 4, do (Actions)
Loop - Actions
Custom script: set udg_KB2D_Offset = PolarProjectionBJ(udg_KB2D_Loc,speed,90*I2R(udg_KB2D_Integer))
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
(Terrain pathing at KB2D_Offset of type Walkability is off) Equal to True
(Number of units in KB2D_TempGroup) Greater than 0
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(KB2D_Integer mod 2) Equal to 1
Then - Actions
Custom script: set kbangle = 0 - udg_KB2D_Angle
Else - Actions
Custom script: set kbangle = 180 - udg_KB2D_Angle
Else - Actions
Custom script: call RemoveLocation(udg_KB2D_Offset)
Custom script: call DestroyGroup(udg_KB2D_TempGroup)
Custom script: return kbangle
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: set udg_KB2D_Angle = GetKnockbackAngle()
Custom script: call ApplyKnockbackCoordinates()
Custom script: set udg_KB2D_TouchRadius = 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,1,udg_KB2D_Angle)
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]

[trigger=]Example
Events
Player - Player 1 (Red) Selects a unit
Conditions
Actions
Set KB2D_Target = (Triggering unit)
Custom script: set udg_KB2D_TempKey = GetHandleId(udg_KB2D_Target)
Set KB2D_SFX = Abilities\Weapons\AncientProtectorMissile\AncientProtectorMissile.mdl
Set KB2D_Distance = 500.00
Set KB2D_Duration = 1.50
Set KB2D_Angle = 90.00
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
And - All (Conditions) are true
Conditions
(KB2D_Target is A structure) Equal to False
(KB2D_Target is A flying unit) Equal to False
(KB2D_Target is alive) Equal to True
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
[/trigger]


The Knockback isnt working :( can somebody help?
+2 rep
 

Attachments

  • Knockback 2D v1.0_2.w3x
    20.6 KB · Views: 48
What parts don't work? What happens?

Create debug messages (game messages) in your triggers and see which ones run. If they all run, then it is probably an issue of some false calculations, wrong actions, or something similar. If some don't display, then there is probably a condition not being met or the functions aren't be executed in general.
 
Top