Is there a way to limit a players maximum velocity (when bhopping) without having to check their velocity and alter it?
I know it would be possible checking on a players velocity and then changing it if it goes over a value but that seems horrendously inefficient to do - I was hoping for something that can be set and would restrict them going over a certain speed.
Something like physenv's maxvelocity (but it doesn't affect players) or sv_maxvelocity which seems to have no affect.
I don't think you can get around looking at their velocity.
You could try adding a hook to GM:OnPlayerHitGround(). Check their velocity, and if it's too high, slow them down.
Don't worry abuot inefficiency. There's a lot more "inefficient" stuff going on in the background compared to a GetVelocity inside a think hook for every player.
[code]
local maxspeed = 1000
maxspeed = maxspeed*maxspeed
hook.Add("Think", "Limit", function()
for k,v in pairs(player.GetAll()) do
local speed = v:GetVelocity():LengthSqr()
if speed > maxspeed then
v:SetVelocity(v:GetVelocity():GetNormal() * math.min(speed, maxspeed))
end
end
end)
[/code]
Try something like this.
SetVelocity adds to their current velocity, you want to use SetLocalVelocity.
[QUOTE=Donkie;41592270]Don't worry abuot inefficiency. There's a lot more "inefficient" stuff going on in the background compared to a GetVelocity inside a think hook for every player.
[code]
local maxspeed = 1000
maxspeed = maxspeed*maxspeed
hook.Add("Think", "Limit", function()
for k,v in pairs(player.GetAll()) do
local speed = v:GetVelocity():LengthSqr()
if speed > maxspeed then
v:SetVelocity(v:GetVelocity():GetNormal() * math.min(speed, maxspeed))
end
end
end)
[/code]
Try something like this.[/QUOTE]
Thanks for the replies - I'm always uncertain about how inefficient things are so if this isn't bad then its good to know.
I realized that though setting the speed server side does work it causes horrendous game play for the clients as the latency causes differences between server/client positions so when the velocity is corrected they see their player jerk around.
[QUOTE=Jonzky;41593208]Thanks for the replies - I'm always uncertain about how inefficient things are so if this isn't bad then its good to know.
I realized that though setting the speed server side does work it causes horrendous game play for the clients as the latency causes differences between server/client positions so when the velocity is corrected they see their player jerk around.[/QUOTE]
Then just add the hook on the client so it is the same as the server? Change the coding a bit, and it should be all fine.
Play around with CMoveData in the Move and SetupMove hooks.
[URL]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0908.html[/URL]
Why would you want to do that?
ok den
[LUA]
if velocity > 10 then velocity = 0 end
[/LU]
[/alu]
/I];IA
[/LIA]
[/LUA[
[/ALU
[/LUA]
You could do sv_maxvelocity in the console and it will constraint it close to that value.
[QUOTE=CrashLemon;41594478]Play around with CMoveData in the Move and SetupMove hooks.
[URL]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0908.html[/URL][/QUOTE]
This seems the most promising to me - I never knew about it. Thanks.
I'm out of the country until Monday but when I get back I'll post my solution if/when I find it.
I tried setting sv_maxvelocty but it didn't have any noticeable affect on speed and it also stopped people taking fall damage.
I believe this worked for me, thanks for the help.
[code]
local MAX_SPEED = 800
function speedLimiter(ply, data)
local speed = ply:GetVelocity():Length()
if speed > MAX_SPEED then
data:SetVelocity(ply:GetVelocity() * (MAX_SPEED/speed))
end
end
hook.Add("Move", "Speed Limit", speedLimiter)
[/code]
Sorry, you need to Log In to post a reply to this thread.