Garry's Mod Wiki

ContentIcon

Description

The spawn icon used for SWEPs and other SENTs, commonly featured as part of the spawn menu. Do note that at least one of your ContentIcon's parents must either be an EditablePanel or derived from it (like a DFrame, for example), else it won't be able to focus and thus be unclickable.

This control only exists in Sandbox derived gamemodes.

Parent

Derives from DButton.

Methods

table ContentIcon:GetColor()
Returns the color set by ContentIcon:SetColor
string ContentIcon:GetContentType()
Returns the content type used to save and restore the content icon in a spawnlist.
table ContentIcon:GetNPCWeapon()
Returns a table of weapon classes for the content icon with "NPC" content type to be randomly chosen from when user tries to spawn the NPC.
string ContentIcon:GetSpawnName()
Returns the internal "name" for the content icon, usually a class name for an entity.
ContentIcon:OpenMenu()
A hook for override, by default does nothing. Called when user right clicks on the content icon, you are supposed to open a DermaMenu here with additional options.
ContentIcon:SetAdminOnly( boolean adminOnly )
Sets whether the content item is admin only. This makes the icon to display a admin icon in the top left corner of the icon.
ContentIcon:SetColor( table clr )
Sets the color for the content icon. Currently is not used by the content icon panel.
ContentIcon:SetContentType( string type )
Sets the content type used to save and restore the content icon in a spawnlist.
ContentIcon:SetMaterial( string path )
Sets the material to be displayed as the content icon.
ContentIcon:SetName( string name )
Sets the tool tip and the "nice" name to be displayed by the content icon.
ContentIcon:SetNPCWeapon( table weapons )
Sets a table of weapon classes for the content icon with "NPC" content type to be randomly chosen from when user tries to spawn the NPC.
ContentIcon:SetSpawnName( string name )
Sets the internal "name" for the content icon, usually a class name for an entity.

Example

Creates a button to spawn one or multiple pistols on top of a custom DFrame.

local frame = vgui.Create( "DFrame" ) frame:SetSize( 400, 200 ) frame:Center() frame:SetTitle( "Secret SWEP Spawn Menu" ) frame:MakePopup() local icon = vgui.Create( "ContentIcon", frame ) icon:Center() icon:SetMaterial( "entities/weapon_pistol.png" ) icon:SetName( "Pistol" ) icon.DoClick = function() RunConsoleCommand( "gm_spawnswep", "weapon_pistol" ) end icon.OpenMenu = function() local menu = DermaMenu() menu:AddOption( "Copy to clipboard", function() SetClipboardText( "weapon_pistol" ) end ) menu:AddOption( "Spawn 5", function() for i=1,5 do RunConsoleCommand( "gm_spawnswep", "weapon_pistol" ) end end ) menu:AddOption( "Spawn 10", function() for i=1,10 do RunConsoleCommand( "gm_spawnswep", "weapon_pistol" ) end end ) menu:Open() end
Output:

Page Links


Special Pages


Wikis

?

Render Time: 91ms

DB GetPage 45
Generate Html 20
SaveChanges (1) 11
Render Body 0
Render Sidebar 12