• Lua for making a server wide keybind make you say something in chat?
    8 replies, posted
What lua would make a server wide keybind make you say something in chat?
[URL="https://wiki.garrysmod.com/page/input/IsKeyDown"]input.IsKeyDown()[/URL]
Also, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/ConCommand]Player:ConCommand[/url] with 'say YOUR STRING HERE' as the command
Can I get an example using both of those?
Not tested and probably not the best answer but I would probably do something like this. The isHeld variable is because the function is called every tick from the Think hook, so we need to make sure that the message is only said once per key press. [CODE]local isHeld = false function keyBind() if input.IsKeyDown(KEY_[your key here]) then if !isHeld then isHeld = true LocalPlayer():ConCommand("say [your message here]") end else isHeld = false end end hook.Add("Think", "Key Bind Think", keyBind)[/CODE]
[QUOTE=Techicep;50452357]Not tested and probably not the best answer but I would probably do something like this. The isHeld variable is because the function is called every tick from the Think hook, so we need to make sure that the message is only said once. [CODE]local isHeld = false function keyBind() if (input.IsKeyDown(KEY_[your key here]) && !isHeld) isHeld = true LocalPlayer():ConCommand("say [your message here]") else isHeld = false end end hook.Add("Think", "Key Bind Think", keyBind)[/CODE][/QUOTE] No point in adding the isheld variable if you're going to run LocalPlayer():ConCommand() after checking if the key is down.
[QUOTE=Tupac;50452363]No point in adding the isheld variable if you're going to run LocalPlayer():ConCommand() after checking if the key is down.[/QUOTE] I just noticed that right after I posted, I fixed it already :p
Why not use [URL="http://wiki.garrysmod.com/page/GM/KeyPress"]GM/KeyPress[/URL]
[QUOTE=Liquidsocks;50454339]Why not use [URL="http://wiki.garrysmod.com/page/GM/KeyPress"]GM/KeyPress[/URL][/QUOTE] KeyPress uses [url=http://wiki.garrysmod.com/page/Enums/IN]IN enums[/url] which means it only works with existing binds. IsKeyDown works with [url=https://wiki.garrysmod.com/page/Enums/KEY]KEY enums[/url] which work with the whole keyboard.
Sorry, you need to Log In to post a reply to this thread.