overload119
New Member
- Reaction score
- 5
JASS:
scope Cleave initializer Init
private struct data
unit target = null
unit caster = null
group knockGroup = null
real v = 0.
real angle = 0.
endstruct
globals
private boolexpr filter = null
private data tempData
endglobals
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == 039;A00N039;
endfunction
private function Filt takes nothing returns boolean
local unit t = GetFilterUnit()
if( IsUnitEnemy(t,GetOwningPlayer(tempData.caster)) and GetWidgetLife(t)>0.405 and not IsUnitType(t, UNIT_TYPE_MECHANICAL)and not IsUnitInGroup(t, tempData.knockGroup) ) then
call GroupAddUnit(tempData.knockGroup, t)
call UnitAddAbility(t, 039;A00O039;)
endif
return FALSE
endfunction
private function KnockbackGroup takes nothing returns nothing
local unit u = GetEnumUnit()
local real dx = 0.
local real dy = 0.
set dx = PolarProjectionX(GetUnitX(u), tempData.v, tempData.angle)
set dy = PolarProjectionY(GetUnitY(u), tempData.v, tempData.angle)
if IsTerrainWalkable(dx, dy) then
call SetUnitX(u, dx)
call SetUnitY(u, dy)
endif
endfunction
private function Callback takes nothing returns nothing
local timer myTimer = GetExpiredTimer()
local data d = GetTimerData(myTimer)
local unit target = null
set d.v = d.v*0.925
set tempData = d
// Enum and add new units to the knockback group
call GroupEnumUnitsInRange(tempGroup, GetUnitX(d.target), GetUnitY(d.target), 125, filter)
// Knockback the entire group
call ForGroup(d.knockGroup, function KnockbackGroup)
if d.v <= 5 then
loop
set target = FirstOfGroup(d.knockGroup)
exitwhen target == null
call UnitRemoveAbility(target, 039;A00O039;)
call GroupRemoveUnit(d.knockGroup, target)
endloop
call DestroyGroup(d.knockGroup)
call ReleaseTimer(myTimer)
call d.destroy()
endif
endfunction
private function Actions takes nothing returns nothing
local timer myTimer = NewTimer()
local unit u = GetTriggerUnit()
local unit t = GetSpellTargetUnit()
local real amount = 50+GetHeroLevel(u)*10+GetUnitStat(u, ATTACK_POWER)*0.4*BarbarianDamageModifier(u,t)
local data d = data.create()
set d.caster = u
set d.target = t
set d.knockGroup = CreateGroup()
set d.angle = AngleBetweenPointsXY(GetUnitX(u), GetUnitY(u), GetUnitX(t), GetUnitY(t))
set d.v = 40.
call GroupAddUnit(d.knockGroup, t)
call UnitAddAbility(t, 039;A00O039;)
call UnitDamage(u, t, PHYSICAL, amount)
call SetTimerData(myTimer, d)
call TimerStart(myTimer, 0.03, true, function Callback)
endfunction
function Init takes nothing returns nothing
local trigger t = CreateTrigger()
set filter = Condition(function Filt)
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Conditions ) )
call TriggerAddAction( t, function Actions )
endfunction
endscope
I haven't posted the additional function in this spell such as UnitDamage, because those are unrelated to the spell and the crash (all spells use these functions but only this one crashes).
The make things stranger, the spell will only crashe around 30 minutes into the game, and in all my tests it was casted on a large unit with a large collision size (144) if that has anything to do with it...