ID:1928527
 
I'm rather new to Coding, and so far i've managed to figure out quite a bit from Byond's forums and Developer's guides. However i have one issue.

I'm trying to make a Stereo in a game that'll play Music.

I'm wanting to make it so that as you walk away from it, the quieter it gets until you can't hear it at all.
But as you walk towards it, the louder it gets.

I however have no clue how to do this at all, no place to start with.

Anyway this can be done?
if so, mind giving me the code for it?
Nevermind, figured out how to make it. It was rather hard but i finally figured it out.
mob/proc/Life()
spawn(25)
var/LOLOL = 0
if(client != null)
for(var/obj/structure/DJplayer/M in world)
for(var/obj/structure/music/T in view(6))
LOLOL = 1
if(usr.hearingmusic == 0)
src.hearingmusic = 1
src << sound(M.music,1)
if(src.hearingmusic == 1 && LOLOL == 0)
src << sound(null,1)
src.hearingmusic = 0
Life()

obj/structure/music
icon = 'Icon/structure.dmi'
icon_state = "stereo"
name = "Stereo"
density = 1
opacity = 0

obj/structure/DJplayer
var/music = 'Music/Static.ogg'
icon = 'Icon/structure.dmi'
icon_state = "DJplayer"
name = "DJstereo"
density = 1
opacity = 0

obj/structure/DJplayer/New()
var/randomizedchoice = rand(1,2)
if(randomizedchoice == 1)
src.music = 'Music/Musiquedintro.ogg'
if(randomizedchoice == 2)
src.music = 'Music/Cantinatheme.ogg'

obj/structure/DJplayer/Click(mob/M)
if(usr in view(1))
var/list/music = list("Musique d'intro","Cantina Theme")
var/musicchoice = input(usr, "What Job shall you choose?", "Racial Choice", "Human") in music
switch(musicchoice)
if("Musique d'intro")
src.music = 'Music/Musiquedintro.ogg'
for(var/mob/player/T in world)
T << sound(null,1)
T.hearingmusic = 0
if("Cantina Theme")
src.music = 'Music/Cantinatheme.ogg'
for(var/mob/player/T in world)
T << sound(null,1)
T.hearingmusic = 0
if (null)
src.music = 'Music/Static.ogg'
for(var/mob/player/T in world)
T << sound(null,1)
T.hearingmusic = 0


Feel free to scavenge up this bit of code.
Koil's Soundmob library can do this as well as 3D sound positioning. It is featured in Pondera.
I made a quick demo to demonstrate how simple it is to use 3D sounds: http://puu.sh/kvgFb/36e6e73b36.zip

Run the project and click around and listen to the differences in how loud each speaker plays the sound (only really works if you have multiple speakers).

The core of it is these lines:
var sound:s = sound('Laser_Shoot5.wav')
s.x = location.x - mob.x
s.z = location.y - mob.y
mob << s

In a sidescroller perspective, you'd use sound.y instead of sound.z. The difference is in the DM Reference: positive y is above your head, while positive z is straight ahead.