Sounds for Walking and Running

Hi, I’m using this to change the footstep sounds for a job. However I would like to have two diffrent sounds, one for walking and this for running. How would I do this?


local Team = ply:Team()
    if Team == TEAM_CP then
	ply:EmitSound( "NPC_MetroPolice.RunFootstepLeft" )
	return true

Walking sound.


NPC_MetroPolice.FootstepLeft

You can either check if the player’s speed exceeds a certain value (

Entity:GetVelocity,

Vector:Length2D) or check their key input (

Player:KeyDown)

I got this error.


[ERROR] addons/darkrpmodification-master/lua/darkrp_customthings/jobs.lua:92: attempt to compare userdata with number
  1. unknown - addons/darkrpmodification-master/lua/darkrp_customthings/jobs.lua:92

This is how I did.


local Team = ply:Team()
    if Team == TEAM_CP and ply:GetVelocity() <= 100 then
	ply:EmitSound( "NPC_MetroPolice.FootstepLeft" )
	return true -- Don't allow default footsteps
	elseif Team == TEAM_CP and ply:GetVelocity() >= 100 then
	ply:EmitSound( "NPC_MetroPolice.RunFootstepLeft" )
	return true -- Don't allow default footsteps

Entity:GetVelocity returns a Vector, not a number. Thus the

Vector:Length2D, which returns the vector’s length (in this case, should be the player’s speed ignoring up/down speed).

Alright, this is new right here is new to me :s: How would I go about writing this?

GetVelocity returns a Vector out of a Entity (which Player inherits), and Length2D returns a number out of a Vector. So you have this:

[lua]
local speed = ply:GetVelocity():Length2D()
if (speed > 300) then
– sprinting…
else
– walking…
end
[/lua]

Thank you!

This works.


function GM:PlayerFootstep( ply, pos, foot, sound, volume, rf )
local speed = ply:GetVelocity():Length2D()
local Team = ply:Team()
if (speed > 150) then
if Team == TEAM_CP then
-- sprinting..
ply:EmitSound( "NPC_MetroPolice.RunFootstepLeft" )
elseif Team == TEAM_CP then
-- walking..
ply:EmitSound( "NPC_MetroPolice.FootstepLeft" )
end
end
end