Loading Audio File by Exact Name without using "bind"?

Help with using HLDJ
Post Reply
H3adSh07
Game DJ
Posts: 9
Joined: Tue Jul 21, 2009 9:03 pm

Loading Audio File by Exact Name without using "bind"?

Post 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..
Renegade
HLDJ Developer
HLDJ Developer
Posts: 1500
Joined: Sat Mar 01, 2008 2:02 pm
Contact:

Re: Loading Audio File by Exact Name without using "bind"?

Post 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
H3adSh07
Game DJ
Posts: 9
Joined: Tue Jul 21, 2009 9:03 pm

Re: Loading Audio File by Exact Name without using "bind"?

Post 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)
Renegade
HLDJ Developer
HLDJ Developer
Posts: 1500
Joined: Sat Mar 01, 2008 2:02 pm
Contact:

Re: Loading Audio File by Exact Name without using "bind"?

Post 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.
H3adSh07
Game DJ
Posts: 9
Joined: Tue Jul 21, 2009 9:03 pm

Re: Loading Audio File by Exact Name without using "bind"?

Post 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 ="?
Renegade
HLDJ Developer
HLDJ Developer
Posts: 1500
Joined: Sat Mar 01, 2008 2:02 pm
Contact:

Re: Loading Audio File by Exact Name without using "bind"?

Post 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 )
H3adSh07
Game DJ
Posts: 9
Joined: Tue Jul 21, 2009 9:03 pm

Re: Loading Audio File by Exact Name without using "bind"?

Post 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)
Renegade
HLDJ Developer
HLDJ Developer
Posts: 1500
Joined: Sat Mar 01, 2008 2:02 pm
Contact:

Re: Loading Audio File by Exact Name without using "bind"?

Post 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.
H3adSh07
Game DJ
Posts: 9
Joined: Tue Jul 21, 2009 9:03 pm

Re: Loading Audio File by Exact Name without using "bind"?

Post 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
Renegade
HLDJ Developer
HLDJ Developer
Posts: 1500
Joined: Sat Mar 01, 2008 2:02 pm
Contact:

Re: Loading Audio File by Exact Name without using "bind"?

Post 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.
H3adSh07
Game DJ
Posts: 9
Joined: Tue Jul 21, 2009 9:03 pm

Re: Loading Audio File by Exact Name without using "bind"?

Post 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
Renegade
HLDJ Developer
HLDJ Developer
Posts: 1500
Joined: Sat Mar 01, 2008 2:02 pm
Contact:

Re: Loading Audio File by Exact Name without using "bind"?

Post by Renegade »

glad you got it working
Post Reply