• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Sound only plays once

Status
Not open for further replies.
Level 8
Joined
Dec 16, 2007
Messages
252
This is a channeling spell that will play the PH1 music upon channeling. But the problem is that the sound only plays at the first cast. When I then cancel the spell, and cast it again. No sound is played. Could it be that the spell only lasts for 6 seconds and the sound lasts for 4 minutes?

JASS:
scope GuitarSolo initializer Init

private struct dat
 unit u
 timer t
 sound music
endstruct 


private function GSConditions takes nothing returns boolean
   return GetSpellAbilityId() == 'A02J' 
endfunction

private function Move takes nothing returns nothing
    local dat d = GetTimerData(GetExpiredTimer())
    local real x = GetUnitX(d.u)
    local real y = GetUnitY(d.u)
    local group g = CreateGroup()
    local real targx
    local real targy
    local real e
    local real f
    local real ang
    local string o
    local unit u
    local real dx
    local real dy
    local real dist
    set o = OrderId2String(GetUnitCurrentOrder(d.u))
    
    if o != "starfall" then
     call StopSound(d.music, true, false )
     call d.destroy()
     call ReleaseTimer(d.t)
     set d.u = null
     set u = null
    endif
    
    call GroupEnumUnitsInRange(g, x, y, 800, AliveGroundFilter)
    loop
    set u = FirstOfGroup(g)
    exitwhen u == null
    call GroupRemoveUnit(g, u)
    
    if (IsUnitEnemy(u, GetOwningPlayer(d.u)) == true) then
        set targx = GetUnitX(u)
        set targy = GetUnitY(u)
        set dx = targx - x
        set dy = targy - y    
        set dist = SquareRoot(dx*dx + dy*dy)
        set ang = Atan2(y - targy, x - targx)
        set e = targx + 10 * Cos(ang)
        set f = targy + 10 * Sin(ang)
        if dist < 200 then
          set e = targx - 1 * Cos(ang)
          set f = targy - 1 * Sin(ang)
        endif
        call SetUnitPosition(u, e, f)
        call UnitDamageTargetBJ(d.u, u, 10, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)

    endif
endloop

    set e = x + GetRandomReal(0, 800) * Cos(GetRandomReal(0, 800))
    set f = y + GetRandomReal(0, 800) * Sin(GetRandomReal(0,800))
        
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", e, f))
    
    call DestroyGroup(g)
    set g = null     
endfunction


private function GSActions takes nothing returns nothing
    local dat d = dat.create()
    local location p = GetUnitLoc(GetTriggerUnit())
    set d.t = NewTimer()
    set d.u = GetTriggerUnit()
    call PlaySoundAtPointBJ(gg_snd_PH1, 100, p, 0)
    set d.music = GetLastPlayedSound()
    call SetTimerData(d.t,d)
    call TimerStart(d.t, 0.05, true, function Move)
    call RemoveLocation(p)
    set p = null
endfunction

//===========================================================================
function Init takes nothing returns nothing
    set gg_trg_Guitar_Solo = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Guitar_Solo, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Guitar_Solo, Condition( function GSConditions ) )
    call TriggerAddAction( gg_trg_Guitar_Solo, function GSActions )
endfunction

endscope
 
Status
Not open for further replies.
Top