I don't think you need to do that at all?
Look at this line, present in the original:
Code: c++
- self.Unit.Callbacks.OnAbilityBeginCast:Call( self, self.Unit )
This runs any callback functions of this type added to the casting unit every time casting starts. Since it passes 'self' (the AbilityTask itself in this case), you should be able to access self.Target from within this callback.
So, to use this, you need to add a callback function to the unit whenever the Eviction ability is on the unit, and remove it when the Eviction ability is removed. Here's some prototype code that you should be able to get working with some testing:
Code: c++
- --Add to the Eviction item's actual ability blueprint
- EvictionTime = 120,
- OnAbilityAdded = function(self, unit)
- unit.Callbacks.OnAbilityBeginCast:Add(self.EvictionCheck, self)
- end,
- OnRemoveAbility = function(self, unit)
- unit.Callbacks.OnAbilityBeginCast:Remove(self.EvictionCheck)
- end,
- --This function gets its first param from the above Add() (the ability def), and the second two params from its Call()
- --in AbilityTask.BeginCastState.OnEnterState (which are self and self.Unit, self being the AbilityTask)
- EvictionCheck = function(abilDef, abilTask, caster)
- --Make sure the ability task in question is eviction; abilDef will always be eviction's blueprint, but abilTask
- --will not always be an eviction cast (it's triggered for all ability casts while this callback is on the unit
- if abilTask.AbilityName == abilDef.Name and abilTask.Target then
- --Looks for an EvictionTime var on the target unit - set this using GetGameTimeSeconds() upon successful cast
- local targetEvicted = abilTask.Target.EvictionTime
- if targetEvicted and GetGameTimeSeconds() - targetEvicted < abilDef.EvictionTime then
- abilTask:AbortCast()
- end
- end
- end,
The game's callback add/remove system is a little confusing, because if the Add() call specifies a second parameter, that becomes the first parameter to a Call() of that callback. If you want to be more/less confused, look at the Add/Remove/Call functions in /lua/system/Callback.lua.
Regardless, this should work fine, because it can get a handle to the target via the abilityTask passed to it, and then issue an AbortCast() directly to the abilityTask if the target matches conditions. I just put some dummy conditions in using GetGameTimeSeconds so it would make sense while I was writing it - just replace that with however you're already doing has-been-evicted-detection.