Code:
/* Loading Music (easy to use directory version)
by Andrew Penry (Andrax2000)
Praise or flame me at cs.wallworm.com Thurs & Sun 9PM EST
This plugin will randomly choose an mp3 from a directory on the server
and play it during the map load.
To use:
1. Compile & Copy, you know the drill
2. Create a directory called loading in <gamemod>/sound/misc/
3. Upload up to 5 mp3s into <gamemod>/sound/misc/loading/
Don't forget to mirror the mp3s on your sv_downloadurl sever.
If you want more than 5 mp3 you can change Maxsounds and recompile. I
would not recommed this, as it will take a long time for the clients to
download. Also note, most maps don't take a great deal of time to download
if you are using sv_downloadurl, so having 6 min long mp3s is pointless. I
recommend trimming the mp3s down to 1 min to make them take less download
time.
Inspired by my admin's frustrations with similar plugins that had the names
of the sounds hardcoded in, or required a config file, etc. I think that
this makes thing much simpler for the server admin.
Thanks to the groundwork layed by [OSA]Odin and eFrigid.
Thanks to arkshine for the precache_generic suggestion.
Important note:
Test that your mp3s work locally before uploading them to the server:
1. Place the mp3 in <gamemod>/sound/misc on YOUR LOCAL machine
2. Open up CS but do not connect to a server.
3. Type "mp3 play sound/misc/<name of mp3>" (note do not type .mp3 at the end)
4. If it plays, it's OK to upload, if not, the mp3 is incompatible with HL
HL seems to prefer mp3s encoded with LAME or Fraunhofer. It will not play
music encoded with mp3pro (the codec that Nero comes with) which use the .mp3
extentions even though they are technically not mp3 files.
Changelog:
v 0.9 Reduced code size by using a do...while loop
Switched to precahce_generic to get rid of the RIFF/WAV warnings
v 0.8 Intital Release
Todo:
Add error checking. It may crash if there are no files in the loading dir.
Add a compile option to include the standard HL sounds into the random mix.
Possibly: Move randomness from client_connect to plugin_precache, so all
clients hear the same sound, and only the current sound needs precached.
That would have the advantage that the client would not need to download
all the songs at once. The disadvantage it that sometimes the song won't
play when it is first downloaded, so it may be several maps before the
client starts hearing music. Would need much testing.
*/
#include <amxmodx>
The major difference between this and eFrigid's version, is that this requires no .ini file with a list of the songs. It simple precaches all mp3s found in sound/misc/loading, so a admin with ftp access just has to upload an mp3. No more giving random people ssh access just to add sounds to the loading screen.