• Aliasing bind
    23 replies, posted
Hey, I was wondering how can I Alias the command "bind" garry thought it would be funny to block it, so I can't use it. [code] concommand.Add("blah", function() RunConsoleCommand("alias", "bind", ""luabind"") RunConsoleCommand("luabind", "mouse4", "concommand") end) [/code] Would that work? So that I can bind keys through lua? Whenever I Just RunConsoleCommand("bind", "-", "command") it says bind is blocked.
alias is blocked too.
How can I go about using bind?
so something like [code] if(input.IsKeyDown(KEY_SPACE)) then print "Hello" end [/code]
It seems (to me), that it may be easier to do this [b]Stolen Wiki Code Alert[/b] [code] local players = player.GetAll() for _, player in ipairs( players ) do if( player:KeyPressed( IN_FORWARD ) ) then Msg( "You pressed the forward key!\n" ) end end[/code] rather then [code]function KeyPressed (P, key) Msg (P:GetName().." pressed "..key.."\n") end hook.Add( "KeyPress", "KeyPressedHook", KeyPressed )[/code]
So then the second one is more efficient, from what it sounds like. Where it says function KeyPressed(P, key) do I replace that with function whatever(P, KEY_SPACE)
I see. Thanks.
No problem. Another small thing is that hook will only work for KEY_* enums, IN_* and MOUSE_* enums will not work!
I see, thanks. Also I would like to make a test script for you to check out and make sure it is being written properly and works. [code]function KeyPressed (P, key) if key == KEY_SPACE then LocalPlayer():ConCommand("+whatever") end end hook.Add( "KeyPress", "KeyPressedHook", KeyPressed )[/code] I don't think it will work, that's why I am trying to make sure.
KEY_ CANNOT be used in KeyPress. Only IN_ enums can. This hook is for binds, not for real-life buttons. So, IN_JUMP should be used instead of KEY_SPACE. And, proper calling is KeyPressed(pl,IN_JUMP), because this hook ONLY launched when SPECIFIED button is pressed. "key" is not a button. Right code: [lua] function KeyPressed (P, IN_JUMP) P:ConCommand("+whatever") end hook.Add( "KeyPress", "KeyPressedHook", KeyPressed ) [/lua]
That is not correct. [lua] local function KeyPress( pl, key ) if key == IN_JUMP then pl:ConCommand( "+whatever;" ) end end local function KeyRelease( pl, key ) if key == IN_JUMP then pl:ConCommand( "-whatever;" ) end end hook.Add( "KeyPress", "+whatever.KeyPress", KeyPress ) hook.Add( "KeyRelease", "+whatever.KeyRelease", KeyRelease ) [/lua] Might have some errors, but that's more along the lines of what it is supposed to be.
Alright, both of your inputs helped alot, but, what if you are not specifically trying to do it with the space bar, then what? Like what if I want to bind m for example or q? What do you do then?
[QUOTE=c-unit;25486270]Alright, both of your inputs helped alot, but, what if you are not specifically trying to do it with the space bar, then what? Like what if I want to bind m for example or q? What do you do then?[/QUOTE] [url]http://wiki.garrysmod.com/?title=IN_KEYS[/url]
Oh, thanks!
[QUOTE=SiPlus666;25482563] And, proper calling is KeyPressed(pl,IN_JUMP), because this hook ONLY launched when SPECIFIED button is pressed. "key" is not a button. Right code: [lua] function KeyPressed (P, IN_JUMP) P:ConCommand("+whatever") end hook.Add( "KeyPress", "KeyPressedHook", KeyPressed ) [/lua][/QUOTE] And why would that work at all? It's not like this in any programming/scripting languages, this is syntax 101.
What do you mean notRzilla
He means SiPlus666 went full retard
lol
[QUOTE=c-unit;25517260]What do you mean notRzilla[/QUOTE] He's trying to compare a value with a hook by re-defining the value whilst defining the function. tl;dr he's a retard.
oh, lol.
Sorry, you need to Log In to post a reply to this thread.