Garry's Mod Wiki

steamworks.Download

  steamworks.Download( string workshopPreviewID, boolean uncompress, function resultCallback )

Description

You really should be using steamworks.DownloadUGC. This is a legacy function.

Downloads a file from the supplied addon and saves it as a .cache file in garrysmod/cache/ folder.

This is mostly used to download the preview image of the addon.

In case the retrieved file is an image and you need the IMaterial, use AddonMaterial with the path supplied from the callback.

Arguments

1 string workshopPreviewID
The Preview ID of workshop item.
2 boolean uncompress
Whether to uncompress the file or not, assuming it was compressed with LZMA.
You will usually want to set this to true.
3 function resultCallback
The function to process retrieved data.
Function argument(s):
1 string path - Path to the downloaded file.

Example

Downloads and saves icon of Gm_construct_Beta Steam Workshop addon, then draws it on screen.

local mat = nil steamworks.FileInfo( 21197, function( result ) steamworks.Download( result.previewid, true, function( name ) print( name ) mat = AddonMaterial( name ) end) end) hook.Add( "HUDPaint", "PutAUniqueHookNameHere", function() if ( !mat ) then return end -- TODO: Draw some loading placeholder surface.SetDrawColor( 255, 255, 255, 255 ) -- Set the drawing color surface.SetMaterial( mat ) -- Use our cached material surface.DrawTexturedRect( 0, 0, 512, 512 ) -- Actually draw the rectangle end )
Output: