- Joined
- May 28, 2007
- Messages
- 365
JASS:
So this is my spell code. For some strange reason, when I cast it, I get the debug SetTimerData message that says
SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer
This occurs, even if the very first spell in the map that uses TimerUtils is this one (so it doesn't have to do with leaking timers).
Another strange thing is that when I cast it and there are people around me, it'll give the message multiple times, the same amount of times as there are people around me.
I've added a little debug message, to see if the source of this spell. Here comes another strange thing.
I get the error message from TimerUtils BEFORE the debug message I placed there, which is strange because my debug message is supposed to appear before.
What's up?
'Also, I'm sure my spell is not coded well. If you can give me tips on what I can do to maximize performance, can you let me know? (It's not giving me any performance errors, but I'd like to learn as much as I can with this)
[code=jass]scope Flush
function Trig_Flush_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A00F'
endfunction
private struct data
real x
real y
unit caster
group g
real v
endstruct
private function Filt takes nothing returns boolean
local data d = GetTimerData(GetExpiredTimer())
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(d.caster)) and GetWidgetLife(GetFilterUnit())>0.405 and not IsUnitType(GetFilterUnit(), UNIT_TYPE_ANCIENT) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL)
endfunction
private function RemoveEffect takes nothing returns nothing
call UnitRemoveAbility(GetEnumUnit(), 'A00G')
endfunction
private function AddEffect takes nothing returns nothing
call UnitAddAbility(GetEnumUnit(), 'A00G')
endfunction
private function FlushKnockback takes nothing returns nothing
local data d = GetTimerData(GetExpiredTimer())
local group g = NewGroup()
local real angle
local real x
local real y
local unit target
set d.v = d.v*0.925
call GroupAddGroup(d.g, g)
call GroupRemoveUnit(g, d.caster)
loop
set target = FirstOfGroup(g)
exitwhen target == null
set angle = AngleBetweenPointsXY(d.x, d.y, GetUnitX(target), GetUnitY(target))
set x = PolarProjectionX(GetUnitX(target), d.v, angle)
set y = PolarProjectionY(GetUnitY(target), d.v, angle)
if IsTerrainWalkable(x,y) then
call SetUnitX(target, x)
call SetUnitY(target, y)
endif
call GroupRemoveUnit(g, target)
endloop
call ReleaseGroup(g)
if d.v < 5 then
call ForGroup(d.g, function RemoveEffect)
call d.destroy()
call PauseTimer(GetExpiredTimer())
call ReleaseTimer(GetExpiredTimer())
endif
endfunction
function Trig_Flush_Actions takes nothing returns nothing
local timer tt = NewTimer()
local unit u = GetTriggerUnit()
local unit t = GetSpellTargetUnit()
local real coBonus = 1+GetPlayerTechCount(GetOwningPlayer(u), 'R007', true)*0.03
local real amount = 125+10*GetHeroLevel(u)+GetUnitStat(u, SPELL_POWER)*0.5*coBonus
local boolexpr filter = Condition(function Filt)
local data d = data.create()
call UnitRemoveBuffs(u, false, true)
call HealUnit(t, amount)
set d.caster = u
set d.g = NewGroup()
set d.v = 30
set d.x = GetUnitX(t)
set d.y = GetUnitY(t)
call GroupEnumUnitsInRange(d.g, d.x, d.y, 250, filter)
call ForGroup(d.g, function AddEffect)
debug call BJDebugMsg("Assigning timer data...")
call SetTimerData(tt, d)
call TimerStart(tt, 0.03, true, function FlushKnockback)
call DestroyBoolExpr(filter)
set filter = null
endfunction
//===========================================================================
function InitTrig_Flush takes nothing returns nothing
set gg_trg_Flush = CreateTrigger( )
call TriggerRegisterAnyUnitEventNL( gg_trg_Flush, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Flush, Condition( function Trig_Flush_Conditions ) )
call TriggerAddAction( gg_trg_Flush, function Trig_Flush_Actions )
endfunction
endscope