- Joined
- Aug 6, 2009
- Messages
- 697
I created a system that takes a sound and changes the volume based on where the screen of a player is relative to where the unit the sound is playing from is. After thorough testing I have discovered that KillSoundWhenDone causes a fatal error and I'm not sure why. I don't want sound leaks so I use KillSoundWhenDone at the end of the timer which is at the end of the sound being played. I tried putting KillSoundWhenDone inside the Bind3DSoundToUnit function but it instantly kills the sound instead of waiting until it finishes. I find this weird since what I've coded is pretty much the same as the "PlaySound" JASS function. I didn't want to use the "PlaySound" function by itself because it doesn't return a sound.
Do I need to kill the sound when it's done or can I just remove this line of code? If this causes a leak, then is there anyway to fix the fatal error that results from KillSoundWhenDone?
Do I need to kill the sound when it's done or can I just remove this line of code? If this causes a leak, then is there anyway to fix the fatal error that results from KillSoundWhenDone?
JASS:
function Bind3DSoundToUnit takes string str, unit u returns sound
set udg_sysSound_Index = GetNewIndexFromLinkedList(udg_sysSound_List)
set udg_sysSound_Sound[udg_sysSound_Index] = CreateSound(str, false, false, false, 10, 10, "")
set udg_sysSound_Unit[udg_sysSound_Index] = u
set udg_sysSound_CurrentTime[udg_sysSound_Index] = 0.00
set udg_sysSound_MaxTime[udg_sysSound_Index] = (GetSoundFileDuration(str)/1000)
set udg_sysSound_HearThroughFog[udg_sysSound_Index] = false
call StartSound(udg_sysSound_Sound[udg_sysSound_Index])
call SetSoundVolume(udg_sysSound_Sound[udg_sysSound_Index], 0)
set udg_sysSound_PointBoolean[udg_sysSound_Index] = false
return udg_sysSound_Sound[udg_sysSound_Index]
endfunction
-
Play3DSoundLoop
-
Events
-
Time - Every 0.03 seconds of game time
-
-
Conditions
-
Actions
-
Custom script: set udg_sysSound_Index = GetFirstIndexFromLinkedList(udg_sysSound_List)
-
Custom script: loop
-
Custom script: exitwhen udg_sysSound_Index == 0
-
Custom script: if udg_sysSound_CurrentTime[udg_sysSound_Index] < udg_sysSound_MaxTime[udg_sysSound_Index] then
-
Set sysSound_CurrentTime[sysSound_Index] = (sysSound_CurrentTime[sysSound_Index] + 0.03)
-
Player Group - Pick every player in Game_AllPlayers and do (Actions)
-
Loop - Actions
-
Custom script: local real dx
-
Custom script: local real dy
-
Custom script: local real dist
-
Custom script: local real vol
-
Custom script: if IsUnitVisible(udg_sysSound_Unit[udg_sysSound_Index], GetEnumPlayer()) == true and IsUnitFogged(udg_sysSound_Unit[udg_sysSound_Index], GetEnumPlayer()) == false and udg_sysSound_HearThroughFog[udg_sysSound_Index] == false then
-
Custom script: if GetLocalPlayer() == GetEnumPlayer() then
-
Custom script: if udg_sysSound_PointBoolean[udg_sysSound_Index] == true then
-
Custom script: set dx = GetLocationX(udg_sysSound_Point[udg_sysSound_Index]) - GetCameraTargetPositionX()
-
Custom script: set dy = GetLocationX(udg_sysSound_Point[udg_sysSound_Index]) - GetCameraTargetPositionY()
-
Custom script: else
-
Custom script: set dx = GetUnitX(udg_sysSound_Unit[udg_sysSound_Index]) - GetCameraTargetPositionX()
-
Custom script: set dy = GetUnitY(udg_sysSound_Unit[udg_sysSound_Index]) - GetCameraTargetPositionY()
-
Custom script: endif
-
Custom script: set dist = SquareRoot((dx*dx) + (dy*dy))
-
Custom script: set vol = 127 * (1 - (dist/6000))
-
Custom script: if vol < 0 then
-
Custom script: set vol = 0
-
Custom script: endif
-
Custom script: endif
-
Custom script: call SetSoundVolume(udg_sysSound_Sound[udg_sysSound_Index], R2I(vol))
-
Custom script: set dx = 0
-
Custom script: set dy = 0
-
Custom script: set dist = 0
-
Custom script: set vol = 0
-
Custom script: elseif udg_sysSound_HearThroughFog[udg_sysSound_Index] == true then
-
Custom script: if GetLocalPlayer() == GetEnumPlayer() then
-
Custom script: if udg_sysSound_PointBoolean[udg_sysSound_Index] == true then
-
Custom script: set dx = GetLocationX(udg_sysSound_Point[udg_sysSound_Index]) - GetCameraTargetPositionX()
-
Custom script: set dy = GetLocationY(udg_sysSound_Point[udg_sysSound_Index]) - GetCameraTargetPositionY()
-
Custom script: else
-
Custom script: set dx = GetUnitX(udg_sysSound_Unit[udg_sysSound_Index]) - GetCameraTargetPositionX()
-
Custom script: set dy = GetUnitY(udg_sysSound_Unit[udg_sysSound_Index]) - GetCameraTargetPositionY()
-
Custom script: endif
-
Custom script: set dist = SquareRoot((dx*dx) + (dy*dy))
-
Custom script: set vol = 127 * (1 - (dist/6000))
-
Custom script: if vol < 0 then
-
Custom script: set vol = 0
-
Custom script: endif
-
Custom script: endif
-
Custom script: call SetSoundVolume(udg_sysSound_Sound[udg_sysSound_Index], R2I(vol))
-
Custom script: set dx = 0
-
Custom script: set dy = 0
-
Custom script: set dist = 0
-
Custom script: set vol = 0
-
Custom script: endif
-
-
-
Custom script: else
-
Custom script: call KillSoundWhenDone(udg_sysSound_Sound[udg_sysSound_Index])
-
Custom script: if udg_sysSound_PointBoolean[udg_sysSound_Index] == true then
-
Custom script: call RemoveLocation(udg_sysSound_Point[udg_sysSound_Index])
-
Custom script: endif
-
Custom script: call RecycleIndexFromLinkedList(udg_sysSound_List,udg_sysSound_Index)
-
Custom script: endif
-
Custom script: set udg_sysSound_Index = GetNextIndexFromLinkedList(udg_sysSound_List,udg_sysSound_Index)
-
Custom script: endloop
-
-