| 01-30-2007, 12:12 AM | #1 |
1st time trying to use a timer for an ability.. JASS:function Trig_Blood_Transfer_Conditions takes nothing returns boolean return GetSpellAbilityId() == 'A04D' endfunction function BloodTransfer takes timer t returns nothing local unit a = GetSpellAbilityUnit() local unit c = GetSpellTargetUnit() local integer i = GetUnitAbilityLevel(a, 'A04D') local real g = GetUnitState(a, UNIT_STATE_LIFE) local integer b if g <= 1500 then set b = 0 call UnitRemoveAbility( c, 'B012' ) elseif g > 1500 then set b = 1 endif if b == 1 then call BJDebugMsg("3") call DestroyEffect( AddSpecialEffect( "Objects\\Spawnmodels\\Demon\\DemonBlood\\DemonBloodPitlord.mdl", GetUnitX(a), GetUnitY(a) ) ) call DestroyEffect( AddSpecialEffect( "Objects\\Spawnmodels\\Demon\\DemonBlood\\DemonBloodPitlord.mdl", GetUnitX(c), GetUnitY(c) ) ) call UnitDamageTarget( a, c, 1, false, true, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS ) call SetUnitState( a, UNIT_STATE_LIFE, g - 1 ) elseif b == 0 then call PauseTimer(t) call DestroyTimer(t) endif set a = null set c = null call BJDebugMsg("4") endfunction function BloodTransfer_Effect takes nothing returns nothing call BloodTransfer(GetExpiredTimer()) endfunction function Trig_Blood_Transfer_Actions_Core takes timer t returns nothing local unit a = GetSpellAbilityUnit() local real r = I2R(GetUnitAbilityLevel(a, 'A04D')) call SetUnitState( a, UNIT_STATE_LIFE, GetUnitState(a, UNIT_STATE_LIFE) - (100 * r) ) call TimerStart( t, 0.60 - (r * 0.15), true, function BloodTransfer_Effect ) set a = null call BJDebugMsg("2") endfunction function Trig_Blood_Transfer_Actions takes nothing returns nothing if GetUnitState(GetSpellAbilityUnit(), UNIT_STATE_LIFE) > 100 * GetUnitAbilityLevel(GetSpellAbilityUnit(), 'A04D') then call BJDebugMsg("1") call Trig_Blood_Transfer_Actions_Core(CreateTimer()) endif endfunction //=========================================================================== function InitTrig_Blood_Transfer takes nothing returns nothing set gg_trg_Blood_Transfer = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Blood_Transfer, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition( gg_trg_Blood_Transfer, Condition( function Trig_Blood_Transfer_Conditions ) ) call TriggerAddAction( gg_trg_Blood_Transfer, function Trig_Blood_Transfer_Actions ) endfunction When i test this, it shows 1,2,4 once 2 things are wrong here. 1, the timer should keeping going, so wouldnt the 3 and the 4 show until the timer stops? 2, The 3 does not show...why? |
| 01-30-2007, 12:23 AM | #2 |
GetSpellAbilityUnit and GetSpellTargetUnit will *never* return a valid unit inside a timer function. You're going to have to store both of those units in some fashion that your timer function can access them. It can be smart timers, gamecache, global variables, or anything else your clever mind can think up. Run through the code again but picture the local variables a and c as null. |
| 01-30-2007, 12:42 AM | #3 |
What are smart timers? Edit: Ok i found out what SmartTimer is |
| 01-30-2007, 01:34 AM | #4 |
Nah, he means that you have to attach information to the timer (which is a horrible approach although it works) You may start with something easy like "handle vars" JASS://After creating the timer, before starting it cal SetHandleHandle(t, "target", GetSpellTargetUnit()) //When the timer expires: call KillUnit(GetHandleUnit(t,"target")) |
