I am trying to bind a key from a piece of lua code, but on wiki it says that it is part of the Restricted commands and it really doesn't work. Does anyone know how to bind a key? Like say: bind I open_window? Thanks in advance.
You can't bind keys through Lua without a module.
Ok, so I am a noob, how do I make/use a module?
I'm gonna take a wild guess here and assume you don't know much about C++ or making modules. Your best bet is use hooks. Unfortunately, there are no default gamemode hooks for when a player presses a key. Here's a simple thing I made a while ago:
[lua]// ########################
// HOOK: PlayerKeyPress
// DESC: Serverside hook that's call when a player presses a key
// ARGS: PLAYER pl, NUMBER key
// AUTH: Entoros
if SERVER then
concommand.Add("cl_keypress",function(pl,cmd,args)
local n = tonumber(args[1])
hook.Call("PlayerKeyPress",GAMEMODE,pl,n)
end)
else
local keys_pressed = {}
hook.Add("Think","CheckKeyPress",function()
for i =1, 130 do
if input.IsKeyDown( i ) then
if keys_pressed[i] then return end
RunConsoleCommand( "cl_keypress", i )
hook.Call("PlayerKeyPress",GAMEMODE,LocalPlayer(),i)
keys_pressed[i] = true
elseif keys_pressed[i] then keys_pressed[i] = nil
end
end
end)
end[/lua]
This would be a shared script.
So if you wanted to bind your menu to a key, you would do something like
[lua]hook.Add("PlayerKeyPress","BindMenu",function(pl,key)
if key == KEY_I then OpenMenu() end
end)
[/lua]
[QUOTE=Entoros;21410421][lua]hook.Add("PlayerKeyPress","BindMenu",function(pl,key)
if key == KEY_I then OpenMenu()
end)
[/lua][/QUOTE]
You missed an end :downs:
[QUOTE=MakeR;21410813]You missed an end :downs:[/QUOTE]
:sun:
Sorry, you need to Log In to post a reply to this thread.