3D sounds

elmstfreddie

The Finglonger
Reaction score
203
In the sound editor, you can convert any mp3 to/from being a 3d sound...

the only difference from a 3d sound and a normal sound is that the intensity of 3d sounds changes depending on how close you are to the source of the sound. Whereas non-3d sounds will play at the same volume no matter where your camera is.

Btw. What relevance to JASS does this have..?
 

wraithseeker

Tired.
Reaction score
122
Because I am going to do it in vJASS and not touching the Sound editor at all, there's a native that allows me to do that.

Yeah thats why I needed 3D sounds.
 

elmstfreddie

The Finglonger
Reaction score
203
Ah, I see. Well could you post your code that doesn't work so we could maybe just fix it?
Could you also specify precisely what is wrong?
 

wraithseeker

Tired.
Reaction score
122
JASS:
scope deathpact initializer Init

globals
    private constant integer SPELL = 'A00P'
    private constant string EFFECT = "MDX\\NewDarkPillar.mdx"
    private sound SLEEP
    private constant string UDEATH = "Objects\\Spawnmodels\\Undead\\UDeathMedium\\UDeath.mdl"
endglobals

private struct data
//! runtextmacro PUI()
    unit caster
    unit target
    unit dummy
    timer t
    integer ticks
    
static method create takes nothing returns data
    local data d = data.allocate()
    set d.caster = GetTriggerUnit()
    set d.target = GetSpellTargetUnit()
    set d.t = NewTimer()
    set d.dummy = CreateUnit(GetOwningPlayer(d.caster),DUMMY,GetUnitX(d.target),GetUnitY(d.target),GetUnitFacing(d.target))
    set d.ticks = 0
    call UnitApplyTimedLife(d.dummy,'BTLF',3)
    call StunUnit(d.target,3)
    call AddTimedEffectTarget(EFFECT,d.dummy,"origin",1)
    return d
endmethod

endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL
endfunction

private function Loop takes nothing returns nothing
    local data d = data(GetTimerData(GetExpiredTimer()))
    local real TLife = GetWidgetLife(d.target) * 0.10
    local real TMana =  GetUnitState(d.target,UNIT_STATE_MANA) *0.10
    local real x = GetUnitX(d.target)
    local real y = GetUnitY(d.target)
    call SetWidgetLife(d.caster,GetWidgetLife(d.caster)+ TLife)
    call SetUnitState(d.caster,UNIT_STATE_MANA,GetUnitState(d.caster,UNIT_STATE_MANA) + TMana)
    call SetWidgetLife(d.target,GetWidgetLife(d.target)-TLife)
    call SetUnitState(d.target,UNIT_STATE_MANA,GetUnitState(d.target,UNIT_STATE_MANA) - TMana)
    set d.ticks = d.ticks + 1
    if d.ticks == 3 then
        call ReleaseTimer(d.t)
        call DestroyEffect(AddSpecialEffect(UDEATH,x,y))
        call SetUnitExploded(d.target,true)
        call KillUnit(d.target)
    endif
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local data d
    if GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_EFFECT then
        call StartSound(SLEEP)
        set d = data.create()
        set data<u> = d
        call SetTimerData(d.t,d)
        call TimerStart(d.t,1,true,function Loop)
        set u = null
        set t = null
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_ENDCAST then
        set d = data<u>
        call ShowUnit(d.dummy,false)
        call StopEffect(1)
        call RemoveUnit(d.dummy)
        call d.destroy()
        set u = null
    endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_ENDCAST)
    call TriggerAddAction( t, function Actions )
    call TriggerAddCondition(t,Condition(function Conditions))
    //set SLEEP = CreateSoundFromLabel(&quot;SleepBirth1&quot;,false,true,true,10,10)
    set SLEEP = CreateSound(&quot;Internal\\Abilities\\Spells\\Undead\\SleepBirth1&quot;,false,true,true,10,10,&quot;&quot;)
    call StartSound(SLEEP)
    call Preload(&quot;Internal\\Abilities\\Spells\\Undead\\SleepBirth1&quot;)
    call SetSoundVolume(SLEEP,2000)
endfunction
endscope</u></u>


Sound doesn't play.
 

wraithseeker

Tired.
Reaction score
122
Attached it but still I can't hear it.

JASS:
scope deathpact initializer Init

globals
    private constant integer SPELL = &#039;A00P&#039;
    private constant string EFFECT = &quot;MDX\\NewDarkPillar.mdx&quot;
    private sound SLEEP
    private constant string UDEATH = &quot;Objects\\Spawnmodels\\Undead\\UDeathMedium\\UDeath.mdl&quot;
endglobals

private struct data
    unit caster
    unit target
    unit dummy
    timer t
    integer ticks
    
    implement AutoData
    
static method create takes nothing returns data
    local data d = data.allocate()
    set d.caster = GetTriggerUnit()
    set d.target = GetSpellTargetUnit()
    set d.t = NewTimer()
    set d.dummy = CreateUnit(GetOwningPlayer(d.caster),DUMMY,GetUnitX(d.target),GetUnitY(d.target),GetUnitFacing(d.target))
    set d.ticks = 0
    call UnitApplyTimedLife(d.dummy,&#039;BTLF&#039;,3)
    call StunUnit(d.target,3)
    call AddTimedEffectTarget(EFFECT,d.dummy,&quot;origin&quot;,1)
    return d
endmethod


endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL
endfunction

private function Loop takes nothing returns nothing
    local data d = data(GetTimerData(GetExpiredTimer()))
    local real TLife = GetWidgetLife(d.target) * 0.10
    local real TMana =  GetUnitState(d.target,UNIT_STATE_MANA) *0.10
    local real x = GetUnitX(d.target)
    local real y = GetUnitY(d.target)
    call AttachSoundToUnit(SLEEP,d.target)
    call StartSound(SLEEP)
    call SetWidgetLife(d.caster,GetWidgetLife(d.caster)+ TLife)
    call SetUnitState(d.caster,UNIT_STATE_MANA,GetUnitState(d.caster,UNIT_STATE_MANA) + TMana)
    call SetWidgetLife(d.target,GetWidgetLife(d.target)-TLife)
    call SetUnitState(d.target,UNIT_STATE_MANA,GetUnitState(d.target,UNIT_STATE_MANA) - TMana)
    set d.ticks = d.ticks + 1
    if d.ticks == 3 then
        call ReleaseTimer(d.t)
        call DestroyEffect(AddSpecialEffect(UDEATH,x,y))
        call SetUnitExploded(d.target,true)
        call KillUnit(d.target)
    endif
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local data d
    local integer id = GetUnitId(u)
    if GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_EFFECT then
        call StartSound(SLEEP)
        set d = data.create()
        set data<u> = d
        call SetTimerData(d.t,d)
        call TimerStart(d.t,1,true,function Loop)
        set u = null
        set t = null
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_ENDCAST then
        set d = data<u>
        call ShowUnit(d.dummy,false)
        call StopEffect(1)
        call RemoveUnit(d.dummy)
        call d.destroy()
        set u = null
    endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_ENDCAST)
    call TriggerAddAction( t, function Actions )
    call TriggerAddCondition(t,Condition(function Conditions))
    //set SLEEP = CreateSoundFromLabel(&quot;SleepBirth1&quot;,false,true,true,10,10)
    set SLEEP = CreateSound(&quot;Internal\\Abilities\\Spells\\Undead\\SleepBirth1&quot;,false,true,true,10,10,&quot;&quot;)
    call StartSound(SLEEP)
    call Preload(&quot;Internal\\Abilities\\Spells\\Undead\\SleepBirth1&quot;)
    call SetSoundVolume(SLEEP,2000)
endfunction
endscope
</u></u>
 

Faust

You can change this now in User CP.
Reaction score
123
I had a 3d sounds problem not long ago, but then I heard the sound, the problem was that I heard it everywhere. But it may help you:

JASS:
function Force3dSound takes string SPath, unit onWho, real MaxDistance, real FadeDistance, integer MaxVolume returns nothing
    local sound s = CreateSound(SPath,false,false,true,1,1,&quot;DefaultEAXON&quot;) //path / boolean if looping / boolean if 3D / boolean if stop when out of range / integer fade in rate / integer fade out rate
    local real dx = GetUnitX(onWho) - GetCameraTargetPositionX()
    local real dy = GetUnitY(onWho) - GetCameraTargetPositionY()
    local real dist = SquareRoot(dx*dx+dy*dy)
    local integer volume = 0

    if dist &lt; FadeDistance then
        set volume = MaxVolume
    elseif dist &lt; MaxDistance then
        set volume = R2I(MaxVolume * (MaxDistance - dist) / (MaxDistance - FadeDistance))
    endif
    
    call SetSoundDuration(s,100) //in ms
    call SetSoundChannel(s,0) //not needed
    call SetSoundPitch(s,1.) //pitch in real, 1. = 100%
    //The following commands do the exact same as PlaySoundOnUnitBJ
    call AttachSoundToUnit(s, GetTriggerUnit())
    call SetSoundVolume(s,volume) //volume
    call StartSound(s)
endfunction


A helper from here gave me this, sorry for not remembering his name right now. x)
 

Chocobo

White-Flower
Reaction score
409
me =D

"Internal\\Abilities\\Spells\\Undead\\SleepBirth1" needs a file extension


and this is how to create (normally) a sound :

(from fsn2)
JASS:
    local sound snd = CreateSound(&quot;war3mapImported\\Rin NP.mp3&quot;, false, false, false, 10, 10,&quot;DefaultEAXON&quot;) //create default sound
    call SetSoundDuration(snd, 6740) //duration 6,740ms
    call SetSoundChannel(snd, 0) //channel normal
    call SetSoundVolume(snd, 127) //volume max
    call SetSoundPitch(snd, 1.0) //pitch rate 1.0x

3rd argument false must be set to true (to be a 3d sound), to play on a unit use AttachSoundToUnit(sound, unit) before or SetSoundPosition(x,y,z) before.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top