How do you make a player bind a key when they join the server?
I think garry blocked running that command people same as unbindall but I may be wrong.
You're right; he blocked a lot of commands which could be used maliciously.
Use KeyPress, PlayerBindPress, and other hooks to determine keys being pressed, then make a call in your code to do something.
[QUOTE=Acecool;43682219]You're right; he blocked a lot of commands which could be used maliciously.
Use KeyPress, PlayerBindPress, and other hooks to determine keys being pressed, then make a call in your code to do something.[/QUOTE]
How would I do use PlayerBindPress, I am crap with lua, and I don't wanna make it seem like saying "Do the work for me" or something, just where to put it and any other information would be great :)
Copying and pasting old test code, some commented out:
[lua]hook.Add( "PlayerBindPress", "BindsManager:PlayerBindPress", function( _p, bind, pressed )
-- local key = string.upper( input.LookupBinding( bind ) )
-- local _key = "KEY_" .. key;
-- print( _key, " ", pressed )
-- if ( key and pressed ) then
-- if (key == "MWHEELDOWN") then
-- stuff
-- return true
-- elseif ( key == "MWHEELUP" ) then
-- stuff
-- return true
-- end
-- end
end );[/lua]
You won't have the BIND_KEY_NAMES, but just print out _key
[lua]-- hook.Add( "KeyPress", "BindsManager:KeyPress", function( _p, _key )
-- print( "IN Press: " .. ( BIND_KEY_NAMES[ _key ] or _key ) )
-- end )
-- hook.Add( "KeyRelease", "BindsManager:KeyRelease", function( _p, _key )
-- print( "IN Release: " .. ( BIND_KEY_NAMES[ _key ] or _key ) )
-- end )[/lua]
These two don't work when holding multiple keys; it's flaky
[lua]//
// PlayerButtonUp/Down for KEY/MOUSE keys
// [url]http://wiki.garrysmod.com/page/Enums/KEY[/url]
// [url]http://wiki.garrysmod.com/page/Enums/MOUSE[/url]
//
-- hook.Add( "PlayerButtonDown", "BindsManager:PlayerButtonDown", function( _p, _key )
-- print( "BUTTON Press: " .. ( BIND_KEY_NAMES[ _key ] or _key ) )
-- end )
-- hook.Add( "PlayerButtonUp", "BindsManager:PlayerButtonUp", function( _p, _key )
-- print( "BUTTON Release: " .. ( BIND_KEY_NAMES[ _key ] or _key ) )
-- end )
[/lua]
There are tons of hooks to use. Some work with multiple keys, some don't. I settled on using the think hook for my binds manager; but then again I have an entire game-mode and about 40 different actions which can be bound to keys.
Sorry, you need to Log In to post a reply to this thread.