Garry's Mod Wiki

spawnmenu.AddPropCategory

  spawnmenu.AddPropCategory( string classname, string name, table contents, string icon, number id = 1000, number parentID = 0, string needsApp = "" )

Description

Used to add addon spawnlists to the spawnmenu tree. This function should be called within SANDBOX:PopulatePropMenu.

Addon spawnlists will not save to disk if edited.

You should never try to modify player customized spawnlists!

Arguments

1 string classname
A unique classname of the list.
2 string name
The name of the category displayed to the player, e.g. Comic Props.
3 table contents
A table of entries for the spawn menu. It must be numerically indexed.

Each member of the table is a sub-table containing a type member, and other members depending on the type.

New content types can be added via spawnmenu.AddContentType.

string type Description Other members
"header" a simple header for organization string text - The text that the header will display
"model" spawns a model where the player is looking string model - The path to the model file
number skin - The skin for the model to use (optional)
string body - The bodygroups for the model (optional)
number wide - The width of the spawnicon (optional)
number tall - The height of the spawnicon (optional)
"entity" spawns an entity where the player is looking
(appears in the Entities tab by default)
string spawnname - The filename of the entity, for example "sent_ball"
string nicename - The name of the entity to display
string material - The icon to display, this should be set to entities/[sent_name].png
boolean admin - Whether the entity is only spawnable by admins (optional)
"vehicle" spawns a vehicle where the player is looking
(appears in the Vehicles tab by default)
string spawnname - The filename of the vehicle
string nicename - The name of the vehicle to display
string material - The icon to display
boolean admin - Whether the vehicle is only spawnable by admins (optional)
"npc" spawns an NPC where the player is looking
(appears in the NPCs tab by default)
string spawnname - The spawn name of the NPC
string nicename - The name to display
string material - The icon to display
table weapon - A table of potential weapons (each a string) to give to the NPC.
When spawned, one of these will be chosen randomly each time.
boolean admin - Whether the NPC is only spawnable by admins (optional)
"weapon" When clicked, gives the player a weapon;
When middle-clicked, spawns a weapon where the player is looking
(appears in the Weapons tab by default)
string spawnname - The spawn name of the weapon
string nicename - The name to display
string material - The icon to display
boolean admin - Whether the weapon is only spawnable by admins (optional)
4 string icon
The icon to use in the tree.
5 number id = 1000
The unique ID number for the spawnlist category. Used to make sub categories. See "parentID" parameter below. If not set, it will be automatically set to ever increasing number, starting with 1000.
6 number parentID = 0
The unique ID of the parent category. This will make the created category a subcategory of category with given unique ID. 0 makes this a base category (such as Builder).
7 string needsApp = ""
The needed game for this prop category, if one is needed. If the specified game is not mounted, the category isn't shown. This uses the shortcut name, e.g. cstrike, and not the Steam AppID.

Example

Create a spawn menu with two icons for each type

hook.Add("PopulatePropMenu", "Add Two Of Each", function() local contents = {} -- Props table.insert( contents, { type = "header", text = "Props" } ) table.insert( contents, { type = "model", model = "models/props_c17/oildrum001.mdl" } ) table.insert( contents, { type = "model", model = "models/props_wasteland/cargo_container01.mdl", skin = 1, wide = 128, tall = 64 } ) -- Entities table.insert( contents, { type = "header", text = "Entities" } ) table.insert( contents, { type = "entity", spawnname = "sent_ball", nicename = "Bouncy Ball", material = "entities/sent_ball.png" } ) table.insert( contents, { type = "entity", spawnname = "combine_mine", nicename = "Hopper Mine", material = "entities/combine_mine.png" } ) -- Vehicles table.insert( contents, { type = "header", text = "Vehicles" } ) table.insert( contents, { type = "vehicle", spawnname = "Airboat", nicename = "Half-Life 2 Airboat", material = "entities/Airboat.png" } ) table.insert( contents, { type = "vehicle", spawnname = "Chair_Office2", nicename = "Executive's Chair", material = "entities/Chair_Office2.png" } ) -- NPCs table.insert( contents, { type = "header", text = "NPCs" } ) table.insert( contents, { type = "npc", spawnname = "npc_citizen", nicename = "A random citizen", material = "entities/npc_citizen.png", weapon = { "weapon_smg1", "weapon_crowbar" } } ) table.insert( contents, { type = "npc", spawnname = "npc_headcrab", nicename = "Headhumper", material = "entities/npc_headcrab.png" } ) -- Weapons table.insert( contents, { type = "header", text = "Weapons" } ) table.insert( contents, { type = "weapon", spawnname = "weapon_crowbar", nicename = "Crowbar", material = "entities/weapon_crowbar.png", } ) table.insert( contents, { type = "weapon", spawnname = "weapon_smg1", nicename = "SMG", material = "entities/weapon_smg1.png", } ) spawnmenu.AddPropCategory( "TwoOfEach", "Two of each type", contents, "icon16/box.png" ) end )
Output: