Search code examples
luagarrys-mod

Will this lua code work to download certain files on my GMOD server


I have recently been building my GMOD server and is slowy getting popular but I was interested to create a addon so I put together something that, should, download some worksop links in loading screen and others ingame. This is what I have created.

sv_auto_download:

// Write the map download codes below

resource.addworkshop( "" )


function DownloadFiles() 

    // Write the the texture codes below

    resource.addworkshop( "" )
    return ""
end
hook.Add ( "PlayerInitialSpawn", "DownloadFiles" )

Solution

  • No, this will not work. Firstly, PlayerInitalSpawn runs after the loading screen and also resource.addworkshop is a server side function that is loaded once so that the server knows to load the workshop files, meaning addons will still be downloaded in the loading screen anyhow.

    You can not "download some worksop links in loading screen and others ingame" and you should not force players to download 10gigs of models if they don't want to.

    The best way to get players to download addons is through the workshop.

    1. Create a collection on the steam workshop for your addons, for example http://steamcommunity.com/sharedfiles/filedetails/?id=1244735564

    2. Head over to http://steamcommunity.com/dev/apikey and use your server's IP address as the website and save your api key somewhere safe (i.e. don't share it)

    3. Go to your launch options for scrds.exe (either a .bat file or in the server dashboard) and add -authkey 3XAMPL3K3YF0RTH3T3ST3 +host_workshop_collection (collection ID), with the collection ID being the ?id=1244735564 part of the collections URL

    Then, players will automatically download server content and it is easy for you to add more addons, with it also serving as a way for players to quickly download large models permanently if they wish to play on your server for an extended period of time.

    By the way, you forgot to include the function delegate into the hook.Add:

    hook.Add ( "PlayerInitialSpawn", "DownloadFiles", DownloadFiles )