ID:164728
 
Oh yes, a newbie question by me! <:0

I tried to do somethign like
// random shooting proc behind this...
var/sound/S = sound('Gunshot.mid') // ...
S.x += Clicked_Place.x-x
S.y += Clicked_Place.y-y
var/volume = 100-get_dist(src,Clicked_Place)*3 // This one works
view() << S


It doesn't work very well with the x and y variables (runtime errors), but if I erase them, the volume works.
Any tutorials?

Thanks!
Gooseheaded wrote:
> // random shooting proc behind this...
> var/sound/S = sound('Gunshot.mid') // ...
> S.x += Clicked_Place.x-x
> S.y += Clicked_Place.y-y
> var/volume = 100-get_dist(src,Clicked_Place)*3 // This one works
> view() << S
>


Try removing the "+"'s. Also, that volume variable won't do anything...


doesn't work very well with the x and y variables (runtime errors), but if I erase them, the volume works.

Can you post the errors?

Also, it might be worth noting that you've got your position variables mixed up:
sound.x = left and right
sound.y = above and below
sound.z = in front and behind

If you still can't get it to work, I'd be happy to post my version, but I figured you would want to try fixing yours first :)
In response to DarkCampainger
Alright, so this >should< be the fixed proc?
// random shooting proc behind this...
var/sound/S = sound('Gunshot.mid') // ...
S.x = Clicked_Place.x-x
S.y = Clicked_Place.y-y
var/Volume = 100-get_dist(src,Clicked_Place)*3 // This one works
view() << sound(S,volume=Volume) // Sorry for not adding this!

Lol, sorry. Look at the last line;sound(S,volume=Volume (that's what works. sorry about not posting that before).
And, I'm in school right now so I can't check out the version without the + 's.

But, thanks for the feedback;

P.S. I alredy know what x's, y's and z's do as sound's variables.
In response to Gooseheaded
Gooseheaded wrote:
Alright, so this >should< be the fixed proc?
> // random shooting proc behind this...
> var/sound/S = sound('Gunshot.mid') // ...
> S.x = Clicked_Place.x-x
> S.y = Clicked_Place.y-y
> var/Volume = 100-get_dist(src,Clicked_Place)*3 // This one works
> view() << sound(S,volume=Volume) // Sorry for not adding this!
>


It might work, but there's a good chance there'll be some problems with using sound() twice. I would suggest just using S.volume= ... and then just sending S to view().

P.S. I alredy know what x's, y's and z's do as sound's variables.

Are you sure? Because as it's set up now, if someone to the north of you shoots, it'll sound like someone on the floor above you is shooting.
In response to Gooseheaded
Gooseheaded wrote:
> var/Volume = 100-get_dist(src,Clicked_Place)*3 // This one works
>


If you're doing true 3D sound, with a soundcard that supports it, that line isn't needed. BYOND and your soundcard will automatically handle making sounds that are farther away sound quieter, and from the proper direction.
Your runtime errors are probably from Clicked_Place being invalid. (Also, why are you trying to play a MIDI as a sound effect instead of an actual wav or ogg file?) Setting the volume is not necessary if the position is set.

Furthermore, you should not send the sound to view(). The x and y coordinates you set are based on the individual listener; thus you need to recalculate them for each listener.

var/sound/S = new('gunshot.ogg')
for(var/mob/M in view())
if(M.client)
S.x = Clicked_Place.x-M.x
S.y = (Clicked_Place.y-M.y) / sqrt(2)
S.z = S.y
M << S


There's a reason I did that trick with y and z, and you'll see why if you read the BYONDscape article I've posted on this subject: Dream Tutor: Do You Hear What I Hear?

Lummox JR