• PlayerFootstep HELP!!
    6 replies, posted
So basically, i'm doing a mod that replaces the footsteps sounds, but as the "sprinting" sound assumes the same sound file as the "walking" sound and i want them to be different, i got this hook, but the problem is, it replaces every single kind of footstep, for example, i just wanted this hook for the dirt surface and i would make another hook with different sounds for the tile surface, can anyone help me? I would be glad. Thanks. Regards. [B]The code:[/B] function NewFootstepSound( ply, pos, foot, sound, volume, rf ) if ply:KeyDown(IN_SPEED) then ply:EmitSound("player/footsteps/_dirt"..math.random(1,4)..".wav") else ply:EmitSound("player/footsteps/dirt"..math.random(1,4)..".wav") end return true end hook.Add(""PlayerFootstep"","NewFootstepSound",NewFootstepSound)
Firstly, please use [noparse][code]...[/code][/noparse] tags when posting code; it makes it far easier for people to read. I'm not sure whether it's just how it's been pasted, but the code has some fundamental errors. I've cleaned it up here: [code] local function NewFootstepSound( ply, pos, foot, sound, volume, rf ) if ply:KeyDown(IN_SPEED) then ply:EmitSound("player/footsteps/_dirt"..math.random(1,4)..".wav") else ply:EmitSound("player/footsteps/dirt"..math.random(1,4)..".wav") end return true end hook.Add("PlayerFootstep", "NewFootstepSound", NewFootstepSound) [/code] Also, it's a good idea to seed the random numbers with [url=http://wiki.garrysmod.com/page/math/randomseed]math.randomseed[/url]. In terms of differing sounds for surface, the simplest way is to use the [i]sound[/i] argument passed to the hook to work out which default sound is about to be played, then determine your alternative sound based on that.
Actually, another alternative would be playing the same sound just with a higher pitched if holding down the sprint key Player:EmitSound( Sound, 100, math.random( 95, 105 ) + ( Player:KeyDown( IN_SPEED ) and 50 or 0 ) ) Where "Sound" is the variable from your function parameter. The random is just for some pitch variation. Sorry I can't answer your question as I've never done anything like that. Edit: Actually, Freeman's idea is better.
Okay thanks, can you just explain the surface thing a little bit more detailed please? I didn't really get it >.>
Well, since freeman didn't respond... As declared in your function "sound" is one of your parameters, if you were to print that variable you would see the sound-path that is about to be played. What he meant was, check what sound is about to be played ( Because these sounds are dependent on surface ) and then actually play your custom sound.
Oh god i'm so lost, can one of you add me on steam please? ;-; [url]http://steamcommunity.com/profiles/76561198062725207/[/url]
I've added you on Steam. :downs:
Sorry, you need to Log In to post a reply to this thread.