Loading URL

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Add asset link example, add to validation)
(Fixed example by escaping the hashtag, works in Chrome now at least)
Line 100: Line 100:
  
 
{{Example
 
{{Example
| Description = {{Validate|Category=No|Example does not work.}}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 [https://developer.mozilla.org/en-US/docs/data_URIs Data URIs] for writing HTML for the URL.
+
| Description = 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 [https://developer.mozilla.org/en-US/docs/data_URIs Data URIs] for writing HTML for the URL.
 
| Code =  
 
| Code =  
data:text/html,<style>html,body{padding:0;margin:0;background:#000}</style><img src="URL-GOES-HERE" width="100%" height="100%">
+
data:text/html,<style>html,body{padding:0;margin:0;background:%23000}</style><img src="URL-GOES-HERE" width="100%" height="100%">
 
}}
 
}}
  

Revision as of 09:16, 25 December 2019

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

Contents

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 the event associated with it happens.

/*
	Called at the start, when the loading screen finishes loading all assets.
	
	serverName- Server's name.
		Convar: hostname
		For exmaple: "Garry's Mod Server"
	serverURL- URL for the loading screen. 
		Convar: sv_loadingurl
		For example: "http://mywebsite.com/myloadingscreen.html"
	mapName- The name of the map the server is playing. 
		For example: "cs_office"
	maxPlayers- Maximum number of players for the server.
		Convar: maxplayers
	steamID- 64-bit, numeric Steam community ID of the client joining. 
		For example: 76561198012345678
	gamemode- The gamemode the server is currently playing. 
		Convar: gamemode
		For example: "deathrun"
*/
function GameDetails( servername, serverurl, mapname, maxplayers, steamid, gamemode ) {}
/*
	Called at the start

	total- Total number of files the client will have to download.
*/
function SetFilesTotal( total ) {}
/*
	Called when the client starts downloading a file.

	fileName- The full path and name of the file the client is downloading.
		This path represents the resource's location rather than the actual file's location on the server.
		For example, the file "garrysmod/addons/myAddon/materials/models/bobsModels/car.mdl" will be:
			"materials/models/bobsModels/car.mdl"
*/
function DownloadingFile( fileName ) {}
/*
	Called when the client's joining status changes.

	status- Current joining status.
		For example: "Sending client info..."
*/
function SetStatusChanged( status ) {}
/*
	Called when the number of files remaining for the client to download changes.

	needed- Number of files left for the client to download.
*/
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.

<?php
$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";
?>

Examples

Example

If you would like to use a local file as a loading screen, for example during gamemode creation as a default loading screen, you can use the asset:// prefix. The example uses the default loading screen, but any html file can be used.

sv_loadingurl "asset://garrysmod/html/loading.html"


Examples

Example

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:%23000}</style><img src="URL-GOES-HERE" width="100%" height="100%">


Gmod-LSM.com

A free, online and easy-to-use loading screen maker, without having to code anything or rent a web server. https://www.gmod-lsm.com

gmod-lsm-example1.jpeg


Load Seed

An application skeleton for building a loading screen. You can use it to quickly get started building your design. Make sure to read the readme before getting started. https://github.com/glua/load-seed

load-seed-preview.jpg
Personal tools
Navigation