Last active
August 29, 2015 14:13
-
-
Save Donkie/7842dabaaded43707a0c to your computer and use it in GitHub Desktop.
Garrysmod Cached Web Material
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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