Knockback System!
Fully follows the JESP standart, is MUI and is the first Knockback System with Group Knocking!
Fully follows the JESP standart, is MUI and is the first Knockback System with Group Knocking!
JASS/GUI: JASS
vJASS: Yes
Systems used: Attachable Vars (Don't complain, I'm not gonna edit)
MUI: Yes
Code:
JASS:
//****************************************************************************
// Knockback System *
// Author: Vestras *
//****************************************************************************
//****************************************************************************
// Credits: *
// vile1, for teaching me the method. *
// Vexorian, for Attachable Vars. *
//****************************************************************************
//****************************************************************************
// Requirements: *
// This trigger. *
// Attachable Vars. *
//****************************************************************************
//***************************************************************************************************
// Function list: *
// *
// KS_SingleKnock(KnockedUnit, KnockingSpeed, KnockingRange, KnockingAngle) *
// Used for single units. *
// *
// KS_GroupKnock(KnockingLocation, KnockingCaster, KnockingGroupRange, KnockingSpeed, KnockingRange)*
// Used for a group knock. *
//***************************************************************************************************
library KnockbackSystem requires AttachableVars
// Configuration
private constant function ShowSFX takes nothing returns boolean
return true // Whether you want the sfx to be showed or not. False if not
endfunction
private constant function GetInterval takes nothing returns real
return 0.03 // The real which the timer that runs the movement is runned
endfunction
private constant function GetDust takes nothing returns string
return "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" // Path of the dust model (Land)
endfunction
private constant function KillDestructables takes nothing returns boolean
return true // Whether or not if destructables should be destroyed. false if not.
endfunction
// End of configuration
// Custom functions
private constant function KillTrees_True takes nothing returns boolean
return true // Needed
endfunction
private function KillTrees_Real takes nothing returns nothing
call KillDestructable(GetEnumDestructable())
endfunction
private function KillTrees takes real x, real y returns nothing
local rect R=Rect(x-200.*.5,y-200.*.5,x+200.*.5,y+200.*.5)
call EnumDestructablesInRect(R, Condition(function KillTrees_True), function KillTrees_Real)
call RemoveRect(R)
set R = null
endfunction
private function SetUnitXY takes unit u, real x, real y returns nothing
if x<GetRectMaxX(bj_mapInitialPlayableArea) and x>GetRectMinX(bj_mapInitialPlayableArea) and y<GetRectMaxY(bj_mapInitialPlayableArea) and y>GetRectMinY(bj_mapInitialPlayableArea) then
call SetUnitX(u,x)
call SetUnitY(u,y)
endif
endfunction
// End of custom functions
// Globals. Do not touch
globals
private location L
private unit uni
private real angl
private real spd
private real rang
endglobals
// End of globals
//**************************************************
// WARNING WARNING WARNING WARNING WARNING WARNING *
// DO ONLY EDIT BELOW IF YOU KNOW WHAT YOU DO *
// WARNING WARNING WARNING WARNING WARNING WARNING *
//**************************************************
private function AddEffect takes nothing returns nothing
local timer tmr = GetExpiredTimer()
local string st = GetAttachmentTable(tmr)
local unit attchto = GetTableUnit(st, "Knockback_Target")
local real x=GetUnitX(attchto)
local real y=GetUnitY(attchto)
local real break = 1.25-.15
local real speed = GetTableReal(st, "Knockback_Speed")
call SetTableReal(st, "Knockback_Speed", speed-break)
call DestroyEffect(AddSpecialEffect(GetDust(),x,y))
if speed <= 0. then
call DestroyTimer(tmr)
endif
set tmr = null
set attchto = null
endfunction
private function Movement takes nothing returns nothing
local timer t = GetExpiredTimer()
local string s = GetAttachmentTable(t)
local unit u = GetTableUnit(s, "Knockback_Target")
local real cos = GetTableReal(s, "Knockback_Cos")
local real sin = GetTableReal(s, "Knockback_Sin")
local real speed = GetTableReal(s, "Knockback_Speed")
local real x = GetUnitX(u) + speed * cos
local real y = GetUnitY(u) + speed * sin
local real break = 1.25-.15
if KillDestructables() == true then
call KillTrees(x, y)
endif
if speed > 0. then
call SetUnitXY(u, x, y)
call SetTableReal(s, "Knockback_Speed", speed-break)
else
call DestroyTimer(t)
endif
set t = null
set u = null
endfunction
function KS_SingleKnock takes unit whichUnit, real speed, real range, real angle returns nothing
local timer t = CreateTimer()
local timer tmr = CreateTimer()
local string s = GetAttachmentTable(t)
local string st = GetAttachmentTable(tmr)
call SetTableReal(s, "Knockback_Cos", Cos(angle*.017453))
call SetTableReal(s, "Knockback_Sin", Sin(angle*.017453))
call SetTableReal(s, "Knockback_Speed", speed)
call SetTableObject(s, "Knockback_Target", whichUnit)
call SetTableObject(st, "Knockback_Target", whichUnit)
call SetTableReal(st, "Knockback_Speed", speed)
call SetTableInt(st, "Knockback_Int", 1)
call TimerStart(t, GetInterval(), true, function Movement)
if ShowSFX() then
call TimerStart(tmr, 0.03, true, function AddEffect)
endif
if GetTableReal(s, "Knockback_Speed") <= 0. then
call DestroyTimer(tmr)
call DestroyTimer(t)
set tmr = null
set t = null
endif
endfunction
private function KS_FilterEnemies takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) != true and GetWidgetLife(GetFilterUnit()) > .405 and IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(uni)) == true
endfunction
private function KS_Group takes nothing returns nothing
local location n = GetUnitLoc(GetEnumUnit())
local real angl = bj_RADTODEG * Atan2(GetLocationY(n) - GetLocationY(L), GetLocationX(n) - GetLocationX(L))
call KS_SingleKnock(GetEnumUnit(), spd, rang, angl)
call RemoveLocation(n)
set n = null
endfunction
function KS_GroupKnock takes location l, unit caster, real range, real speed, real r returns nothing
local group g = CreateGroup()
local real x = GetLocationX(l)
local real y = GetLocationY(l)
set spd = speed
set rang = r
set uni = caster
set L = l
call GroupEnumUnitsInRange(g, x, y, range, Condition(function KS_FilterEnemies))
call ForGroup(g, function KS_Group)
call RemoveLocation(L)
set uni = null
set L = null
endfunction
endlibrary
Screenshot:
I put 3 days of hard work to this, so please enjoy!