Page 1 of 1
Loading Audio File by Exact Name without using "bind"?
Posted: Tue Jul 21, 2009 9:07 pm
by H3adSh07
Is there a way to load an audio file by its exact name without having "bind" in the command? I'm trying to make a little menu for fast audio switching but lua blocks the command "bind". It also blocks "alias" so that won't work either =P..
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Tue Jul 21, 2009 9:51 pm
by Renegade
Do you mean "bind" is a reserved word in lua? Most scripting languages will have a way for you to use reserved words (i.e. enclosed in "string literals"). Other than that, anyway you can get the Command Relay Key bound to the command you want will work (although I can think of any other than using the bind syntax or the index number, but that's not exact)
If you give me more insight on what you're trying to achieve, I can make a better suggestion. Is this lua scripting for the source engine?
edit: bingo, I was pretty close:
http://www.lua.org/pil/11.5.html
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Tue Jul 21, 2009 10:04 pm
by H3adSh07
I am Lua coding for Garry's Mod. The commands alone work fine when I type them manually or bind them to a key. It's Lua blocking the commands with "bind" in them so when I try to run the command to switch the song, it will say that the command "bind" is blocked.
When I press the button, it does this:
Code: Select all
LocalPlayer():ConCommand( "bind = " .. audioclipname .. "; hldjsf" )
audioclipname is the song selected in the derma list (no bugs in it it works fine)
If I press the button with the clip "Music-DaftPunk-Discovery_01_OneMoreTime" selected, it runs the command in console
Code: Select all
bind = Music-DaftPunk-Discovery_01_OneMoreTime; hldjsf
However, it blocks the command "bind" when it's used through Lua so it will not let me switch songs, therefore ruining all my efforts and wasting a good few hours of my life. >.<
Code: Select all
ConCommand blocked! (bind = Music-DaftPunk-Discovery_01_OneMoreTime; hldjsf)
EDIT: RunConsoleCommand does the same thing.
Code: Select all
RunConsoleCommand( "bind", "=", "" .. audioclipname, ";", "hldjsf" )
Runs the console command:
Code: Select all
bind = Music-DaftPunk-Discovery_01_OneMoreTime; hldjsf
Resulting in this error being printed to console:
Code: Select all
RunConsoleCommand: Command is blocked! (bind)
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Tue Jul 21, 2009 11:02 pm
by Renegade
Hmm, seems like a limitation (possibly deliberate) by the Gmod devs. There's probably a reason or workaround for it they may know of. If not, there may be other ways to bind the key, BindToggle may work.
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Tue Jul 21, 2009 11:05 pm
by H3adSh07
http://wiki.garrysmod.com/?title=G.RunConsoleCommand
Scroll to the bottom of that and it has all the console commands that are blocked.
BindToggle is blocked as well.. Is it possible for you to make a custom console command for loading files instead of "bind ="?
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Wed Jul 22, 2009 2:18 am
by Renegade
Not without significantly changing HLDJ's infrastructure. Why not just create a bunch of aliases and call them in the script:
Code: Select all
alias loadmyfile1 "bind = >$\music\my*audio*file; hldjsf"
...
Code: Select all
LocalPlayer():ConCommand( loadmyfile1 )
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Wed Jul 22, 2009 2:52 pm
by H3adSh07
I would do that but you would have to recreate the aliases every time you launch Garry's Mod or put them in cfg but I don't know how to do the 2nd option. So I would have to type like 150 commands every time I use HLDJ. (Alias is also blocked in Lua so I can't have an autorun Lua that runs all of them on startup)
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Thu Jul 23, 2009 3:13 am
by Renegade
Game scripting is much easier than Lua scripting, read (step #2):
http://www.hldj.org/forums/viewtopic.php?f=6&t=252
just place all the aliases in your
hldj_custom.cfg.
If you want to get fancy, you can even use Lua or some other scripting language (Perl, etc) to go through all your audio files and generate the aliases dynamically.
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Thu Jul 23, 2009 1:32 pm
by H3adSh07
I just want to be 100% clear so I can make this work right XD.. If I have a song named "OneMoreTime" and I wanted to create an alias command to load that song when I type "OneMoreTime" in console, what would be the alias command? =P
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Thu Jul 23, 2009 3:20 pm
by Renegade
There are a few different ways listed in the link, but here's the two I would recommend:
relative to your Audio Folder:
Code: Select all
alias load_onemoretime "bind = >$\OneMoreTime; hldjsf"
absolute path:Code: Select all
alias load_onemoretime "bind = >X:\path\to\audio\folder\OneMoreTime; hldjsf"
(where X:\ is the drive or network address)
Keep in mind you can change your Command Relay Key from the default ("=") to anything.
Also, if the path contains
spaces, you can do one of two things:
1) replace all spaces in the path with "*"
Code: Select all
alias load_onemoretime "bind = >$\this*folder*has*spaces\OneMoreTime; hldjsf"
2) create an extra alias
Code: Select all
alias loada_onemoretime bind = ">$\this folder has spaces\OneMoreTime"
alias loadb_onemoretime "loada_onemoretime; hldjsf"
Either method should work fine. The first can be a bit tedious at times (although it's much easier if you make a script to replace all spaces with "*"); the second requires more aliases and I'm not sure if it works in all games. See which one you prefer.
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Thu Jul 23, 2009 4:35 pm
by H3adSh07
I have all the sounds in my audio folder renamed for there to be no spaces in it. Thanks for all the help! =D
Re: Loading Audio File by Exact Name without using "bind"?
Posted: Thu Jul 23, 2009 5:53 pm
by Renegade
glad you got it working