HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Sound System Not Working?

07-12-2009, 12:49 AM#1
DeathRing
I've been working on a Sound System for this mage based game I'm working on, but whenever I try to call up the sounds, they don't work.
Collapse JASS:
scope SoundSystem initializer InitTrig
    globals
        public sound array SFX
    endglobals
    
    private function SSound takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i==3
            call SetSoundVolume(SFX[i], 127)
            call StartSound(SFX[i])
            set i = i+1
        endloop
    endfunction
    
    private function PSound takes nothing returns nothing
        local trigger t = CreateTrigger()
        call BJDebugMsg("Sounds Registered")
        set SFX[0] = CreateSound("war3mapImported\\PreCastFireMagic.mp3", false, true, true, 10, 10, "")
        set SFX[1] = CreateSound("war3mapImported\\CastFire.mp3", false, true, true, 10, 10, "")
        set SFX[2] = CreateSound("war3mapImported\\PreCastFrostMagicMedium.mp3", false, true, true, 10, 10, "")
        set SFX[3] = CreateSound("war3mapImported\\CastIce.mp3", false, true, true, 10, 10, "")        
        
        
        call TriggerAddAction(t,function SSound)
        call TriggerExecute(t)
    endfunction
    
    

    private function InitTrig takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEvent(t,.001,false)
        call TriggerAddAction(t,function PSound)
    endfunction
endscope

Every time I would attempt to play a sound it would be called in something like:
Collapse JASS:
call StartSound(SoundSystem_SFX[*Selected Number Goes Here*]) 
, but it wouldn't play at all. Could somebody help me fix this system?
07-12-2009, 01:15 AM#2
Blubb-Tec
PSound is running twice this way. since you don't remove PSound as a trigger function when you call TriggerExecute(). anyway, why do you use TriggerExecute() if you can simply do call SSound()?

edit: also this one exitwhen i==3 will cause the loop to only init 0,1,2 and then exit.

edit2: also try putting a KillSoundWhenDone() after each StartSound() in your SSound function.
07-12-2009, 01:25 AM#3
DeathRing
Quote:
Originally Posted by Blubb-Tec
PSound is running twice this way. since you don't remove PSound as a trigger function when you call TriggerExecute(). anyway, why do you use TriggerExecute() if you can simply do call SSound()?

edit: also this one exitwhen i==3 will cause the loop to only init 0,1,2 and then exit.

edit2: also try putting a KillSoundWhenDone() after each StartSound() in your SSound function.

Well I made those fixes, but the sounds still don't work. But here's the updated trigger:
Collapse JASS:
scope SoundSystem initializer InitTrig
    globals
        public sound array SFX
    endglobals
    
    private function SSound takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i>3
            call SetSoundVolume(SFX[i], 127)
            call StartSound(SFX[i])
            call KillSoundWhenDone(SFX[i])
            set i = i+1
        endloop
    endfunction
    
    private function PSound takes nothing returns nothing
        call BJDebugMsg("Sounds Registered")
        set SFX[0] = CreateSound("war3mapImported\\PreCastFireMagic.mp3", false, true, true, 10, 10, "")
        set SFX[1] = CreateSound("war3mapImported\\CastFire.mp3", false, true, true, 10, 10, "")
        set SFX[2] = CreateSound("war3mapImported\\PreCastFrostMagicMedium.mp3", false, true, true, 10, 10, "")
        set SFX[3] = CreateSound("war3mapImported\\CastIce.mp3", false, true, true, 10, 10, "")        
        
        
        call SSound()
    endfunction
    
    

    private function InitTrig takes nothing returns nothing
        call PSound()
    endfunction
endscope
07-13-2009, 01:08 AM#4
PurplePoot
Sounds don't work the first time they're played. If that's actually just preloading (kinda hard to tell), then could you post the code around which you're trying to play them (ie are you setting their positions and such)?

Also, are you sure you want to use such low fade in and fade out rates?
07-13-2009, 04:34 AM#5
DeathRing
Quote:
Originally Posted by PurplePoot
Sounds don't work the first time they're played. If that's actually just preloading (kinda hard to tell), then could you post the code around which you're trying to play them (ie are you setting their positions and such)?

Also, are you sure you want to use such low fade in and fade out rates?

Yes, I am sure on the fade in and fade out rates, but they don't even play after the first sound they are played. Here's the code im using it in, it may be one of my more unpolished spell cast triggers, but its currently the only one I was testing the sound system with:
Collapse JASS:
scope Fireball

    globals
        private constant integer SPELL_ID  = 'A002'
        private constant integer SPELL_TIME_INT = 15
        private constant string SPELL_MODEL = "Abilities\\Weapons\\RedDragonBreath\\RedDragonMissile.mdl"
        private constant real SPELL_SPEED = 1200.00
        private constant real SPELL_ANGLESPEED = 100.00
        private constant real SPELL_MAXDIST = 1600.00
        private constant real SPELL_HEIGHT = 100.00
        private constant real SPELL_COLLISION = 100.00
        private constant attacktype ATTACKTYPE = ATTACK_TYPE_NORMAL
        private constant damagetype DAMAGETYPE = DAMAGE_TYPE_FIRE
        
    endglobals
    
//===================================================================================      
    private constant function Fireball_SpellId takes nothing returns integer
        return 'A00C'
    endfunction
    
    private function Fireball_Attack_Type takes nothing returns attacktype
        return ATTACK_TYPE_CHAOS
    endfunction
    
    private function Fireball_Damage_Type takes nothing returns damagetype
        return DAMAGE_TYPE_FIRE
    endfunction
//===================================================================================    
    
    private struct fireballdata
        unit caster
    endstruct
    
    private struct triggerdata
        unit target
        unit caster
        triggeraction ac
        timer t
        integer int = 0
        texttag array castingtime[26]
        real x
        real y
        real x2
        real y2
        real z
        location loc_caster
        integer order
    endstruct
    
    private function fireball_hit takes nothing returns nothing
        local fireballdata F = fireballdata(CollisionMissile_GetTag(GetTriggerCollisionMissile()))
        local unit targ = GetTriggerUnit()
        local unit m = GetTriggerCollisionMissile()
        local unit temp
        local unit u = F.caster
        local real damage = (75.00 + (25.00*GetUnitAbilityLevel(u,SPELL_ID)))+(GetHeroInt(u, true)*(1.50 + (.5*GetUnitAbilityLevel(u,SPELL_ID))))
        local real x = GetUnitX(m)
        local real y = GetUnitY(m)
        local group g = CreateGroup()
        
        set damage = damage + SpellBuffDamageInc(u)
        

        if targ==null then
            call DestroyEffect(AddSpecialEffect("NewGroundEX.mdx",x,y))
            
            call GroupEnumUnitsInRange(g,x,y, 200.00,null)
            loop
                set temp = FirstOfGroup(g)
                exitwhen temp == null
                if IsUnitEnemy(temp,GetOwningPlayer(u)) then
                    call UnitDamageTarget(u,temp,damage, true, false,ATTACKTYPE,DAMAGETYPE, null)
                    call BJDebugMsg(R2S(damage))
                    call UnitDamageUnitTimed(u,12.00,1.00,5.00,temp,"","head",ATTACKTYPE,DAMAGETYPE)
                    call AddSpecialEffectTargetUnitWithTimer("head",temp,"Abilities\\Spells\\Other\\BreathOfFire\\BreathOfFireDamage.mdl",5.00)
                endif
                call GroupRemoveUnit(g,temp)
            endloop
        else
            if IsUnitEnemy(targ,GetOwningPlayer(u)) then
                call CollisionMissile_Destroy(m)
                call F.destroy()
            endif
        endif
    
        
        
        
        
        call DestroyGroup(g)
        
        set targ = null
        set temp = null
        set u = null
        set g = null
    endfunction
    
    
    private function fireball takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local fireballdata F = fireballdata.create()
        local triggerdata T = triggerdata( GetCSData(t) )
        local integer i = T.int
        local integer j = 0
        local unit m
        local unit u = T.caster
        local real angle = AngleBetweenPointsXY(T.x,T.y,T.x2,T.y2)
        local real max_dist = DistanceBetweenPointsXY(T.x,T.y,T.x2,T.y2)
        
        set F.caster = T.caster
        set i = i+1
        set T.int = i
        
        //Checks if caster is stunned or incapacitated
        if (GetUnitCurrentOrder(u)!=T.order) then
            call CS_Error(GetOwningPlayer(u),"Caster has stopped casting!")
            call StopSound(SoundSystem_SFX[0],false,false)
            
            call ReleaseTimer(t)
            call T.destroy()                           
            
            set i = 0
        endif
        //Check Ends!
        
        if SpeedEnhancedBoolean(u)==true then
            set j = SpeedEnhancedInt(u)
        endif
            
        if (i==SPELL_TIME_INT-j) then
            call SetUnitAnimation(u,"Attack")
            set m = CollisionMissile_Create(SPELL_MODEL,T.x,T.y,angle,SPELL_SPEED,0,max_dist, SPELL_HEIGHT,true,SPELL_COLLISION,function fireball_hit)
            
            call CollisionMissile_SetTag(m, integer(F))
            
            call AttachSoundToUnit(SoundSystem_SFX[1],u)
            call StartSound(SoundSystem_SFX[1])
            call StopSound(SoundSystem_SFX[0],false,false)

                
            call ReleaseTimer(t)
            call T.destroy()                 //Also recycle the object (quite important)
        else
            call F.destroy()
        endif
        
        set m = null
        set u = null
    endfunction
    
    private function casting takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local triggerdata T = triggerdata.create()
        local location l = GetSpellTargetLoc()
        local real x = GetLocationX(l)
        local real y = GetLocationY(l)
        local timer t = NewTimer()
        local integer i
        
        
        
        call SetUnitAnimation(u,"Spell Channel")
        call AddSpecialEffectTargetUnitWithTimer("hand, left",u,"Fire Uber.mdx",I2R(SPELL_TIME_INT/10))
        call AddSpecialEffectTargetUnitWithTimer("hand, right",u,"Fire Uber.mdx",I2R(SPELL_TIME_INT/10))
        
        call AttachSoundToUnit(SoundSystem_SFX[0],u)
        call StartSound(SoundSystem_SFX[0])
        

        set T.caster = u
        set T.order = GetUnitCurrentOrder(u)
        set T.x = GetUnitX(u)
        set T.y = GetUnitY(u)
        set T.x2 = x
        set T.y2 = y
        set T.z = 25.00
        call SetCSData(t, integer(T) )
        call TimerStart(t,.1,true,function fireball)

        
        call RemoveLocation(l)
        
        set l = null
        set u = null
    endfunction

//===========================================================================
    public function InitTrig takes nothing returns nothing
        call OnAbilityEffect( SPELL_ID, SCOPE_PRIVATE+"casting" )
    endfunction
    
endscope
07-13-2009, 05:14 AM#6
darkwulfv
Quote:
Sounds don't work the first time they're played
Everyone keeps saying this, but I've never noticed this problem; all my sounds (They're created in the Sound Editor, if that perhaps changes things?) always play when I tell them to.