ply:SetDuckSpeed

I need some help with SetDuckSpeed. I am knowledgable in scripting for plugins in other source games with python and pawn but I am new to lua and gmod standards, etc. Can someone explain to me how I would use this (I assume in shared.lua?) I just need to know how to set up a function and make it used when the player spawns, so that when they crouch it crouches instantly. For some reason I cannot get it working!

Thanks :unsmith:

p.s. http://wiki.garrysmod.com/?title=Player.SetUnDuckSpeed = broken?

Those 2 functions needs to be called serverside. wrap them around a “if SERVER then… end” statement.

Works great, thanks!
[lua]
if SERVER then
function DuckFix()
for _, ply in pairs(player.GetAll()) do
ply:SetDuckSpeed(0.0)
ply:SetUnDuckSpeed(0.0)
end
end
end
hook.Add(“PlayerInitialSpawn”, “DuckFix”, DuckFix)
[/lua]

Does this look okay? It works but I’m not sure if it is good code…

PlayerInitialSpawn takes an argument that is the spawned player, use that instead of iterating all players.

And put the hook.Add inside the if SERVER then statement.

[lua]
if SERVER then
function DuckFix(ply)
ply:SetDuckSpeed(0.20)
ply:SetUnDuckSpeed(0.20)
end
hook.Add(“PlayerInitialSpawn”, “DuckFix”, DuckFix)
end
[/lua]

:unsmith:

You may want to localize that function.

local function DuckFix(ply)
othershit
end

if you were in doubt :slight_smile:

thank you guys, i think i am getting the hang of functions!

IIRC you need to call it clientside as well for the camera to work properly.

!?!:psyboom:

I’m pretty sure the wiki says to call it shared.

I changed it to shared and it’s less buggy when I spam crouch and jump, thanks.

No problem.