Volume control script

Cool tips, tricks, FAQs, scripts, binds, etc.
Post Reply
Renegade
HLDJ Developer
HLDJ Developer
Posts: 1500
Joined: Sat Mar 01, 2008 2:02 pm
Contact:

Volume control script

Post by Renegade »

To easily control volume (or other variable) levels, cyclical aliasing works best: (hint: you can place the following code into a script file, such as your userconfig or hldj_custom.cfg)

Code: Select all

// Renegade's volume script
// set initial volume to 0.5 (or whatever you want)
volume 0.5

// set initial up/down aliases to 75/25 (or whatever you want)
alias game_volume_up vol_75
alias game_volume_down vol_25

// for each volume level, set a new volume, echo what the current level is,
// and specifiy which is the next level up and down.
alias vol_0 "volume 0.00; echo volume 0%; alias game_volume_up vol_25; alias game_volume_down vol_0"
alias vol_25 "volume 0.25; echo volume 25%; alias game_volume_up vol_50; alias game_volume_down vol_0"
alias vol_50 "volume 0.50; echo volume 50%; alias game_volume_up vol_75; alias game_volume_down vol_25"
alias vol_75 "volume 0.75; echo volume 75%; alias game_volume_up vol_100; alias game_volume_down vol_50"
alias vol_100 "volume 1.00; echo volume 100%; alias game_volume_up vol_100; alias game_volume_down vol_75"

// binds keypad up/down arrows to volume up/down
// set to whatever keys you want
bind KP_UPARROW game_volume_up
bind KP_DOWNARROW game_volume_down
This is something I just created now, so you may want to test it out and feel free to change the alias names or echos to anything you'd like. There may be better, more fancier "volume" scripts out there, but this one should get the job done nicely. You can copy/paste the same script and change all instances of "volume" to "voice_scale" if you wanted to adjust microphone volume only for example.
If you notice, the reason why they are called cyclic is because the alias "game_volume_up" and "game_volume_down" cycle through different values. This is just one example of how powerful cyclic aliases are (they are used extensively in many advanced scripts I've seen), and in general how powerful HL/HL2 scripting can be, especially when used in conjuction with HLDJ commands (although the above example contains only HL commands).
ThermalSloth
Game DJ
Posts: 7
Joined: Thu Feb 19, 2009 4:36 pm

Re: Volume control script

Post by ThermalSloth »

hey, for you who might want this, this script changes the volume with 5% instead of 25%.

also, now the buttons to control the volume are Keypad + and Keypad -

have fun :)

Code: Select all

// Place all your custom configurations and commands for HLDJ in this file.
// It will be copied, loaded, and executed when a game is started with HLDJ.
// All other files in this folder will also be copied to the game directory.

// Renegade's volume script
// set initial volume to 0.5 (or whatever you want)
volume 0.5

// set initial up/down aliases to 75/25 (or whatever you want)
alias game_volume_up vol_45
alias game_volume_down vol_55

// for each volume level, set a new volume, echo what the current level is,
// and specifiy which is the next level up and down.
alias vol_0 "volume 0.00; echo volume 0%; alias game_volume_up vol_5; alias game_volume_down vol_0"
alias vol_5 "volume 0.05; echo volume 5%; alias game_volume_up vol_10; alias game_volume_down vol_0"
alias vol_10 "volume 0.10; echo volume 10%; alias game_volume_up vol_15; alias game_volume_down vol_5"
alias vol_15 "volume 0.15; echo volume 15%; alias game_volume_up vol_20; alias game_volume_down vol_10"
alias vol_20 "volume 0.20; echo volume 20%; alias game_volume_up vol_25; alias game_volume_down vol_15"
alias vol_25 "volume 0.25; echo volume 25%; alias game_volume_up vol_30; alias game_volume_down vol_20"
alias vol_30 "volume 0.30; echo volume 30%; alias game_volume_up vol_35; alias game_volume_down vol_25"
alias vol_35 "volume 0.35; echo volume 35%; alias game_volume_up vol_40; alias game_volume_down vol_30"
alias vol_40 "volume 0.40; echo volume 40%; alias game_volume_up vol_45; alias game_volume_down vol_35"
alias vol_45 "volume 0.45; echo volume 45%; alias game_volume_up vol_50; alias game_volume_down vol_40"
alias vol_50 "volume 0.50; echo volume 50%; alias game_volume_up vol_55; alias game_volume_down vol_45"
alias vol_55 "volume 0.55; echo volume 55%; alias game_volume_up vol_60; alias game_volume_down vol_50"
alias vol_60 "volume 0.60; echo volume 60%; alias game_volume_up vol_65; alias game_volume_down vol_55"
alias vol_65 "volume 0.65; echo volume 65%; alias game_volume_up vol_70; alias game_volume_down vol_60"
alias vol_70 "volume 0.70; echo volume 70%; alias game_volume_up vol_75; alias game_volume_down vol_65"
alias vol_75 "volume 0.75; echo volume 75%; alias game_volume_up vol_80; alias game_volume_down vol_70"
alias vol_80 "volume 0.80; echo volume 80%; alias game_volume_up vol_85; alias game_volume_down vol_75"
alias vol_85 "volume 0.85; echo volume 85%; alias game_volume_up vol_90; alias game_volume_down vol_80"
alias vol_90 "volume 0.90; echo volume 90%; alias game_volume_up vol_95; alias game_volume_down vol_85"
alias vol_95 "volume 0.95; echo volume 95%; alias game_volume_up vol_100; alias game_volume_down vol_90"
alias vol_100 "volume 1.00; echo volume 100%; alias game_volume_up vol_100; alias game_volume_down vol_95"

// binds keypad up/down arrows to volume up/down
// set to whatever keys you want
bind KP_PLUS game_volume_up
bind KP_MINUS game_volume_down
Asoltan
Game DJ
Posts: 1
Joined: Wed Mar 25, 2009 7:09 pm

Re: Volume control script

Post by Asoltan »

Do I 'copy and paste' this script?
If yes, fine.
If no, I don't know what to do with it.
Renegade
HLDJ Developer
HLDJ Developer
Posts: 1500
Joined: Sat Mar 01, 2008 2:02 pm
Contact:

Re: Volume control script

Post by Renegade »

Yes, read the first post.
Dragonshadow
Game DJ
Posts: 1
Joined: Sat Jun 06, 2009 11:03 am

Re: Volume control script

Post by Dragonshadow »

Could you not simply use incrementvar?
Renegade
HLDJ Developer
HLDJ Developer
Posts: 1500
Joined: Sat Mar 01, 2008 2:02 pm
Contact:

Re: Volume control script

Post by Renegade »

Yes, for Source - this script will work across both engines.
Post Reply