Using SpawnIcons

From GMod Wiki

Revision as of 21:36, 20 September 2011 by [KOTL] Fullmetal (Talk | contribs)
Jump to: navigation, search

Using SpawnIcons

Spawn icons are actually really easy to work with. Here is some code that i stumbled upon quite a while ago now. It's probably not the best way to to it but it works perfectly

Examples

DescriptionCreate a small spawnmenu from a table of models
Used onNewerClient.png
Code
 
function fridge()
        local food = {}
 
        food[1] = "models/props_junk/garbage_milkcarton002a.mdl"
	food[2] = "models/props_junk/PopCan01a.mdl"
	food[3] = "models/props_junk/garbage_takeoutcarton001a.mdl"
	food[4] = "models/props_junk/watermelon01.mdl"
	food[5] = "models/props_junk/garbage_metalcan001a.mdl"
	food[6] = "models/props_lab/box01a.mdl"
	food[7] = "models/props_lab/box01b.mdl"
 
        local frame = vgui.Create("DFrame")
	local IconList = vgui.Create( "DPanelList", frame ) 
 
	frame:Center()
	frame:SetSize(220,200)
	frame:SetTitle("Fridge")
	frame:MakePopup()
 
 	IconList:EnableVerticalScrollbar( true ) 
 	IconList:EnableHorizontal( true ) 
 	IconList:SetPadding( 4 ) 
	IconList:SetPos(10,30)
	IconList:SetSize(200, 160)
 
	for k,v in pairs(food) do
	local icon = vgui.Create( "SpawnIcon", IconList ) 
	icon:SetModel( v )
 	IconList:AddItem( icon )
	icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("gm_spawn", v) end 
	end 	
end
 
OutputFridge.jpg


Also see

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox