Randomizing On Hit Sounds

Ask about editing graphics, sounds, models, music, etc here!
Shaders (GLSL) and SNDINFO questions also go here!

Moderators: GZDoom Developers, Raze 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.
Post Reply
User avatar
Mr. Fancy Pants
Posts: 16
Joined: Wed Apr 04, 2018 4:06 pm
Location: Housewares

Randomizing On Hit Sounds

Post by Mr. Fancy Pants »

I'm attempting to alter the hit sound for a specific weapon to go from playing only a single sound file to playing one of three sound files at random. I've identified the line that pertains to the sound in the wad's sndinfo.txt file as

Code: Select all

weapons/tink    tink
I've tried simply changing it to:

Code: Select all

weapons/tink    tink tink2 tink3
as well as adding in more lines like:

Code: Select all

weapons/tink    tink

Code: Select all

weapons/tink    tink2

Code: Select all

weapons/tink    tink3
however with all of these I'm just getting the standard tink sound. Any ideas?
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: Randomizing On Hit Sounds

Post by Blue Shadow »

You need to use the $random command. Look it up [wiki=SNDINFO]here[/wiki].
User avatar
Mr. Fancy Pants
Posts: 16
Joined: Wed Apr 04, 2018 4:06 pm
Location: Housewares

Re: Randomizing On Hit Sounds

Post by Mr. Fancy Pants »

I know about that command, but I have no clue what a aliasname, logicalname or lumpname is.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Randomizing On Hit Sounds

Post by wildweasel »

lumpname is the name of the file inside your WAD or PK3. Therefore, if it's called DSPISTOL, DSPISTOL is the lump's name. logicalname is what the individual entry is in SNDINFO - if the line reads like:

Code: Select all

weapons/pistol DSPISTOL
then weapons/pistol is the logical name to DSPISTOL's lump name.

When using $random, you give it a list of logical names, then define which lumps they go to. So if you have 3 tink sounds, you'd probably have something looking like this:

Code: Select all

$random weapons/tink { tink1 tink2 tink3 }
tink1 TINK1
tink2 TINK2
tink3 TINK3
Then any time you need to play a tink sound, you'd specify weapons/tink and ZDoom will pick randomly from the three in the list.
User avatar
Mr. Fancy Pants
Posts: 16
Joined: Wed Apr 04, 2018 4:06 pm
Location: Housewares

Re: Randomizing On Hit Sounds

Post by Mr. Fancy Pants »

Yea sorry about that silly last post, I figured it out through some experimentation. Final code looks like this and functions perfectly:

Code: Select all

$random weapons/tink    {weapons/tink1 weapons/tink2 weapons/tink3}
weapons/tink1 tink
weapons/tink2 tink2
weapons/tink3 tink3
User avatar
Mr. Fancy Pants
Posts: 16
Joined: Wed Apr 04, 2018 4:06 pm
Location: Housewares

Re: Randomizing On Hit Sounds

Post by Mr. Fancy Pants »

Well, now I'm having trouble replicating the same behavior with a different weapon.

SNDINFO:

Code: Select all

$random weapons/wiff {weapons/wiff1 weapons/wiff2 weapons/wiff3 weapons/wiff4}
weapons/wiff1 wiff1
weapons/wiff2 wiff2
weapons/wiff3 wiff3
weapons/wiff4 wiff4
Decorate code:

Code: Select all

fire:	
		axeg BCDE 1
		tnt1 a 2
		axeg F 1 A_PlayWeaponSound("weapons/wiff")
		axeg G 1 A_CustomPunch(6,0,0,"axePuff2")
		axeg H 1 
		tnt1 a 5 
		axeg Edcb 1
		axeg A 0 A_ReFire	
		Goto Ready
All 4 of my "wiff" sounds are in OGG format, if that matters.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Randomizing On Hit Sounds

Post by Enjay »

Looks right to me. Is it not working entirely (i.e. no sound) or is it just that the randomisation isn't happening?

If it's the former, obvious checks - are the ogg files actually in your project? Are they in the sounds folder?
User avatar
Mr. Fancy Pants
Posts: 16
Joined: Wed Apr 04, 2018 4:06 pm
Location: Housewares

Re: Randomizing On Hit Sounds

Post by Mr. Fancy Pants »

It's just flat out not playing at all. Ogg files are in the wad files sounds folder.
User avatar
Mr. Fancy Pants
Posts: 16
Joined: Wed Apr 04, 2018 4:06 pm
Location: Housewares

Re: Randomizing On Hit Sounds

Post by Mr. Fancy Pants »

I did find out that editing the decorate code from:

Code: Select all

axeg F 1 A_PlayWeaponSound("weapons/wiff")
to:

Code: Select all

axeg F 1 A_PlayWeaponSound("weapons/wiff1")
does cause my wiff1 sound to be played, and making it wiff2 causes wiff2 to play etc.

Not sure why it isn't reading it otherwise.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Randomizing On Hit Sounds

Post by Enjay »

What happens if you bring down the console and type

playsound weapons/wiff

:?:
User avatar
Mr. Fancy Pants
Posts: 16
Joined: Wed Apr 04, 2018 4:06 pm
Location: Housewares

Re: Randomizing On Hit Sounds

Post by Mr. Fancy Pants »

Enjay wrote:What happens if you bring down the console and type

playsound weapons/wiff

:?:
No message at all and no sound playing - it doesn't give me the "not a sound" message.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Randomizing On Hit Sounds

Post by Enjay »

That's odd because I just used an exact copy/paste of the code that you posted and it worked perfectly for me using some ogg files I have lying around here.

do

playsound weapons/wiff1

playsound weapons/wiff2

playsound weapons/wiff3

and

playsound weapons/wiff4

work?
User avatar
Hexereticdoom
Posts: 652
Joined: Thu Aug 08, 2013 1:30 pm
Graphics Processor: nVidia with Vulkan support
Location: Spain
Contact:

Re: Randomizing On Hit Sounds

Post by Hexereticdoom »

Hello there, if for some weird reason the sound randomize function is not working correctly, as a last resort you could try this alternative Decorate code that should work always:

Code: Select all

Fire:   
      AXEG BCDE 1
      TNT1 A 2
      TNT1 A 0 A_Jump(128, 2, 3, 4)
      AXEG F 1 A_PlayWeaponSound("weapons/wiff1")
      Goto EndFire
      AXEG F 1 A_PlayWeaponSound("weapons/wiff2")
      Goto EndFire
      AXEG F 1 A_PlayWeaponSound("weapons/wiff3")
      Goto EndFire
      AXEG F 1 A_PlayWeaponSound("weapons/wiff4")
      Goto EndFire
EndFire:
      AXEG G 1 A_CustomPunch(6, 0, 0, "AxePuff2")
      AXEG H 1
      TNT1 A 5
      AXEG EDCB 1
      AXEG A 0 A_ReFire   
      Goto Ready
Hope this helps! 8-)
Post Reply

Return to “Assets (and other stuff)”