Simple script demonstrating how to download Steam avatars and generate a Material from them using clientside GLua.
This script is particularly stringent and applies a lot of defensive programming techniques.
Avatar images are cached for 1 day and 1 server session.
This code could be combined with Circles! to produce a textured circular avatar.
getAvatarMaterial(LocalPlayer():SteamID64(), function(mat)
print("Downloaded", mat)
end)
local avatar, downloaded = ( Material("vgui/avatar_default") )
hook.Add("HUDPaint", "showMyAvatar", function()
if not downloaded then
downloaded = true
-- NEVER call this every frame unless you are planning on DDoSing Steam.
getAvatarMaterial(LocalPlayer():SteamID64(), function(mat)
avatar = mat
end)
end
surface.SetDrawColor(255, 255, 255)
surface.SetMaterial(avatar)
surface.DrawTexturedRect(50, 50, 128, 128)
end)
include("vgui-element.lua")
local avatar = vgui.Create("AvatarMaterial")
avatar:SetSize(128, 128)
avatar:SetPos(50, 200)
avatar:SetSteamID64(LocalPlayer():SteamID64())
--avatar:SetPlayer(LocalPlayer())