Random Garry's Mod Loading Sounds

Hello, how would I go about making my custom garry’s mod loading screen play random sounds?
I can’t even make it play one sound at the moment, and the current code I use right now is



<embed     
src="player.swf"                
 id="radioplayer"                 
name="radioplayer"                 
quality="medium"                 
allowScriptAccess="always"                 
width="1"                 
height="1"                 
type="application/x-shockwave-flash"                 
FlashVars="file=sounds/song2.mp3&volume=25&start=0&duration=0&autostart=true&controlbar=none&dock=false&icons=false">   
</embed>


The audio file “song2.mp3” is in root/sounds/song2.mp3 and it won’t play.

Anyway, how would I go about making it play random .mp3 or midi files from my /sounds folder?
I’m a tad new to this kind of stuff, thanks in advance guys!

Instead of trying to embed it into the web code etc, go into garrysmod/sound/ui/ and place the song or sound of your choosing there and rename it to


gamestartup01.mp3

It plays the sound file at the start of your game.

You may also have garrysmod randomly select multiple songs by adding multiple files.


ie: gamestartup01.mp3 gamestartup02.mp3

I’ve been working on a custom sv_loadingurl for the server, and I have been successful.
I’m trying to get the loadingurl to broadcast music to everyone who connects.

I don’t want Garry’s Mod to just play a sound for me or in-game, I want the web page while connecting to the server to do so.

I found an example, check this link out: http://sammyservers.com/loading/loading_board.php
That’s Sammy Server’s loadingurl that you see every time you connect to their servers.

It plays a random music clip every time you load their page. I’m trying to do something similar.

I found code also on another website, but it doesn’t work either. Of course, I changed the http links to correct directories of my website. The code is



<script type="text/javascript">
var numberOfSongs = 3
var sound = new Array(numberOfSongs+1)
sound[0]= "http://www.yourwebsite.com/audiofolder/song1.mid"
sound[1]= "http://www.yourwebsite.com/audiofolder/song2.mid"
sound[2]= "http://www.yourwebsite.com/audiofolder/song3.mid"
function randomNumber(){
var randomLooper = -1
while (randomLooper < 0 || randomLooper > numberOfSongs || isNaN(randomLooper)){    randomLooper = parseInt(Math.random()*(numberOfSongs+1))
}
    return randomLooper
}
var randomsub = randomNumber()
var soundFile = sound[randomsub]
document.write ('<EMBED src= "' + soundFile + '" hidden=true autostart=true loop=true>')
</script>


I still need help. Thanks in advance guys.

After looking through various posts around FP, I have found that the player.swf should be working



<embed src="player.swf" 
id="radioplayer" 
name="radioplayer" 
quality="medium" 
allowScriptAccess="always" width="1" height="1" 
type="application/x-shockwave-flash" 
FlashVars="file=song2.mp3&volume=20&start=0&duration=0&autostart=true&controlbar=none&dock=false&icons=false">
</embed>


Yet, it doesn’t. I have my song2.mp3 placed correctly, and just in case you all wanted to see:

I have found an embed that works for a single song in a web browser, but it doesn’t work in Garry’s Mod.



<embed src="http://pds20.egloos.com/pds/201106/24/79/RiceLarngke.swf" height="0" width="0" />


This is frustrating, but I’m patient. I have no idea why Player.swf isn’t even working, even though it should.

Can you please post your web code for the loading url you’re trying to direct it to?

Here’s the code for my loadingurl:



<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<style>
*{
	margin: 0;
	padding: 0;
}
body{	background: #121212;
	max-width: 900px;
	text-align: center;
	margin: auto;

}
#header{
	margin-top: 20px;
}
#header h1{
	font-size: 55px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #6C8BA6;
	text-shadow: #000 0px 0px 1px;
	letter-spacing: -2px;
}
#header h2{
	font-size: 44px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #6C8BA6;
	text-shadow: #000 0px 0px 1px;
	letter-spacing: -2px;
}
#header h3{
	font-size: 34px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #6C8BA6;
	text-shadow: #000 0px 0px 1px;
	letter-spacing: -2px;
}
#announcement{
	font-family:Arial, Helvetica, sans-serif;	
	padding: 5px;
	border: 2px dashed #00AEFF;
	background: #41bdd8;
	margin-top: 15px;
	-webkit-border-radius: 8px;
	-moz-border-radius: 8px;
	border-radius: 8px;
}
#announcement p{
	color: #003456;
	font-weight: 900;
}
#rules{
	margin: auto;
	max-width: 280px;
	margin-top: 15px;
	padding: 5px;
	border: 2px dashed #000000;
	background: #464646;
	-webkit-border-radius: 8px;
	-moz-border-radius: 8px;
	border-radius: 8px;
}
#rules h1{
	font-size: 44px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #6C8BA6;
	text-shadow: #000 0px 0px 1px;
	letter-spacing: -2px;
}
#rules h3{
	font-size: 38px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #6C8BA6;
	text-shadow: #000 0px 0px 1px;
	letter-spacing: -2px;
}
#rules ol{
	margin-top: 10px;
}
#rules li{
	font-size: 16px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #fff;
	font-weight: 900;
	text-shadow: #000 0px 0px 1px;
	list-style-type: none;
	
}
#rules p{
	margin-top: 10px;
	font-size: 16px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #fff;
	font-weight: 900;
	text-shadow: #000 0px 0px 1px;
}
#rules a{
	margin-top: 10px;
	font-size: 16px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #fff;
	font-weight: 900;
	text-shadow: #000 0px 0px 1px;
}
#rules b{
	margin-top: 600px;
	font-size: 18px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #6C8BA6;
	text-shadow: #000 0px 0px 1px;
	letter-spacing: -1px;
}
#admins{
	margin-top: 25px;
}
#admins h1{
	font-size: 44px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #6C8BA6;
	text-shadow: #000 0px 0px 1px;
	letter-spacing: -2px;
}
#admins ol{
	margin-top: 10px;
}
#admins li{
	font-size: 24px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #fff;
	font-weight: 900;
	text-shadow: #000 0px 0px 1px;
}
#admins a:link {
	color: #FFF;
	text-decoration: none;
	-webkit-transition: all 0.4s ease-in-out;
    -moz-transition: all 0.4s ease-in-out;
    -o-transition: all 0.4s ease-in-out;
	}
#admins a:visited {color:#FFF;text-decoration:none;}
#admins a:hover {
	color: #FFF;
	text-decoration: none;
	text-shadow: #838383 0px 0px 4px;
}
#admins a:active {color:#FFF;text-decoration:none;}
#donating{
	margin-top: 35px;
}
#donating p{
	margin-top: 10px;
	font-size: 16px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #fff;
	font-weight: 900;
	text-shadow: #000 0px 0px 1px;
}
#donating h1{
	font-size: 44px;
	font-family:Arial, Helvetica, sans-serif;	
	color: #6C8BA6;
	text-shadow: #000 0px 0px 1px;
	letter-spacing: -2px;
}

.f {
	font-size: xx-small;
}
.f {
}
.f td {
	color: #F00;
}
.f {
	color: #F00;
}
</style>

</head>

<body>
<?php
require_once('classlib/GameQ.php');
if(!empty($_GET['ip']) && !empty($_GET['port'])){
$gq = new GameQ();
$gq->
<div id="header">
<h1>[ttt] Last Known Suspect [ttt]</h1>
<h2><?php echo($sname); ?></h2>
<h3>Website Coming Soon! Donate to help!</h3>
</div>

<div id="announcement">
<p>
Welcome to Trouble in Terrorist Town!</p>
</div>
<div class="f"> .</div>
<table width="197" height="265" border="1" align="left">
  <tr>
    <th width="272" scope="row"> </th>
  </tr>
</table>
<table width="197" height="266" border="1" align="right">
  <tr>
    <th width="272" scope="row"> </th>
  </tr>
</table>
<img src="will smith.gif" width="500" height="264">
<div id="admins" style="float:center">
  <h1>Downloading</h1>
	<img src="file:///C|/Users/Benjamin/Documents/ajax-loader.gif">
		<div id='loadingtext' style="font-size: 16px;font-family:Arial, Helvetica, sans-serif;	color: #fff;font-weight: 900;text-shadow: #000 0px 0px 1px;list-style-type: none;" >Loading Text..</div>
	</div>
    



<embed src="player.swf" 
id="radioplayer" 
name="radioplayer" 
quality="medium" 
allowScriptAccess="always" width="1" height="1" 
type="application/x-shockwave-flash" 
FlashVars="file=song2.mp3&volume=20&start=0&duration=0&autostart=true&controlbar=none&dock=false&icons=false">
</embed>




<script type="text/javascript">

	keywords = 
	[
	 "Tip: Don't RDM or kill people for no reason.", 
	 "Tip: Prop-killing can get you killed.",
	 "Tip: Welcome to the server!",
	 "Tip: Press F1 for a tutorial on how to play.",
	 "Tip: Having a problem? Tell an admin right away!",
	 "Tip: Have a suggestion? Feel free to tell an admin!",
	 "Tip: Lacking trust? Try to find some trustworthy people!",
	 "Tip: Donate to help keep the server running!",
	 "Tip: Explore around to become familiar with most maps.",
	 "Tip: You can press C as a traitor to buy equipment",
	 "Tip: Apozen was here!", 
	 "Tip: Plant C4 in hidden places to avoid being found!",
	 "Tip: Respect all members.",
	 "Tip: Donations will help keep the server running!",
	 "Tip: You are joining LKS Trouble in Terrorist Town!",
	 "Tip: You're headed in the right direction!",
	 "Tip: Just a few more seconds....",
	 "Tip: Knives are 1-hit kill.",
	 "Tip: Place a Melon Mine above a door to give a nasty suprise!",
	 "Tip: You are allowed to prop-kill as a spectator.",
	 "Tip: Some players making you angry? Contact an admin ASAP.",
	 "Tip: Don't you love reading all these tips?",
	 "Tip: Buy a disguiser while sniping to avoid being seen!",
	 "Tip: Hide bodies under cars, on the ceiling, or in other hidden places!"
	]


	var bCanChangeStatus = true;
	function ChangeText ( )	{
		if ( bCanChangeStatus )
		{
			var keyword = keywords[ Math.floor( Math.random() * keywords.length ) ]
			document.getElementById( "loadingtext" ).innerHTML = keyword;
		}
		
		setTimeout( "ChangeText()", 2500 );
	}
	
	ChangeText();
	
	var iFilesNeeded = 0;
	var iFilesTotal = 0;
	var bDownloadingFile = false;
	
	function SetFilesNeeded( iNeeded )
	{
		iFilesNeeded = iNeeded;
		RefreshFileBox();
	}
	
	function SetFilesTotal( iTotal )
	{
		iFilesTotal = iTotal;
		RefreshFileBox();
	}
	
	function DownloadingFile( filename )
	{
		if ( bDownloadingFile )
		{
			iFilesNeeded = iFilesNeeded - 1;
			RefreshFileBox();
		}
		
		document.getElementById( "loadingtext" ).innerHTML = "Downloading " + filename;
		bCanChangeStatus = false;
		setTimeout( "bCanChangeStatus = true;", 1000 );
		
		bDownloadingFile = true;
		
	}
	
	function SetStatusChanged( status )
	{
		if ( bDownloadingFile )
		{
			iFilesNeeded = iFilesNeeded - 1;
			bDownloadingFile = false;
			RefreshFileBox();
		}
		
		document.getElementById( "loadingtext" ).innerHTML = status;
		bCanChangeStatus = false;
		setTimeout( "bCanChangeStatus = true;", 1000 );
	}
	
	function RefreshFileBox()
	{
		document.getElementById( "files" ).innerHTML = "<img src='download.png' style='position: relative; top: 7px;'> " + iFilesNeeded + " downloads remaining";
		
		if ( iFilesTotal > 0 )
			document.getElementById( "files" ).style.visibility = 'visible';
		else
			document.getElementById( "files" ).style.visibility = 'hidden';
	}
	
	RefreshFileBox();
	
</script>

</div>




</object>
</div>
<div id="rules">
<center>
&copy 2012 LKS
</center>

<?php
$communityid = $_GET["steamid"];
echo "Your Community ID is $communityid<br>";
?>
	
</body>

</html>



Does anybody see any error as to why my player.swf isn’t working?



<? $number = rand(1, 8) ?>
<embed     
src="player.swf"                
 id="radioplayer"                 
name="radioplayer"                 
quality="medium"                 
allowScriptAccess="always"                 
width="1"                 
height="1"                 
type="application/x-shockwave-flash"                 
FlashVars="file=sounds/<?php echo $number; ?>.mp3&volume=25&start=0&duration=0&autostart=true&controlbar=none&dock=false&icons=false">   
</embed>

save this to whatyouwant.php

Work ? :smiley:

It should be working! But it’s not :frowning: I made whatyouwant.php , put it in root, made a sounds folder and moved song.mp3 to it, yet nothing plays on the initial page.
(I even placed the php code in index.html, still didn’t work)
Could this be something to do with my website’s settings?

I can easily play a youtube video in the background though, I wouldn’t have the slightest idea on making that random.

Here’s the code:



<object style="height: 1; width: 1"><param name="movie" value="http://www.youtube.com/v/YTlqIBaRSk0&autoplay=1&loop=1"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/YTlqIBaRSk0&autoplay=1&loop=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="1" height="1"></object


Rename your index.html to index.php
Rename all your song like this : 1.mp3 / 2.mp3 / 3.mp3 / etc …

Edit: And change 8 to the number of song you have <? $number = rand(1, 8) ?>

Changing my index.html to index.php makes my webpage result in an error, saying
“This site is under development”
Otherwise, it still refuses to work, even after making the changes like you suggested.

Edit: Thanks though for trying to help.

Okay, your webbost have php installed ?

Yes, it says this:
PHP Version:
5.2.12

also:



This is the default version of PHP that your site is currently using. Note that you can always choose between PHP4 and PHP5 for individual files by naming them with the corresponding extension. For example, script1.php4 and script2.php5 would use PHP 4 and 5, respectively, regardless of your default version setting. The default choice, below, is used only for files named with the generic .php extension.

If you choose to edit your php.ini files, please pay careful attention to which version of PHP you are using. Some configuration options that work in PHP 4 will not work in PHP 5, and vice versa. We let you create separate php.ini files for each major version — one for PHP 4, and one for PHP 5 — to give you maximum flexibility in fine-tuning PHP's behavior. This may mean that certain types of configuration changes may need to be made in both files separately.


Edit: If needed I could send a ticket to my host, asking why this simple php script won’t load.
May have something to do with some settings? It looks like it would work.
I can’t even get player.swf to load on my website, which a lot of people say to use.

Add me on steam.