[ZScript] Ambient Sound Objects

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Sarah
Posts: 551
Joined: Wed Sep 06, 2006 12:36 pm
Preferred Pronouns: She/Her
Operating System Version (Optional): Debian 11 (bullseye), Windows 10
Location: Middle of Nowheresville Il.
Contact:

[ZScript] Ambient Sound Objects

Post by Sarah »

Good evening everyone! I did some digging and I'm not finding conclusive answers, so I thought I'd ask, can an ambient sound object in a map be assigned a sound to play through ZScript? If so, how? Also if you could point me to the relevant source files, I'd also appreciate that; maybe I just overlooked something. Thank you!

*If not, gee darnit, that random idea just died a swift death, thank you still! :D
necros
Posts: 19
Joined: Mon Dec 30, 2019 10:26 pm
Contact:

Re: [ZScript] Ambient Sound Objects

Post by necros »

Through zscript? You could, but you can just use sndinfo:

Code: Select all

$AMBIENT 1 ambient/world/fan5		POINT CONTINUOUS 1
Plays sound with alias "ambient/world/fan5" on loop at volume 1 and this is assigned to "ambient sound 1" entity.

If you want to do it with zscript, you can, you could just make an invisible actor with TNTA frames. Here, I attached the sound to a decoration. This is decorate script, but you can do the exact same with zscript:

Code: Select all

actor neStrifeStandLamp 32010
{
	//$Category StrifeLights
	//$Title "Strife Stand Lamp"
	Height 76
	Radius 10
	ProjectilePassHeight -16
	+SOLID
	States
	{
		Spawn:
			TLMP BB 1 BRIGHT A_StartSound("ambient/world/ne_hum5", CHAN_BODY, CHANF_LOOPING, 0.02, 3.0)
		Idle:
			TLMP B 100 BRIGHT Light("ne_candelabra")
			Loop
	}
}
Couple of things to note: you need 2 frames. for whatever reason, the first frame doesn't execute any functions. Also of note, to avoid constantly calling the sound over and over, make a second state and do not put a loop into the spawn state. zdoom will play through the first state and drop into the second state then loop the second state only.
User avatar
Virathas
Posts: 249
Joined: Thu Aug 10, 2017 9:38 am

Re: [ZScript] Ambient Sound Objects

Post by Virathas »

Couple of things to note: you need 2 frames. for whatever reason, the first frame doesn't execute any functions.
Just for clarity why this happens - first function of the spawn state is never called, which is original doom design. To have it called you need the NoDelay keyword. For more details see [wiki]Actor states[/wiki]
User avatar
Sarah
Posts: 551
Joined: Wed Sep 06, 2006 12:36 pm
Preferred Pronouns: She/Her
Operating System Version (Optional): Debian 11 (bullseye), Windows 10
Location: Middle of Nowheresville Il.
Contact:

Re: [ZScript] Ambient Sound Objects

Post by Sarah »

Good morning! Thank you, necros and Virathas for replying! I very clearly wasn't clear enough about what I was asking, but I can also say that I wasn't 100% sure what I was looking for either. What I was primarily interested in was the ambient sound ID assigned to the "Custom Ambient Sound" object in DB; what I wanted to know was could I somehow access that variable from within, say, a ZScript event handler, allowing me to place a set number of objects and assign sounds to them at will. The answer seems to be: "You can probably do what your thinking, but not in the way you're thinking."

So what I'm thinking of doing: a dynamically generated soundscape system. Allow a level to have a set number of ambient sounds that will play regardless, but based on inputs, add or take some away. Now these inputs could/should be things the player is doing and events taking place in the level; health changes, objective accomplishments, etc. And finally so that the soundscape does not descend into a cacophony of out of time insanity, a sound could/should be described by a class that contains information, like root, beats per minute, etc. The soundscape itself should also specify a key; for example C, and scale (if it's pentatonic it has 5 notes instead of 7).

Lastly to not spend an inordinate amount of time on this idea, I thought the best course of action would be look into the ZDoom sound system; if I can't get sounds playing when I want them then the whole thing is pointless. So, thank you both again for your replies! I think this is doable in some form!

*Edit, I'm sure some audiophile is fingering their Pick of Destiny over my obvious lack of audio knowledge, I'm sorry! I haven't picked up a guitar in over a year and I'm sooo sad about it :D
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [ZScript] Ambient Sound Objects

Post by Player701 »

You can access the ambient sound ID of the ambient sound actor via its args array. The first value in the array (args[0]) is the ID, and from the looks of the source code it appears that you can change it dynamically in-game and it will be reflected accordingly.

However, I'm not sure why you want to use the built-in AmbientSound class considering that most of its behavior is hard-coded. What you've described is probably best done outside the constraints of any existing ambient sound functionality.
Post Reply

Return to “Scripting”