/Cry, Spell Only Works Once

Frosthowl

TH.net Regular
Reaction score
15
Ok, so I made a spell that fades a unit out over 1 second and then 15 seconds later, fades the unit back in. For some reason, after I use the spell a second time, the values I used are already set to max and nothing happens. Why is this happening even after its destroying the struct.

Code:
struct Fade
unit u
integer f
integer i
endstruct

function Trig_Hypnosis_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'HYPN'
endfunction

function Fade_Actions takes nothing returns nothing
local timer t = GetExpiredTimer()
local Fade data = GetTimerStructA(t)
set data.i = data.i + 1

if IsUnitAliveBJ(data.u) == false or data.i > 400 then
set data.f = data.f - 4
call SetUnitVertexColorBJ(data.u, 100, 100, 100, data.f)
else
    if data.i <= 25 then
    set data.f = data.f + 4
    call SetUnitVertexColorBJ(data.u, 100, 100, 100, data.f)
    endif
endif

if data.f <= 0 then
    //call DisplayTextToForce( GetPlayersAll(), I2S(data.i) )
    //call DisplayTextToForce( GetPlayersAll(), I2S(data.f) )
    call data.destroy()
    call ClearTimerStructA(t)
    call PauseTimerBJ(true, t)
    call DestroyTimer (t)
endif
endfunction

function Trig_Hypnosis_Actions takes nothing returns nothing
    local unit c = GetSpellAbilityUnit()
    local Fade data = Fade.create()
    local timer t = CreateTimer()
    set data.u = c
    
    call SetTimerStructA(t, data)
    call TimerStart(t, .04, true, function Fade_Actions)
endfunction

//===========================================================================
function InitTrig_Hypnosis takes nothing returns nothing
    set gg_trg_Hypnosis = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hypnosis, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Hypnosis, Condition( function Trig_Hypnosis_Conditions ) )
    call TriggerAddAction( gg_trg_Hypnosis, function Trig_Hypnosis_Actions )
endfunction
 

The Undaddy

Creating with the power of rage
Reaction score
55
When you destroy a struct,you do not clear it's values,you just make it reuseable.To fix it just initialize the values like so:

JASS:
struct Fade
unit u
integer f = 0
integer i = 0
endstruct
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top