Sv loadingurl
From GMod Wiki
Go to: Console Variables |
CVar: | sv_loadingurl |
---|---|
Description: | The page players will see when joining your server and downloading resources. |
Gamemode: | All |
Default Value: | http://loading.garrysmod.com |
Setting up a sv_loadingurl page
To setup sv_loadingurl all you need is a web server to host the page on. Once you have uploaded your page just run sv_loadingurl "http://mywebsite.com/loadingurl" or whatever the directory name (or php file) is.
Webpage Javascript functions
These are the javascript functions that the game will call to your webpage to update the status of the joining process. You can see an implementation of it at http://loading.garrysmod.com
- DownloadingFile(filename);
- Called when a file starts downloading (based on the status text in the grey loading box)
- The parameter is the name of the file (as printed in the status text in the grey loading box)
- SetStatusChanged(strStatus);
- Called when a status other than downloading appears in the grey loading box
- The parameter is the status text (as printed in the status text in the grey loading box)
- SetFilesNeeded(toDownload);
- Called when the number of files left to download changes
- The parameter is the number of files remaining to be downloaded (including the currently downloading file)
- SetFilesTotal(maxFiles);
- Called at the same time as SetFilesNeeded
- The parameter is the total number of files to be downloaded during this connect attempt
To use these javascript functions simply define them in your HTML with the exact name and number of parameters as are shown in the above list. GMod will call them as the information updates.
Using PHP with Loading URL
If you run sv_loadingurl "http://mywebsite.com/loadingpage.php?steamid=%s&mapname=%m" then the following $_GET values are available to PHP.
- $_GET["steamid"] is the player's steam community id.
- $_GET["mapname"] is the current map name. EX: gm_construct
Example code for a simple loading page.
<?php //Get the steamid (really the community id) $communityid = $_GET["steamid"]; //Get the map name $mapname = $_GET["mapname"]; //See if the second number in the steamid (the auth server) is 0 or 1. Odd is 1, even is 0 $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"; //Output welcome line echo "Welcome to my server!<br>"; //Output Steam Community ID echo "Your Community ID is $communityid<br>"; //Output calculated SteamID echo "Your SteamID is $steamid<br>"; //Output current map echo "The current map is $mapname<br>"; //Output friendly greeting echo "Enjoy your stay!"; ?>
This will output something similar to
Welcome to my server! Your CommunityID is 76561197962734862 Your SteamID is STEAM_0:0:1234567 The current map is gm_construct Enjoy your stay!
NOTE: You must have bcmath installed and use bcsub where shown for PHP to be able to correctly calculate a player's SteamID from their Community ID
Extra Information: "sv_loadingurl" does not work just inside of server.cfg, it needs to be in the command line and autoexec.cfg to work properly