Tools
Garry's Mod

Your own loading screen with HTML and JavaScript

A GMod loading screen is a normal web page. While connecting, Garry's Mod calls five JavaScript functions in it and passes server data and the loading progress.

In short

Define the global functions GameDetails, SetFilesTotal, SetFilesNeeded, DownloadingFile and SetStatusChanged on your page. Garry's Mod calls them while connecting. Write the JavaScript in ES5 so it also runs in the older built-in browser.

The five functions

  • GameDetails(servername, serverurl, mapname, maxplayers, steamid, gamemode, volume, language): once at the start, with the server name, map, slots, the player's SteamID64, gamemode, music volume (0 to 1) and game language.
  • SetFilesTotal(total): the number of files that have to be loaded.
  • SetFilesNeeded(needed): how many of them are still missing. Progress is (total - needed) / total.
  • DownloadingFile(fileName): the file that is loading right now.
  • SetStatusChanged(status): the status of the game, such as “Mounting Addons” or “Sending client info…”.

A minimal example

The skeleton shows the map, progress and status. It uses only ES5, so no let, no arrow functions and no template strings.

<p id="map"></p>
<div id="bar" style="height:6px;width:0;background:#5143d9"></div>
<p id="status"></p>
<script>
var total = 0;
function GameDetails(servername, serverurl, mapname, maxplayers, steamid, gamemode, volume, language) {
  document.getElementById('map').textContent = mapname;
}
function SetFilesTotal(n) { total = n; }
function SetFilesNeeded(n) {
  if (total > 0) { document.getElementById('bar').style.width = Math.round((total - n) / total * 100) + '%'; }
}
function DownloadingFile(file) { document.getElementById('status').textContent = file; }
function SetStatusChanged(status) { document.getElementById('status').textContent = status; }
</script>

What to watch out for

  • Old browser technology: Depending on the system, Garry's Mod uses a browser much older than Chrome. Test in the game, not just on a PC.
  • Keep the bottom right corner free: Garry's Mod shows its own window with the status and “Cancel” there.
  • Stay small: The page loads in parallel with the addons. Compressed images and few scripts make it faster.
  • Music: Respect volume from GameDetails so players with music turned off don't hear anything.

Frequently asked questions

Are all the functions always called?

Not always all of them. Without downloads there are hardly any calls to DownloadingFile, and SetFilesTotal can be missing. Expect some values to stay empty.

Can I use jQuery or a framework?

Yes, as long as the version runs in the old built-in browser. Plain JavaScript is usually enough for a loading screen.

A finished loading screen without writing HTML

The generator builds the page and the line for your server.cfg, and takes care of progress, music and the Steam name. You pick a design and enter your texts.

Create a loading screen

Free. Sign in with your Nexthosting account; creating one costs nothing.