Loading URL

From Garry's Mod
Revision as of 01:49, 22 September 2013 by Sam (Talk | contribs)
Jump to: navigation, search

The convar sv_loadingurl allows a server owner to define a webpage to show to players when joining the server.


Setting your server's loading URL

If you are setting the convar through the console then make sure to put quotes around the URL. Also a + should be added to the front. Your command should look something like this:

+sv_loadingurl "http://wiki.garrysmod.com/"

If you are placing this into your autoexec.cfg configuration file, be sure to remove the +, like so:

sv_loadingurl "http://wiki.garrysmod.com/"

If you want, you may also use %s or %m in your URL (most likely in a GET variable) to pass the steam id, and map name respectively. For example:

sv_loadingurl "http://wiki.garrysmod.com/?mapname=%m&steamid=%s"

These can be later retrieved with simple PHP code.

Custom loading pages

This section will not detail creating your page, and assumes you have already designed one.

Javascript functions

There are several Javascript functions which are called directly by Garry's Mod. To use these, simply create a function with that name in your page - it will be called when your page loads.

// Called when the loading screen finishes loading all assets.
function GameDetails( servername, serverurl, mapname, maxplayers, steamid, gamemode ) {}
// Called when a file starts downloading. The filename includes the entire path of the file;
// for example "materials/models/bobsModels/car.mdl".
function DownloadingFile( fileName ) {}
// Called when something happens. This might be "Initialising Game Data", "Sending Client Info", etc.
function SetStatusChanged( status ) {}
// Called at the start, tells us how many files need to be downloaded in total.
function SetFilesTotal( total ) {}
// Called when the number of files to download changes.
function SetFilesNeeded( needed ) {}

PHP GET parameters

%m and %s will be replaced with the server's current map and the player's 64-bit steam community ID, respectively. This means you can grab them using PHP's $_GET superglobal.

The map is a string, so you should have no trouble making use of that. However, the steam community ID is not the classic "shorthand" steam ID often seen in-game. A method of conversion (using PHP's bcmath & bcsub) is shown below.

$authserver = bcsub( $communityid, '76561197960265728' ) & 1;
//Get the third number of the steamid
$authid = ( bcsub($communityid, '76561197960265728') - $authserver ) / 2;
//Concatenate the STEAM_ prefix and the first number, which is always 0, as well as colons with the other two numbers
$steamid = "STEAM_0:$authserver:$authid";



If you would like to use a simple image as a loading screen, but don't have a webhost, you can use the following code as your sv_loadingurl value. Make sure to replace URL-GOES-HERE with the link to the image you would like to use. This makes use of Data URIs for writing HTML for the URL.

data:text/html,<style>html,body{padding:0;margin:0;background:black;}</style><img src="URL-GOES-HERE" width="100%" height="100%"/>
Personal tools