Skip to content

Instantly share code, notes, and snippets.

@Donkie
Last active August 29, 2015 14:13
Show Gist options
  • Save Donkie/7842dabaaded43707a0c to your computer and use it in GitHub Desktop.
Save Donkie/7842dabaaded43707a0c to your computer and use it in GitHub Desktop.
Garrysmod Cached Web Material
local mats = {}
function GetWebMaterial( url, callback )
local fileName = util.CRC(url)
if mats[fileName] then
return mats[fileName]
end
if file.Exists( fileName .. ".txt", "DATA" ) then
local mat = Material( "../data/" .. fileName .. ".txt\n.png" )
mats[fileName] = mat
callback(mat)
else
http.Fetch( url,
function()
file.Write( fileName .. ".txt", body )
local mat = Material( "../data/" .. fileName .. ".txt\n.png" )
mats[fileName] = mat
callback(mat)
end,
function()end
);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment