Disabling Player Sprint Depending on Map

Hi,

I’ve attempted doing the following but it doesn’t work:


function GM:PlayerSpawn(ply)
		disableSprint(ply)
end


function disableSprint( ply )
	if game.GetMap() == "irr_Mitch" then
	ply:SprintDisable()
	end
end

I don’t suppose any of you know what the problem is?

It’s placed inside of “init.lua”.

< Reply =

Use this ! :>



hook.Add("PlayerAuthed", "SprintDisable", function( pl )
	if ( game.GetMap() == "irr_Mitch" ) then
		pl:SprintDisable()
	end
end)


Thank you for your effort, but that didn’t work :(.

I think the function is broken and you have to set it so than the run speed is equal to the walk speed.
ply:SetRunSpeed(ply:GetWalkSpeed())

This is what I now have:


function GM:PlayerSpawn(ply)
		disableSprint(ply)
end


function disableSprint( ply )
	if game.GetMap() == "irr_Mitch" then
	ply:SetRunSpeed(ply:GetWalkSpeed())
	end
end

This didn’t work, however.

Did your function GM:PlayerSpawn() work for you? I could never get that GM Hook to work. I just typed this up for you just incase it didn’t work.


 hook.Add("PlayerSpawn","NoSprint", function(pl)
pl:SprintDisable()
end) 

The code looks correct, although I’m not sure why it doesn’t work. Can you give us the error?

There is no error when I use that code too but it doesn’t work. GM:PlayerSpawn also works too because if add a “print” function it shows up in the console when the player spawns.



hook.Add("PlayerSpawn","NoSprint", function(pl)
    pl:SetRunSpeed(pl:GetWalkSpeed())
end)


I did a quick test and the code didn’t seem to work.

http://i.snag.gy/03oDP.jpg

I’d go with TylerB’s workaround.

It doesn’t prevent from sprinting, it merely stops sprinting, as if the player just released their sprint button.

I have solved it for him on steam: He was using a stamina script that was setting their speed dynamically.