ID:2612185
 
(See the best response by Magicsofa.)
Code:
var/sound/airlock_trigger = sound('airlock.ogg', falloff = 1)


obj
door
var/dooropen = 0
name = "Airlock"
icon = 'door.dmi'
icon_state = "door_closed"
density = 1
desc = "its a door, for F*** sake"










// begin procedures

/obj/door
Click()
if(icon_state == "door_closed")
world << airlock_trigger
icon_state = "door_opened"
density = 0
else
world << airlock_trigger
icon_state = "door_closed"
density = 1


Problem description:
Hello,

I am new to byond, I have a door that I can open and close, it will play the sound of an airlock opening. I need to only play it to those in the area or else everyone on the map will hear it.

I think there's a few different ways to handle this;

I have attempted falloff, it doesn't throw any errors but whenever falloff is introduced with any number in there the sound doesnt play at all.

More importantly, I want to get a list of all mobs in an area, the area this door is in is /area/startregion; i have attempted things like /area/startregion.contents but this throws an error.

Any help would be appreciated


Best response
Falloff for 3D sounds already defaults to 1, so you don't need to set it.

What you do need is to give the sound object coordinates. Also, since it happens regardless of whether the door is closing or opening, I moved it out of the if-else block:

/obj/door
Click()
if(icon_state == "door_closed")
icon_state = "door_opened"
density = 0
else
icon_state = "door_closed"
density = 1
airlock_trigger.x = x - usr.x
airlock_trigger.y = y - usr.y
usr << airlock_trigger


I only output the sound to usr here, if you want multiple players to hear it then you'll need to loop through them somehow and get the x and y values for each. I almost always keep a list of player mobs for just this kind of purpose. But, getting the list from an area could work too.

You can't use the type path to access variables. /area/startregion is just a type, rather than an instance. It could be defined but if you never place it on the map or generate it otherwise, there will be no instances of it to use. It sounds like you did paint it onto the map so you should be able to access it easily. One thing to note is that areas are referenced by the turfs they contain, with their loc var. So the door object's loc is a turf, but that turf's loc is the area startregion.

Also keep in mind that areas are restricted to only one instance at a time. So if you had a startregion area on every z level of your map, that would still only be one area.

Anyway, to get the mobs in that area you could do something like this:

/obj/door
Click()
var/myArea = loc.loc //it looks silly but it works
for(var/mob/M in myArea)
//do stuff


MagicSofa

Thank you for that last block of code and your thorough explanation! This resolved the issue