I was unable to find a vanilla JASS knockback system and so I decided to create my own. Still feeling somewhat inexperienced I was hoping that someone would look over my code, provide suggestions and perhaps point out my mistakes.
It currently works pretty well, but there are probably ways that I can improve it further? (I'm especially thinking about efficiency here as the system currently has just about all the functionality that I desire)
Thanks in advance!
It currently works pretty well, but there are probably ways that I can improve it further? (I'm especially thinking about efficiency here as the system currently has just about all the functionality that I desire)
JASS:
function Frictional_Knockback_System_Callback takes nothing returns nothing
local unit u = GetEnumUnit()
local real x
local real y
local real x1
local real y1
local real angle
local real friction
local integer id = GetHandleId(u)
local real speed = LoadReal(udg_FKS_Hashtable, id, 0)
if GetWidgetLife(u) > 0.405 and speed > 0. then
set x = GetUnitX(u)
set y = GetUnitY(u)
set angle = LoadReal(udg_FKS_Hashtable, id, 1)
set x1 = ProjectX(x, speed, angle)
set y1 = ProjectY(y, speed, angle)
if IsTerrainPathable(x1, y1, PATHING_TYPE_WALKABILITY) == false then
call SetUnitX(u, x1)
call SetUnitY(u, y1)
set friction = LoadReal(udg_FKS_Hashtable, id, 2)
set speed = speed - friction
call SaveReal(udg_FKS_Hashtable, id, 0, speed)
else
call DestroyEffect(LoadEffectHandle(udg_FKS_Hashtable, id, 3))
call GroupRemoveUnit(udg_FKS_Group, u)
call FlushChildHashtable(udg_FKS_Hashtable, id)
set udg_FKS_Count = udg_FKS_Count - 1
endif
else
call DestroyEffect(LoadEffectHandle(udg_FKS_Hashtable, id, 3))
call GroupRemoveUnit(udg_FKS_Group, u)
call FlushChildHashtable(udg_FKS_Hashtable, id)
set udg_FKS_Count = udg_FKS_Count - 1
endif
set u = null
endfunction
function Frictional_Knockback_System_Actions takes nothing returns nothing
if udg_FKS_Count > 0 then
call ForGroup(udg_FKS_Group, function Frictional_Knockback_System_Callback)
else
call DisableTrigger(GetTriggeringTrigger())
endif
endfunction
//===========================================================================
function InitTrig_Frictional_Knockback_System takes nothing returns nothing
set gg_trg_Frictional_Knockback_System = CreateTrigger()
call TriggerRegisterTimerEventPeriodic(gg_trg_Frictional_Knockback_System, 0.03125)
call TriggerAddAction(gg_trg_Frictional_Knockback_System, function Frictional_Knockback_System_Actions)
endfunction
Thanks in advance!