Garry's Mod Wiki

Revision Difference

Panel:SetSteamID#546065

<function name="SetSteamID" parent="Panel" type="classfunc"> <description>Used by <page>AvatarImage</page> panels to load an avatar by its 64-bit Steam ID (community ID).</description> <realm>Client</realm> <args> <arg name="steamid" type="string">The 64bit SteamID of the player to load avatar of</arg> <arg name="size" type="number">The size of the avatar to use. Acceptable sizes are 32, 64, 184.</arg> </args> </function> <example> <description>Creates a grid of randomly generated Steam avatars which link to their corresponding Steam user pages.</description> <code> -- Returns a random 64-bit Steam ID between STEAM_0:0:1 and STEAM_0:1:100000000 function GetRandomSteamID() return "7656119"..tostring(7960265728+math.random(1, 200000000)) end -- Create the Steam User Grid -- Arg1: the size of each avatar -- Arg2: the size to load each avatar (16, 32, 64, 84, 128, 184) function CreateSteamUserGrid(av_size, av_res) -- Remove this block of code if you do not mind loading thousands of avatars if(av_size < 64) then Error("Avatar size cannot be less than 64 square pixels.\n") return end -- Delete existing grid if(SteamUserGrid) then SteamUserGrid:Remove() end -- The amount of avatars we can fit width-wise and height-wise local w_count = math.floor(ScrW()/av_size) local h_count = math.floor((ScrH()-25)/av_size) -- 25 = frame header size -- Container panel SteamUserGrid = vgui.Create("DFrame") SteamUserGrid:SetSize(w_count*av_size, (h_count*av_size)+25) SteamUserGrid:Center() SteamUserGrid:SetTitle("Randomly Generated Grid of Steam Users") SteamUserGrid:MakePopup() -- Loop variables local avatar, random_id -- Create enough avatars to fill up screen without overflowing for i = 0, (w_count*h_count)-1 do random_id = GetRandomSteamID() -- Add avatar to container panel avatar = vgui.Create("AvatarImage", SteamUserGrid) -- Layout the avatars in a grid avatar:SetPos((i%w_count)*av_size, 25+math.floor(i/w_count)*av_size) -- Load the avatar image avatar:SetSteamID(random_id, av_res) avatar:SetSize(av_size, av_size) ⤶ avatar.id = random_id⤶ -- Open user's Steam page on avatar click avatar.OnMousePressed = function(self) local url = "http://steamcommunity.com/profiles/"..random_id⤶ local url = "http://steamcommunity.com/profiles/" .. self.id⤶ gui.OpenURL(url) end end end </code> <output> `CreateSteamUserGrid(64, 64)` <image src="AvatarImage_SetSteamID_example1.png"/> The white question mark avatars mean no custom icon used or the user hasn't set up a community profile. The blue question mark avatars mean the user doesn't exist. </output> </example>