Many custom loading screens fake the progress bar with a CSS animation that loops whatever is downloading. GMod gives you better data: its menu code calls a few JavaScript functions on your page while the client joins. This guide describes what each call sends, based on GMod's loading screen code (lua/menu/loading.lua), and how to build a bar on top of it.
The functions GMod calls
Define them as global functions on window. GMod checks that each one exists before calling it:
GameDetails(servername, serverurl, mapname, maxplayers, steamid, gamemode, volume, language): called once, after your page has finished loading. Use it for the server name and map.volumeis the player's music volume setting (0 to 1),languagetheir GMod menu language.SetFilesNeeded(needed): the number of files from the server's download list that are missing on the client. Called when that list changes, and only while at least one file is missing. It is not called again after each finished file, and never with 0.SetFilesTotal(total): the size of the server's download list, called right after SetFilesNeeded.DownloadingFile(fileName): called when a download starts, once per file. Server files arrive as paths, Workshop items by name.SetStatusChanged(status): the other status lines, such as 'Starting Lua...'. Statuses from before the downloads usually never reach the page.
A progress bar built on these calls
Count the downloads that start and compare them with the last number of missing files GMod reported. Workshop items are not part of that number, so cap the bar at 100% and keep the file name visible:
<div id="status">Connecting...</div>
<div class="bar"><div id="fill"></div></div>
<div id="file"></div>
<script>
var missing = 0; // last value sent by SetFilesNeeded
var started = 0; // DownloadingFile calls since then
window.GameDetails = function (servername, serverurl, mapname) {
document.getElementById("status").textContent =
"Joining " + servername + " (" + mapname + ")";
};
window.SetFilesNeeded = function (needed) {
missing = needed;
started = 0;
};
window.DownloadingFile = function (fileName) {
started++;
document.getElementById("file").textContent = fileName;
if (missing > 0) {
var percent = Math.min(100, Math.round((started / missing) * 100));
document.getElementById("fill").style.width = percent + "%";
}
};
window.SetStatusChanged = function (status) {
document.getElementById("status").textContent = status;
};
</script>Edge cases the simple version misses
- No files to download: returning players often have everything already. SetFilesNeeded and SetFilesTotal are then never called, so show a neutral state instead of a bar stuck at 0%.
- Workshop-heavy servers: Workshop items trigger DownloadingFile but are not counted in SetFilesNeeded. The bar can reach 100% while Workshop downloads continue, so keep the file name or the status next to it.
- Fast joins: on a client that already has the content, loading can end within seconds. Don't animate the bar so slowly that it never reaches the end.
- JavaScript errors: one uncaught exception in a function can stop all later updates. Keep each function short and defensive.
How Lumescreen handles it
Every Lumescreen theme listens to these calls through a shared script, which also sends load events to your dashboard: page loads, the GameDetails call, downloads and screen resolutions.
Building your own? The URL side is covered in the sv_loadingurl complete guide. Rather have it done for you? Pick a theme and the progress bar is already wired up.