HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Channeling Spell Problems

07-24-2007, 12:22 AM#1
Spiky
Yes, another spell problem. Here it is:

Collapse JASS:
//*************************************************************
//* Constant Functions (Only edit things under this section.) *
//*************************************************************

constant function BH_Raw_Code takes nothing returns integer
  return 'A006'
endfunction

constant function BH_Dummy_Raw_Code takes nothing returns integer
  return 'h000'
endfunction

constant function BH_Hellfire_Raw_Code takes nothing returns integer
  return 'A007'
endfunction

constant function BH_Timer_Time takes nothing returns real
  return 1.0
endfunction

constant function BH_Effect_Dummy takes nothing returns integer
  return 'h001'
endfunction

//**************
//* Conditions *
//**************

function BH_Spell_Check takes nothing returns boolean
  return GetSpellAbilityId() == BH_Raw_Code()
endfunction

//*************
//* Functions *
//*************

function BH_Channeling takes nothing returns nothing
//Local Variables
  local timer t = GetExpiredTimer()
  local unit caster = GetHandleUnit(t, "caster")
  local real angle = GetRandomInt(1, 360)
  local real distance = GetRandomInt(1, 1000)
  local real X = GetUnitX(caster) + distance * Cos(angle * bj_DEGTORAD)
  local real Y = GetUnitY(caster) + distance * Sin(angle * bj_DEGTORAD)
  local unit dummy
  local unit e
  local integer count = GetHandleInt(t, "count")
  local integer lvl = GetHandleInt(t, "lvl")

//Functions

  if GetWidgetLife(caster) > 0.405 and count < 10 then
    set dummy = CreateUnit(GetOwningPlayer(caster), BH_Dummy_Raw_Code(), GetUnitX(caster), GetUnitY(caster), 270.0)
    call UnitAddAbility(dummy, BH_Hellfire_Raw_Code())
    call SetUnitAbilityLevel(dummy, BH_Hellfire_Raw_Code(), lvl)
    call IssuePointOrder(dummy, "flamestrike", X, Y)
    call UnitApplyTimedLife(dummy, 'BTLF', 1.0)
    call SetHandleInt(t, "count", count + 1)
    set e = CreateUnit(GetOwningPlayer(caster), BH_Effect_Dummy(), X, Y, 270.0)
    call UnitApplyTimedLife(e, 'BTLF', 5.0)
  else
    call PauseTimer(t)
    call DestroyTimer(t)
    set t = null
    call SetHandleInt(t, "count", 0)
    call FlushHandleLocals(t)
  endif
  
//Null Variables
  set t = null
  set caster = null
  set dummy = null
endfunction

function BH_Spell takes nothing returns nothing
//Local Variables
  local unit caster = GetTriggerUnit()
  local timer t
  local integer count = 0
  local integer lvl = GetUnitAbilityLevel(caster, BH_Raw_Code())
  
//Functions
  if GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_EFFECT then
    set t = CreateTimer()
    call SetHandleHandle(t, "caster", caster)
    call SetHandleInt(t, "count", count)
    call SetHandleInt(t, "lvl", lvl)
    call SetHandleHandle(t, "t", t)
    call TimerStart(t, BH_Timer_Time(), true, function BH_Channeling)
  elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_ENDCAST then
    set t = GetHandleTimer(t, "t") 
    call PauseTimer(t)
    call DestroyTimer(t)
    set t = null
    call FlushHandleLocals(t)
endif

//Null Variables
  set caster = null
  set t = null    
endfunction

//===========================================================================
function InitTrig_Bring_Hell takes nothing returns nothing
local integer i = 0
    set gg_trg_Bring_Hell = CreateTrigger(  )
    loop
      exitwhen i>12
        call TriggerRegisterPlayerUnitEventSimple( gg_trg_Bring_Hell, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerRegisterPlayerUnitEventSimple( gg_trg_Bring_Hell, Player(i), EVENT_PLAYER_UNIT_SPELL_ENDCAST)
        set i = i + 1
    endloop
    call TriggerAddCondition( gg_trg_Bring_Hell, Condition(function BH_Spell_Check))
    call TriggerAddAction( gg_trg_Bring_Hell, function BH_Spell )
endfunction

I don't want to use NewGen/Caster System. I want this to be able to be used by anyone. I don't want any discussion about why, I just want help with my spell. Anyways, whenever I stop casting, the trigger keeps going. Any ideas?
07-24-2007, 06:50 AM#2
Pyrogasm
In your init function, you're going to need to add this line:
Collapse JASS:
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Bring_Hell, Player(i), EVENT_PLAYER_UNIT_SPELL_FINISH)
And simply change the elseif in the cast function to an "else"; the trigger won't fire any other way, right?

The reason that you need to register both events is because of the difference between "Finishes" and "Stops" à la GUI. When you stop casting (ENDCAST), it is because a stun or something interrupted you; when you finish casting (FINISH), it is because the spell's channel time ended or the player ordered the unit to stop.