spawnmenu.AddPropCategory

From Garry's Mod
Revision as of 10:19, 12 May 2019 by Robotboy655 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
 spawnmenu.AddPropCategory( )

Contents

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.

WARNING

You should never try to modify player customized spawnlists!

Arguments

string classname

A unique classname of the list.

Arguments

string name

The name of the category displayed to the player, e.g. Comic Props.

Arguments

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.

  • string type - "header" - a simple header for organization
    • string text - The text that the header will display
  • string type - "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)
  • string type - "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)
  • string type - "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)
  • string type - "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)
  • string type - "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)

Arguments

string icon

The icon to use in the tree.

Arguments

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.

Arguments

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).

Arguments

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.

Examples

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:

AddPropCategory Two of each.jpeg
Personal tools
Navigation