-
-
Save Codingale/69c9be291531125c23d891fb15366c56 to your computer and use it in GitHub Desktop.
This is a simple Garry's Mod helper function to hot-load images from a web URL for use in your rendering operations.
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 WebMaterials = {} | |
function surface.GetURL(url, w, h, time) | |
if not url or not w or not h then return Material("error") end | |
if WebMaterials[url] then return WebMaterials[url] end | |
local WebPanel = vgui.Create( "HTML" ) | |
WebPanel:SetAlpha( 0 ) | |
WebPanel:SetSize( tonumber(w), tonumber(h) ) | |
WebPanel:OpenURL( url ) | |
WebPanel.Paint = function(self) | |
if not WebMaterials[url] and self:GetHTMLMaterial() then | |
WebMaterials[url] = self:GetHTMLMaterial() | |
self:Remove() | |
end | |
end | |
timer.Simple( 1 or tonumber(time), function() if IsValid(WebPanel) then WebPanel:Remove() end end ) -- In case we do not render | |
return Material("error") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment