SetWalkSpeed, SetRunSpeed, SetCrouchedWalkSpeed, all do not work at all, but SetJumpPower works fine
5 replies, posted
I am trying to make an swep which spawns a non-solid object that should slow players down in a certain radius. However, with every method I have tried, the result is buggy lag-like rubber banding movement and I'm not sure where to go from here. I've been trying to use SetWalkPower and such commands to slow the player down near the entity, but they aren't working.
The basic idea of the script for the entity:
[code]
function ENT:Think()
if CLIENT then return end
for _, ply in pairs(player.GetAll()) do
local dist = (ply:GetPos() - self:GetPos()):Length()
if (dist < 128) then
-- slow code
else
-- return code if necessary
end
end
end
[/code]
I have tried using SetWalkSpeed as a test to see if I could get it working for running, as this seems like the most obvious solution:
[code]
if (dist < 128) then
if (ply:GetWalkSpeed() == 220) then
ply:SetWalkSpeed(80)
end
else
if not (ply:GetWalkSpeed() == 220) then
ply:SetWalkSpeed(220)
end
end
[/code]
It doesn't work at all. But if I change GetWalkSpeed and SetWalkSpeed to GetJumpPower and SetJumpPower, it works exactly how I would expect:
[code]
if (dist < 128) then
if (ply:GetJumpPower() == 160 or 200) then
ply:SetJumpPower(40)
end
else
if not (ply:GetJumpPower() == 160 or 200) then
ply:SetJumpPower(200)
end
end
[/code]
Simply running the following command on my server, regardless of whether it's on TTT or Sandbox, also results in absolutely nothing:
lua_run for _, v in pairs(player.GetAll()) do v:SetWalkSpeed(50) end
But the following command also works fine:
lua_run for _, v in pairs(player.GetAll()) do v:SetJumpPower(1000) end
By the way, none of this code gives me any lua errors. Please ignore or yell at me for any horrendous coding practices I might have but won't see because I'm a noob.
Is there something I'm missing or screwing up here?
Is there a better way than SetWalkSpeed and such to slow a player without causing rubber-banding (as a reaction force with ply:SetVelocity(-ply:GetVelocity)) would)?
Edit:
It turns out that it was related to the gamemode I was using it in. A friend suggested that TTT was overriding my values and he was right. Apparently TTT has some code in its tick function for the iron-sight that sets SetWalkSpeed and such every tick, and is why it looked like the commands weren't working for me. I fixed it by changing the code in player_ext slightly.
[code]lua_run for _, ply in pairs(player.GetAll()) do v:SetWalkSpeed(50) end[/code]
for _, [B]ply [/B]in pairs(player.GetAll()) do [B]v[/B]:SetWalkSpeed(50) end
I don't know if that's just an error in your post or actual code.
Your rubber banding problem is probably because you aren't setting the power on the server and client, if you only set it on one then client-prediction will be wrong.
[QUOTE=wh1t3rabbit;41641623][code]lua_run for _, ply in pairs(player.GetAll()) do v:SetWalkSpeed(50) end[/code]
for _, [B]ply [/B]in pairs(player.GetAll()) do [B]v[/B]:SetWalkSpeed(50) end
I don't know if that's just an error in your post or actual code.
Your rubber banding problem is probably because you aren't setting the power on the server and client, if you only set it on one then client-prediction will be wrong.[/QUOTE]
Thanks for the reply.
That's an error in the post, not the code. I wrote it on the fly and got mixed up. It's fixed now.
My problem with the SetWalkSpeed method is that it simply does not work and I have no idea why.
I'll try SetVelocity on both Client and Server and see if it changes anything, albeit I don't expect it to.
Are you sure that the original walk-speed is exactly 220?
I recommend using a dynamic effect. Basically have a radius, and as they get closer to the center they slow down, as they are farther away they gain speed.
I made a stamina system a while back that as you lose stamina, you dynamically start slowing down while running from the run speed to the walk speed. I call the SetRunSpeed on the server and it works.
The reason it may be jumpy is that it's activating and slowing you instantly, instead of a gradual slowing effect like a field is causing you to slow.
Try setting up some concommands on the server to ensure it's working.
so:
[lua]concommand.Add( "speeds", function( ply, cmd, args )
print( "Run Speed: " .. ply:GetRunSpeed( ) )
print( "Walk Speed: " .. ply:GetWalkSpeed( ) )
end )
concommand.Add( "setwalkspeed", function( ply, cmd, args )
if ( !args[ 1 ] ) then return; end
ply:SetWalkSpeed( tonumber( args[ 1 ] ) );
end )
concommand.Add( "setrunspeed", function( ply, cmd, args )
if ( !args[ 1 ] ) then return; end
ply:SetRunSpeed( tonumber( args[ 1 ] ) );
end )[/lua]
I asked a friend about it and it turns out that it was actually the gamemode (TTT) overriding whatever values I was setting in, and unrelated to my code. I was able to find a workaround.
Thanks anyways guys
[QUOTE=Leopardson;41643039]I asked a friend about it and it turns out that it was actually the gamemode (TTT) overriding whatever values I was setting in, and unrelated to my code. I was able to find a workaround.
Thanks anyways guys[/QUOTE]
Mind posting it? I'm struggling with the same thing atm.
Edit:
Oh, just had to overwrite the function.
Sorry, you need to Log In to post a reply to this thread.