Using SpawnIcons

From GMod Wiki

(Difference between revisions)
Jump to: navigation, search
(Also see)
m (The rest of the wiki uses 'See Also'.)
 
Line 45: Line 45:
   output =  [[Image:Fridge.jpg]]| }}
   output =  [[Image:Fridge.jpg]]| }}
-
==Also see==
+
==See Also==
*[[Derma_Controls:DModelPanel|DModelPanel]]
*[[Derma_Controls:DModelPanel|DModelPanel]]
*[[P.SpawnIcon]]
*[[P.SpawnIcon]]

Latest revision as of 11:55, 21 September 2011

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


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox