How to do a KeyPressed Hook

Hi guys Facepunch

I’m making an addon in this, I wanted to make when pressing a button, the player becomes a ragdoll, and this, ovio, lies on the floor until you press a key, but this never happens, why?

You try everything, but I can not put the correct function or the code for this to happen: S

Here’s the code that did not work, I would like to note that use a “if SERVER then” because otherwise the ragdoll would not work hehe

[LUA]function reset(ply)
if( player:KeyDown( IN_FORWARD ) ) then
Msg( "You pressed the forward key!
" )
end
end
[/LUA]

Thanks for see

I see a function and no hook.

Sorry if I sound bad, I’m no0b to this … I want is that when you press something, something happens …

Your current code is in a function. The function won’t run unless you tell it to.

[lua]
function Reset(P, key)
if (key == “IN_FORWARD”) then
Msg(P…" pressed the "…key)
end

hook.Add( “KeyPress”, “KeyPressedHook”, Reset) --Hooks are triggered based on what type of hook it is.
–This hook is a “KeyPress” hook. So when any key is pressed it will trigger the function that is tied to it.
–With this example it is the Reset function.
– Hooks look like this: hook.Add(“HookType”, “HookName”, functionToRun)
– Hook Name can be anything.
[/lua]

You’re missing an “end”

[lua]
function Reset(P, key)
if (key == “IN_FORWARD”) then
Msg(P…" pressed the "…key)
end
end

hook.Add( “KeyPress”, “KeyPressedHook”, Reset)[/lua]

Thanks guys :smiley: