| 03-21-2007, 11:49 PM | #1 |
Here is my code for a custom poison function. The problem is that sometimes (it seems randomly) the buff is not removed correctly and the target continues taking damage forever (or until the unit is attacked again and the bug doesn't happen; as I said it's quite random). This script fires when a unit is physically attacked by a unit with a poison ability: JASS:function Poisoned_Strike_Damage_Target takes nothing returns nothing local timer t = GetExpiredTimer( ) local unit target = LoadUnit( t, "target", "Poisoned Strike" ) local unit source = LoadUnit( t, "source", "Poisoned Strike" ) call UnitDamageTarget( source, target, 10, TRUE, FALSE, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS ) set t = null set target = null set source = null endfunction // B006 = Slow Buff // A00G = Slow Ability function Poisoned_Strike_Destroy_Timers takes nothing returns nothing local timer t1 = GetExpiredTimer( ) local timer t2 = LoadTimer( t1, "timer 2", "Poisoned Strike" ) local unit target = LoadUnit( t1, "target", "Poisoned Strike" ) call UnitRemoveAbility( target, 'B006' ) call UnitRemoveAbility( target, 'A00G' ) // distrugge entrambi i timer call PauseTimer( t1 ) call DestroyTimer( t1 ) call PauseTimer( t2 ) call DestroyTimer( t2 ) set t1 = null set t2 = null set target = null endfunction // A00G = Slow Ability function PoisonedStrike takes unit source, unit target returns nothing local timer t1 = CreateTimer( ) local timer t2 = CreateTimer( ) local timer tt1 = LoadTimer( target, "timer 1", "Poisoned Strike" ) local timer tt2 = LoadTimer( target, "timer 2", "Poisoned Strike" ) local real timeout = 5 call UnitAddAbility( target, 'A00G' ) call PauseTimer( tt1 ) call DestroyTimer( tt1 ) call PauseTimer( tt2 ) call DestroyTimer( tt2 ) call UnitDamageTarget( source, target, 10, TRUE, FALSE, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS ) if IsUnitType( target, UNIT_TYPE_HERO ) == true then set timeout = 1.00 endif // salva il bersaglio, l'attaccante ed il danno nel timer 2 ed il timer 2 // nel bersaglio // ********** IMPORTANT // my handles function explanation: // |where| |string| |other string| |what| call SaveHandle( t2, "target", "Poisoned Strike", target ) call SaveHandle( t2, "source", "Poisoned Strike", source ) call SaveReal( t2, "damage", "Poisoned Strike", damage ) call SaveHandle( target, "timer 2", "Poisoned Strike", t2 ) // salvo il timer 2 nel timer 1 call SaveHandle( t1, "timer 2", "Poisoned Strike", t2 ) // salvo il bersaglio nel timer 1 ed il timer 1 nel bersaglio call SaveHandle( t1, "target", "Poisoned Strike", target ) call SaveHandle( target, "timer 1", "Poisoned Strike", t1 ) // faccio partire i timer call TimerStart( t1, timeout, false, function Poisoned_Strike_Destroy_Timers ) call TimerStart( t2, 1, true, function Poisoned_Strike_Damage_Target ) set t1 = null set t2 = null set tt1 = null set tt2 = null endfunction //=========================================================================== function InitTrig_Poisoned_Strike takes nothing returns nothing endfunction What can be the problem? Thank you very much. |
| 03-22-2007, 03:07 PM | #2 |
i dont get why you are using so many timers. wouldnt it be easier just making it simply with 1 timer?. something like this: JASS:function timer takes blabla returns blabla local timer t=GetExpiredTimer() local unit source=blabla local unit target=blabla if GetUnitAbilityLevel(target,<Poison BuffID>) > 0 then // if the unit is poisoned it will take damage call UnitDamageTarget(blablabla) else //if the unit didnt have the buff the timer will stop call PauseTimer(t) call DestroyTimer(t) set t=null set source=null set target=null endfunction function blabla takes blabla returns blabla local timer t=CreateTimer() //Attach the things to the time here(source,target) //Create a unit and make it cast the poision buff on target. call TimerStart(t,bla,bla,<ur timer function>) set t=null endfunction |
| 03-22-2007, 03:52 PM | #3 |
I need two timers because I don't use a dummy caster, but an aura ability which needs to be removed after some time. Thanks anyway. |
