How to create a HUD toggle bind in Source engine games?












2















HUD is disabled with the cl_drawhud 0 command and enabled again with cl_drawhud 1. Additionally r_drawviewmodel 0 and r_drawviewmodel 1 can be used to toggle the viewmodel. Instead of pasting the commands into the console every time I want to capture a screenshot I'd prefer a hotkey to toggle (H would be sensible) which can be achieved by using alias, I believe.










share|improve this question























  • Then this might be useful. If not a duplicate as well.

    – Joachim
    yesterday
















2















HUD is disabled with the cl_drawhud 0 command and enabled again with cl_drawhud 1. Additionally r_drawviewmodel 0 and r_drawviewmodel 1 can be used to toggle the viewmodel. Instead of pasting the commands into the console every time I want to capture a screenshot I'd prefer a hotkey to toggle (H would be sensible) which can be achieved by using alias, I believe.










share|improve this question























  • Then this might be useful. If not a duplicate as well.

    – Joachim
    yesterday














2












2








2








HUD is disabled with the cl_drawhud 0 command and enabled again with cl_drawhud 1. Additionally r_drawviewmodel 0 and r_drawviewmodel 1 can be used to toggle the viewmodel. Instead of pasting the commands into the console every time I want to capture a screenshot I'd prefer a hotkey to toggle (H would be sensible) which can be achieved by using alias, I believe.










share|improve this question














HUD is disabled with the cl_drawhud 0 command and enabled again with cl_drawhud 1. Additionally r_drawviewmodel 0 and r_drawviewmodel 1 can be used to toggle the viewmodel. Instead of pasting the commands into the console every time I want to capture a screenshot I'd prefer a hotkey to toggle (H would be sensible) which can be achieved by using alias, I believe.







source-engine






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









user598527user598527

3,30422471




3,30422471













  • Then this might be useful. If not a duplicate as well.

    – Joachim
    yesterday



















  • Then this might be useful. If not a duplicate as well.

    – Joachim
    yesterday

















Then this might be useful. If not a duplicate as well.

– Joachim
yesterday





Then this might be useful. If not a duplicate as well.

– Joachim
yesterday










2 Answers
2






active

oldest

votes


















2














I am not sure, if all Source engine games do it this way, but in Team Fortress 2 I use the autoexec.cfg file together with a few additional files. >Reference to a relevant Portal 2 question



Of course, you can also use the syntax described below directly in the console as well - it just won't be persistent that way.



In the games config directory (e.g. Team Fortress 2/tf/cfg) you can find (or create if it isn't there) a file called autoexec.cfg. You should not change the existing config.cfg, but you can have a look into that file for further reference.



In this autoexec.cfg file we can add commands that will be automatically called on launch of the game. You should be able to add a line for your keybind in here. The syntax may look like the following:



bind "h" "incrementvar r_drawviewmodel 0 1 1"
bind "j" "incrementvar cl_drawhud 0 1 1"
host_writeconfig


This will toggle the r_drawviewmodel command each time you press the "h"-Button. The incrementvar keyword will count upwards from 0 until it reaches 1 by increments of 1 - that's how that works. It works the same on on the "j"-key with cl_drawhud. If you want to do both at the same time, you can use a semicolon to bind multiple command to one key:



bind "h" "incrementvar r_drawviewmodel 0 1 1; incrementvar cl_drawhud 0 1 1"
host_writeconfig


The last line is sometimes needed, sometimes not - it can be frickly and different from game to game in my experience.



In certain games sv_cheats might need to be set to 1 for this to work (I just encountered this problem in CS:GO).





You may also want to make sure to save the file in UTF-8 encoding, if it is not working. When using the Windows Notepad, there is a dropdown menu in the save file interface that reads ANSI by default.






share|improve this answer


























  • I know that host_writeconfig is mandatory in Counter-Strike: Global Offensive autoexec.

    – user598527
    yesterday











  • I recommend editing the command in your answer to bind "h" "incrementvar cl_drawhud 0 1 1", but it's good to mention the viewmodel command as well.

    – user598527
    yesterday











  • I edited my answer to include both commands that were mentioned in the question.

    – Faxter
    yesterday











  • Also, you might be able to put both commands onto one button by using a semicolon, but I have not tested that yet.

    – Faxter
    yesterday











  • I just confirmed that you can use both commands on one key using a semicolon to separate them - edited that into my answer.

    – Faxter
    yesterday



















1














You can use the following commands in your Source game (tested in Half-Life 2: Episode 2). Paste and enter one line at a time:



alias noHUD "HUD_toggle1"

alias HUD_toggle1 "cl_drawhud 0; r_drawviewmodel 0; alias noHUD HUD_toggle2"

alias HUD_toggle2 "cl_drawhud 1; r_drawviewmodel 1; alias noHUD HUD_toggle1"

bind "h" noHUD



The names of the functions eventually don't really matter.






share|improve this answer


























  • I'm using the commands in HL2: Episode 2 as well and haven't got the toggle to work yet. I paste everything at once to the console, right? Your formatting implies that the commands must be used individually. I will of course save the script in autoexec once it functions.

    – user598527
    yesterday








  • 1





    I think the last line should be "bind "h" noHUD", shouldn't it?

    – Faxter
    yesterday











  • @Faxter you are very right. And the lines should be fed to the console one at the time. Edited.

    – Joachim
    yesterday













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "41"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgaming.stackexchange.com%2fquestions%2f347153%2fhow-to-create-a-hud-toggle-bind-in-source-engine-games%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














I am not sure, if all Source engine games do it this way, but in Team Fortress 2 I use the autoexec.cfg file together with a few additional files. >Reference to a relevant Portal 2 question



Of course, you can also use the syntax described below directly in the console as well - it just won't be persistent that way.



In the games config directory (e.g. Team Fortress 2/tf/cfg) you can find (or create if it isn't there) a file called autoexec.cfg. You should not change the existing config.cfg, but you can have a look into that file for further reference.



In this autoexec.cfg file we can add commands that will be automatically called on launch of the game. You should be able to add a line for your keybind in here. The syntax may look like the following:



bind "h" "incrementvar r_drawviewmodel 0 1 1"
bind "j" "incrementvar cl_drawhud 0 1 1"
host_writeconfig


This will toggle the r_drawviewmodel command each time you press the "h"-Button. The incrementvar keyword will count upwards from 0 until it reaches 1 by increments of 1 - that's how that works. It works the same on on the "j"-key with cl_drawhud. If you want to do both at the same time, you can use a semicolon to bind multiple command to one key:



bind "h" "incrementvar r_drawviewmodel 0 1 1; incrementvar cl_drawhud 0 1 1"
host_writeconfig


The last line is sometimes needed, sometimes not - it can be frickly and different from game to game in my experience.



In certain games sv_cheats might need to be set to 1 for this to work (I just encountered this problem in CS:GO).





You may also want to make sure to save the file in UTF-8 encoding, if it is not working. When using the Windows Notepad, there is a dropdown menu in the save file interface that reads ANSI by default.






share|improve this answer


























  • I know that host_writeconfig is mandatory in Counter-Strike: Global Offensive autoexec.

    – user598527
    yesterday











  • I recommend editing the command in your answer to bind "h" "incrementvar cl_drawhud 0 1 1", but it's good to mention the viewmodel command as well.

    – user598527
    yesterday











  • I edited my answer to include both commands that were mentioned in the question.

    – Faxter
    yesterday











  • Also, you might be able to put both commands onto one button by using a semicolon, but I have not tested that yet.

    – Faxter
    yesterday











  • I just confirmed that you can use both commands on one key using a semicolon to separate them - edited that into my answer.

    – Faxter
    yesterday
















2














I am not sure, if all Source engine games do it this way, but in Team Fortress 2 I use the autoexec.cfg file together with a few additional files. >Reference to a relevant Portal 2 question



Of course, you can also use the syntax described below directly in the console as well - it just won't be persistent that way.



In the games config directory (e.g. Team Fortress 2/tf/cfg) you can find (or create if it isn't there) a file called autoexec.cfg. You should not change the existing config.cfg, but you can have a look into that file for further reference.



In this autoexec.cfg file we can add commands that will be automatically called on launch of the game. You should be able to add a line for your keybind in here. The syntax may look like the following:



bind "h" "incrementvar r_drawviewmodel 0 1 1"
bind "j" "incrementvar cl_drawhud 0 1 1"
host_writeconfig


This will toggle the r_drawviewmodel command each time you press the "h"-Button. The incrementvar keyword will count upwards from 0 until it reaches 1 by increments of 1 - that's how that works. It works the same on on the "j"-key with cl_drawhud. If you want to do both at the same time, you can use a semicolon to bind multiple command to one key:



bind "h" "incrementvar r_drawviewmodel 0 1 1; incrementvar cl_drawhud 0 1 1"
host_writeconfig


The last line is sometimes needed, sometimes not - it can be frickly and different from game to game in my experience.



In certain games sv_cheats might need to be set to 1 for this to work (I just encountered this problem in CS:GO).





You may also want to make sure to save the file in UTF-8 encoding, if it is not working. When using the Windows Notepad, there is a dropdown menu in the save file interface that reads ANSI by default.






share|improve this answer


























  • I know that host_writeconfig is mandatory in Counter-Strike: Global Offensive autoexec.

    – user598527
    yesterday











  • I recommend editing the command in your answer to bind "h" "incrementvar cl_drawhud 0 1 1", but it's good to mention the viewmodel command as well.

    – user598527
    yesterday











  • I edited my answer to include both commands that were mentioned in the question.

    – Faxter
    yesterday











  • Also, you might be able to put both commands onto one button by using a semicolon, but I have not tested that yet.

    – Faxter
    yesterday











  • I just confirmed that you can use both commands on one key using a semicolon to separate them - edited that into my answer.

    – Faxter
    yesterday














2












2








2







I am not sure, if all Source engine games do it this way, but in Team Fortress 2 I use the autoexec.cfg file together with a few additional files. >Reference to a relevant Portal 2 question



Of course, you can also use the syntax described below directly in the console as well - it just won't be persistent that way.



In the games config directory (e.g. Team Fortress 2/tf/cfg) you can find (or create if it isn't there) a file called autoexec.cfg. You should not change the existing config.cfg, but you can have a look into that file for further reference.



In this autoexec.cfg file we can add commands that will be automatically called on launch of the game. You should be able to add a line for your keybind in here. The syntax may look like the following:



bind "h" "incrementvar r_drawviewmodel 0 1 1"
bind "j" "incrementvar cl_drawhud 0 1 1"
host_writeconfig


This will toggle the r_drawviewmodel command each time you press the "h"-Button. The incrementvar keyword will count upwards from 0 until it reaches 1 by increments of 1 - that's how that works. It works the same on on the "j"-key with cl_drawhud. If you want to do both at the same time, you can use a semicolon to bind multiple command to one key:



bind "h" "incrementvar r_drawviewmodel 0 1 1; incrementvar cl_drawhud 0 1 1"
host_writeconfig


The last line is sometimes needed, sometimes not - it can be frickly and different from game to game in my experience.



In certain games sv_cheats might need to be set to 1 for this to work (I just encountered this problem in CS:GO).





You may also want to make sure to save the file in UTF-8 encoding, if it is not working. When using the Windows Notepad, there is a dropdown menu in the save file interface that reads ANSI by default.






share|improve this answer















I am not sure, if all Source engine games do it this way, but in Team Fortress 2 I use the autoexec.cfg file together with a few additional files. >Reference to a relevant Portal 2 question



Of course, you can also use the syntax described below directly in the console as well - it just won't be persistent that way.



In the games config directory (e.g. Team Fortress 2/tf/cfg) you can find (or create if it isn't there) a file called autoexec.cfg. You should not change the existing config.cfg, but you can have a look into that file for further reference.



In this autoexec.cfg file we can add commands that will be automatically called on launch of the game. You should be able to add a line for your keybind in here. The syntax may look like the following:



bind "h" "incrementvar r_drawviewmodel 0 1 1"
bind "j" "incrementvar cl_drawhud 0 1 1"
host_writeconfig


This will toggle the r_drawviewmodel command each time you press the "h"-Button. The incrementvar keyword will count upwards from 0 until it reaches 1 by increments of 1 - that's how that works. It works the same on on the "j"-key with cl_drawhud. If you want to do both at the same time, you can use a semicolon to bind multiple command to one key:



bind "h" "incrementvar r_drawviewmodel 0 1 1; incrementvar cl_drawhud 0 1 1"
host_writeconfig


The last line is sometimes needed, sometimes not - it can be frickly and different from game to game in my experience.



In certain games sv_cheats might need to be set to 1 for this to work (I just encountered this problem in CS:GO).





You may also want to make sure to save the file in UTF-8 encoding, if it is not working. When using the Windows Notepad, there is a dropdown menu in the save file interface that reads ANSI by default.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









FaxterFaxter

4839




4839













  • I know that host_writeconfig is mandatory in Counter-Strike: Global Offensive autoexec.

    – user598527
    yesterday











  • I recommend editing the command in your answer to bind "h" "incrementvar cl_drawhud 0 1 1", but it's good to mention the viewmodel command as well.

    – user598527
    yesterday











  • I edited my answer to include both commands that were mentioned in the question.

    – Faxter
    yesterday











  • Also, you might be able to put both commands onto one button by using a semicolon, but I have not tested that yet.

    – Faxter
    yesterday











  • I just confirmed that you can use both commands on one key using a semicolon to separate them - edited that into my answer.

    – Faxter
    yesterday



















  • I know that host_writeconfig is mandatory in Counter-Strike: Global Offensive autoexec.

    – user598527
    yesterday











  • I recommend editing the command in your answer to bind "h" "incrementvar cl_drawhud 0 1 1", but it's good to mention the viewmodel command as well.

    – user598527
    yesterday











  • I edited my answer to include both commands that were mentioned in the question.

    – Faxter
    yesterday











  • Also, you might be able to put both commands onto one button by using a semicolon, but I have not tested that yet.

    – Faxter
    yesterday











  • I just confirmed that you can use both commands on one key using a semicolon to separate them - edited that into my answer.

    – Faxter
    yesterday

















I know that host_writeconfig is mandatory in Counter-Strike: Global Offensive autoexec.

– user598527
yesterday





I know that host_writeconfig is mandatory in Counter-Strike: Global Offensive autoexec.

– user598527
yesterday













I recommend editing the command in your answer to bind "h" "incrementvar cl_drawhud 0 1 1", but it's good to mention the viewmodel command as well.

– user598527
yesterday





I recommend editing the command in your answer to bind "h" "incrementvar cl_drawhud 0 1 1", but it's good to mention the viewmodel command as well.

– user598527
yesterday













I edited my answer to include both commands that were mentioned in the question.

– Faxter
yesterday





I edited my answer to include both commands that were mentioned in the question.

– Faxter
yesterday













Also, you might be able to put both commands onto one button by using a semicolon, but I have not tested that yet.

– Faxter
yesterday





Also, you might be able to put both commands onto one button by using a semicolon, but I have not tested that yet.

– Faxter
yesterday













I just confirmed that you can use both commands on one key using a semicolon to separate them - edited that into my answer.

– Faxter
yesterday





I just confirmed that you can use both commands on one key using a semicolon to separate them - edited that into my answer.

– Faxter
yesterday













1














You can use the following commands in your Source game (tested in Half-Life 2: Episode 2). Paste and enter one line at a time:



alias noHUD "HUD_toggle1"

alias HUD_toggle1 "cl_drawhud 0; r_drawviewmodel 0; alias noHUD HUD_toggle2"

alias HUD_toggle2 "cl_drawhud 1; r_drawviewmodel 1; alias noHUD HUD_toggle1"

bind "h" noHUD



The names of the functions eventually don't really matter.






share|improve this answer


























  • I'm using the commands in HL2: Episode 2 as well and haven't got the toggle to work yet. I paste everything at once to the console, right? Your formatting implies that the commands must be used individually. I will of course save the script in autoexec once it functions.

    – user598527
    yesterday








  • 1





    I think the last line should be "bind "h" noHUD", shouldn't it?

    – Faxter
    yesterday











  • @Faxter you are very right. And the lines should be fed to the console one at the time. Edited.

    – Joachim
    yesterday


















1














You can use the following commands in your Source game (tested in Half-Life 2: Episode 2). Paste and enter one line at a time:



alias noHUD "HUD_toggle1"

alias HUD_toggle1 "cl_drawhud 0; r_drawviewmodel 0; alias noHUD HUD_toggle2"

alias HUD_toggle2 "cl_drawhud 1; r_drawviewmodel 1; alias noHUD HUD_toggle1"

bind "h" noHUD



The names of the functions eventually don't really matter.






share|improve this answer


























  • I'm using the commands in HL2: Episode 2 as well and haven't got the toggle to work yet. I paste everything at once to the console, right? Your formatting implies that the commands must be used individually. I will of course save the script in autoexec once it functions.

    – user598527
    yesterday








  • 1





    I think the last line should be "bind "h" noHUD", shouldn't it?

    – Faxter
    yesterday











  • @Faxter you are very right. And the lines should be fed to the console one at the time. Edited.

    – Joachim
    yesterday
















1












1








1







You can use the following commands in your Source game (tested in Half-Life 2: Episode 2). Paste and enter one line at a time:



alias noHUD "HUD_toggle1"

alias HUD_toggle1 "cl_drawhud 0; r_drawviewmodel 0; alias noHUD HUD_toggle2"

alias HUD_toggle2 "cl_drawhud 1; r_drawviewmodel 1; alias noHUD HUD_toggle1"

bind "h" noHUD



The names of the functions eventually don't really matter.






share|improve this answer















You can use the following commands in your Source game (tested in Half-Life 2: Episode 2). Paste and enter one line at a time:



alias noHUD "HUD_toggle1"

alias HUD_toggle1 "cl_drawhud 0; r_drawviewmodel 0; alias noHUD HUD_toggle2"

alias HUD_toggle2 "cl_drawhud 1; r_drawviewmodel 1; alias noHUD HUD_toggle1"

bind "h" noHUD



The names of the functions eventually don't really matter.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









JoachimJoachim

1,382218




1,382218













  • I'm using the commands in HL2: Episode 2 as well and haven't got the toggle to work yet. I paste everything at once to the console, right? Your formatting implies that the commands must be used individually. I will of course save the script in autoexec once it functions.

    – user598527
    yesterday








  • 1





    I think the last line should be "bind "h" noHUD", shouldn't it?

    – Faxter
    yesterday











  • @Faxter you are very right. And the lines should be fed to the console one at the time. Edited.

    – Joachim
    yesterday





















  • I'm using the commands in HL2: Episode 2 as well and haven't got the toggle to work yet. I paste everything at once to the console, right? Your formatting implies that the commands must be used individually. I will of course save the script in autoexec once it functions.

    – user598527
    yesterday








  • 1





    I think the last line should be "bind "h" noHUD", shouldn't it?

    – Faxter
    yesterday











  • @Faxter you are very right. And the lines should be fed to the console one at the time. Edited.

    – Joachim
    yesterday



















I'm using the commands in HL2: Episode 2 as well and haven't got the toggle to work yet. I paste everything at once to the console, right? Your formatting implies that the commands must be used individually. I will of course save the script in autoexec once it functions.

– user598527
yesterday







I'm using the commands in HL2: Episode 2 as well and haven't got the toggle to work yet. I paste everything at once to the console, right? Your formatting implies that the commands must be used individually. I will of course save the script in autoexec once it functions.

– user598527
yesterday






1




1





I think the last line should be "bind "h" noHUD", shouldn't it?

– Faxter
yesterday





I think the last line should be "bind "h" noHUD", shouldn't it?

– Faxter
yesterday













@Faxter you are very right. And the lines should be fed to the console one at the time. Edited.

– Joachim
yesterday







@Faxter you are very right. And the lines should be fed to the console one at the time. Edited.

– Joachim
yesterday




















draft saved

draft discarded




















































Thanks for contributing an answer to Arqade!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgaming.stackexchange.com%2fquestions%2f347153%2fhow-to-create-a-hud-toggle-bind-in-source-engine-games%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to label and detect the document text images

Vallis Paradisi

Tabula Rosettana