Garry's Mod Wiki

Revision Difference

GM:SpawniconGenerated#517390

<function name="SpawniconGenerated" parent="GM" type="hook"> <ishook>yes</ishook> <description>Called when spawn icon is generated.</description> <realm>Client</realm> <predicted>No</predicted> <args> <arg name="lastmodel" type="string">File path of previously generated model.</arg> <arg name="imagename" type="string">File path of the generated icon.</arg> <arg name="modelsleft" type="number">Amount of models left to generate.</arg> </args> </function> <example> <description>That's how it is used in **garrysmod/lua/includes/gui/icon_progress.lua** for show progress of generating icons</description> <code> local g_Progress = nil hook.Add( "SpawniconGenerated", "SpawniconGenerated", function( lastmodel, imagename, modelsleft ) if ( !IsValid( g_Progress ) ) then g_Progress = vgui.Create( "DPanel" ) g_Progress:SetSize( 64+10, 64+10+20 ) g_Progress:SetBackgroundColor( Color( 0, 0, 0, 100 ) ) g_Progress:SetDrawOnTop( true ) g_Progress:DockPadding( 5, 0, 5, 5 ) g_Progress.Think = function() if ( SysTime() - g_Progress.LastTouch &amp;lt; 3 ) then return end g_Progress:Remove() g_Progress.LastTouch = SysTime() end local label = g_Progress:Add( "DLabel" ) label:Dock( BOTTOM ) label:SetText( "remaining" ) label:SetTextColor( Color( 255, 255, 255, 255 ) ) label:SetExpensiveShadow( 1, Color( 0, 0, 0, 200 ) ) label:SetContentAlignment( 5 ) label:SetHeight( 14 ) label:SetFont( "DefaultSmall" ) g_Progress.Label = g_Progress:Add( "DLabel" ) g_Progress.Label:Dock( BOTTOM ) g_Progress.Label:SetTextColor( Color( 255, 255, 255, 255 ) ) g_Progress.Label:SetExpensiveShadow( 1, Color( 0, 0, 0, 200 ) ) g_Progress.Label:SetContentAlignment( 5 ) g_Progress.Label:SetFont( "DermaDefaultBold" ) g_Progress.Label:SetHeight( 14 ) g_Progress.icon = vgui.Create( "DImage", g_Progress ) g_Progress.icon:SetSize( 64, 64 ) g_Progress.icon:Dock( TOP ) end g_Progress.LastTouch = SysTime() imagename = imagename:Replace( "materials\\", "" ) imagename = imagename:Replace( "materials/", "" ) g_Progress.icon:SetImage( imagename ) g_Progress:AlignRight( 10 ) g_Progress:AlignBottom( 10 ) g_Progress.Label:SetText( modelsleft ) end ) </code> <output></output>⤶ <output><image src="spawnicon_progress.png"/></output>⤶ </example>