Toggle Method

Status
Not open for further replies.
Messages
356
Reaction score
629
Points
430
Location
Netherlands
Hello everyone,

I’d like to introduce a simple way on how to toggle between certain actions/commands Ingame.

This guide is going to be a Step by Step guide with easy screenshots and instructions. Feel free to leave any question, comment or TIP in the comments.

The following steps are going to be an example on 'how to /me mutes his radio and /me unmutes his radio.' Meaning that whenever Goverment Members press their 'Default H' It would say *Mutes his radio* and *Unmutes his radio* whenever you press it again.

Step #1 – Locate the CFG Folder
Ws4XkTQ.png

Open the CFG Folder and continue to Step #2

Step #2 - Create a 'Text Document' as 'ToggleMute'
Tr2T54U.png

Open the Text Document you created and follow Step #3

Step #3 - Copy and paste the following code
Code:
alias mute_on "say /me mutes his radio; alias togglemute mute_off"
alias mute_off "say /me unmutes his radio; alias togglemute mute_on"
mute_off
bind h togglemute

Step #4 -Saving the code
The following screenshots will guide you on how to safe the code correctly.
  • 1 - 'Save as'
    FyrkQUh.png

  • 2 - 'All files'
    1Kanr60.png
  • 3 - 'ToggleMute.cfg'
    3N911KE.png
Save the file now, it should appear within your folder as a 'notepad'

Step #5 - Locate the 'autoexec.cfg' folder
1hTAr6c.jpg


Step #6 - Open the 'autoexec.cfg' and paste in the following
Code:
exec ToggleMute

Step #7 - Save the 'autoexec.cfg' folder (CTRL+S)

Q&A
Q: Am I able to use this same method on with other actions/command?
A: Yes, you can use this same method to create;for example, toggle crouch.
Q: How does the command work?
A: The command is pretty simple, the entire string of 'mini commands' is to create a simple toggle between certain commands. You are able to bind two commands to a single key ingame (bind {key} "{command1}; {command2}") this is practicly the same, you are only giving it a few names so the game registers it as a string of commands. Having it in the autoexec makes to boot up everytime you start Garry's Mod up.
Q: Does this requires you to restart Garry's Mod?
I No it does not, you can simply go into your ingame console and typ "exec {command name}" example: exec Toggleradio this will trigger the command in the 'autoexec.cfg' file and allows it to instantly work ingame.


Code:
alias {name1}_on "{command/action 1}; alias {name2} {name1}_off"
alias {name1}_off "{command/action 2; alias {name2} {name1}_on"
{name1}_off
bind {key} {name2}

Simply follow all the steps from before once you understand how to change to code for your commands.

How To: Give it a simple name so the code registers it {Name#1} add the command and or action. Give it a 2e name (name#2) this is so the game knows what command to execute whenever you boot up Garry's Mod. Fill the name#1 and name#2 for whatever you picked and add up a key and you are done.

Enjoy!
 
Last edited:
Here is a toggle button for voice chat, I've been used to play like this for years now and is also pretty useful if you want to micspam in CS:GO or any other Source game :^)
Code:
alias voicetoggle "voicetoggleon"
alias voicetoggleon "+voicerecord; alias voicetoggle voicetoggleoff"
alias voicetoggleoff "-voicerecord; alias voicetoggle voicetoggleon"
bind "v" "voicetoggle"
Replace "v" with your desired button.

+1 for the guide
 
Slight update resolving you having to quit the game

Update:
You do not have to disconnect or quit your game to have this work, follow all steps above and use the "exec" command in console manual.

3zwaGWH.png

This should trigger the command lines and make it work ingame instantly without having to disconnect/reconnect or by having to restart Garry's Mod at all.
 
Update:
I have slightly edited the guide to match the recent update to prevent you having to restart Garry's Mod.
See changes in the thread itself.
 
Update:
Sometimes it displayes that you mute/unmute your radio whenever you already had it either muted/unmuted so it would get mixed up.
Example: You have your radio muted and you press your H button to unmute it, it displays that you mute your radio instead.

Easy way to fix this is by simply pressing your B button (Radio Broadcasting) This way it kind of resets itself and you can resume your day again.
 
Status
Not open for further replies.
Back
Top