[Tutorial] How to toggle duck

Status
Not open for further replies.

Craynon

Member
Joined
Aug 31, 2011
Messages
47
Reaction score
0
Note: This is a rough approximation of a guide that used to be on these forums.

Tired of not being able to talk whilst crouching? Well fear not! I have a solution.

You're going to need to create three files in your C:\Program Files\Steam\steamapps\<Login Name>\garrysmod\garrysmod\cfg folder.

These files are:
  • autoexec.cfg
  • myaliases.cfg
  • mybindings.cfg


In autoexec.cfg, type:

Code:
exec myaliases.cfg
exec mybindings.cfg


In myaliases.cfg, type:

Code:
alias duck_t "duck_on"
alias duck_on "alias duck_t duck_off; +duck; developer 1; echo Crouching (on); developer 0"
alias duck_off "alias duck_t duck_on; -duck; developer 1; echo Crouching (off); developer 0"


In mybindings.cfg, type:

Code:
bind "<KEY>" "duck_t"

Remember to replace <KEY> with the key of your choice.

Then just save these three files, restart Gmod et Voilá! 1 custom crouch keybind!

Enjoy!
 
Ah, I remember this. You can just copypaste this whole block into aliases.cfg:

Code:
//Walk Toggle
alias walk_t "walk_on"
alias walk_on "alias walk_t walk_off; +forward; developer 1; echo Walking (on); developer 0"
alias walk_off "alias walk_t walk_on; -forward; developer 1; echo Walking (off); developer 0"

//Crouch Toggle
alias duck_t "duck_on"
alias duck_on "alias duck_t duck_off; +duck; developer 1; echo Crouching (on); developer 0"
alias duck_off "alias duck_t duck_on; -duck; developer 1; echo Crouching (off); developer 0"
 
Steve said:
Ah, I remember this. You can just copypaste this whole block into aliases.cfg:

Code:
//Walk Toggle
alias walk_t "walk_on"
alias walk_on "alias walk_t walk_off; +forward; developer 1; echo Walking (on); developer 0"
alias walk_off "alias walk_t walk_on; -forward; developer 1; echo Walking (off); developer 0"

//Crouch Toggle
alias duck_t "duck_on"
alias duck_on "alias duck_t duck_off; +duck; developer 1; echo Crouching (on); developer 0"
alias duck_off "alias duck_t duck_on; -duck; developer 1; echo Crouching (off); developer 0"

Ah, I forgot about the walk toggle. Cheers for that.
 
Or if you want,

Garrysmod>Garrysmod>Lua>Autorun>Client and create a Lua file with this inside,
function ToggleDuck(ply)
if (CLIENT) then
if not ply.TogD then ply.TogD = false end
if ply.TogD == false then
ply.TogD = true
ply:ConCommand("+duck")
else
ply.TogD = false
ply:ConCommand("-duck")
end
end
end
concommand.Add("ToggleDuck",ToggleDuck)

And bind toggleduck to whatever key you use to duck.
-Easy enough format to change this to allow you to toggle whatever you want.
 
Code:
concommand.Add('rp_toggleduck', function() RunConsoleCommand(LocalPlayer():KeyDown(IN_DUCK) and '-duck' or '+duck') end)

ply:ConCommand on LocalPlayer() is deprecated; the "ply" parameter is useless as it will always be LocalPlayer(), in addition the CLIENT check isn't required because, well, it's only executed on the client.
 
Zaubermuffin said:
Code:
concommand.Add('rp_toggleduck', function() RunConsoleCommand(LocalPlayer():KeyDown(IN_DUCK) and '-duck' or '+duck') end)

ply:ConCommand on LocalPlayer() is deprecated; the "ply" parameter is useless as it will always be LocalPlayer(), in addition the CLIENT check isn't required because, well, it's only executed on the client.

/shrug, Just a script that a guy with no knowledge of Lua touched.
 
No problem. I didn't mean to offend or anything, I just wanted to point out some things.
 
No matter what I do, it consistently says
Unknown command: duck_t
Unknown command: walk_t

And I swear I've done everything right. It worked before I reformatted my computer, I dunno why it's not working now. :<
 
Mifio said:
No matter what I do, it consistently says
Unknown command: duck_t
Unknown command: walk_t

And I swear I've done everything right. It worked before I reformatted my computer, I dunno why it's not working now. :<

Same here, I gave up after spending a day or two looking into this :(
 
One could simply bind my lua script too:
Code:
bind i "lua_run_cl RunConsoleCommand(LocalPlayer():KeyDown(IN_DUCK) and '-duck' or '+duck')"
 
Terribly sorry for bumping this, but does this still work?
 
The one in the OP does, yeah. It works for all source games and has perfectly for years in all Source games.
 
Status
Not open for further replies.

Users who are viewing this thread