Multiple Jumping Sounds?

Status
Not open for further replies.

Mimoz

Member
I'm currently in the process of making my first legit character WAD with custom sprites. I'm planning on using voice lines for some actions such as jumping and spindashing, but hearing the same thing over and over again can get irritating. Is there a script or a way that could allow for a random sound clip out of a few to play instead of the default jumping sound? I have absolutely no experience in scripting, so I'm a bit lost.
 
I don't have time to look at the exact code you'd need right now, but I know that you can use Lua to make sounds play at certain moments. If you use one of the random functions (such as P_RandomChance), you can add a chance for a certain sound to play when jumping.

There are also four slots for pain and death that you can use for the game to choose between randomly, though you may have already known that.
 
One way to do it would be to use a blank sound file for the jump and then in Lua check every time the player is pressing the jump button without holding it, without pressing it just willy nilly in midair, and then use a random function as Cobalt said to pick a sound that should be played.
 
With the technical side of how you'd insert a function to decide when the voice line is played sorted, I'd just like to say that I'm rather fond of Shantae's solution of having the first use of an action in a while give the voice line, and subsequent uses not playing it (except randomly sometimes). They really got it just right on there, IMO.
 
Funny you should mention that. There's a function in both my metronome and wisps mod that does just that. For metronome, it calls a random function, but for wisps it calls a random voice upon double jump.

Code:
function A_ChooseRandomSound(mobj)
	local randomvoice = P_RandomRange(1, 4) //checks for a random number between 1 and 4, inclusive
	if not S_SoundPlaying(mobj, sfx_voice1)
	and not S_SoundPlaying(mobj, sfx_voice2)
	and not S_SoundPlaying(mobj, sfx_voice3)
	and not S_SoundPlaying(mobj, sfx_voice4) //don't play the voice if you're already speaking!
		//Random voice checks start here
		if (randomvoice == 1)
			S_StartSound(mobj, sfx_voice1)
		elseif (randomvoice == 2)
			S_StartSound(mobj, sfx_voice2)
		elseif (randomvoice == 3)
			S_StartSound(mobj, sfx_voice3)
		elseif (randomvoice == 4)
			S_StartSound(mobj, sfx_voice4)
		end
	end
end

Try this, for example, but replace sfx_voice1 through sfx_voice4 on all lines that use it with your own sfx. Be sure to make freeslots for them, too.
 
The fun thing is that sfx_ constants are actually numbers, so if you freeslot all the sfx_voicen's in a row you can just do S_StartSound(mobj, sfx_voice1 + P_RandomKey(4)) - I replaced RandomRange with RandomKey because key is from 0 to n-1, and we DO want voice1 to happen sometimes.

A fun little shortcut.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top