Difference between revisions of "DarkRP:Categories"

From Official DarkRP Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
{{TOC right}}
 
{{TOC right}}
 
DarkRP 2.6.1 comes with quite a big change in the default F4 menu: categories. This page explains how to create categories, how to use them and how to change the categories of default items.
 
DarkRP 2.6.1 comes with quite a big change in the default F4 menu: categories. This page explains how to create categories, how to use them and how to change the categories of default items.
Note: Categories do '''NOT''' work for custom F4 menus '''unless''' the authors of these F4 menus explicitly add support for them. Until then the categories will ''NOT'' break those F4 menus.
+
 
 +
'''Note:''' Categories do '''NOT''' work for custom F4 menus '''unless''' the authors of these F4 menus explicitly add support for them. Until then the categories will ''NOT'' break those F4 menus.
  
 
= Creating categories =
 
= Creating categories =
Line 33: Line 34:
  
 
= How to use categories =
 
= How to use categories =
 +
Custom jobs, vehicles, entities, shipments and the lot now have two fields: category and sortOrder. They are explained below
 +
 +
'''NOTE: The category of ALL jobs/shipments/entities/etc. will be set to "Other" UNLESS you change it!'''
 +
 +
'''category'''
 +
<div style="margin-left: 16px; margin-bottom: 8px;">
 +
The category it belongs to in the F4 menu.
 +
NOTE: This will throw an error if the category doesn't exist!
 +
</div>
 +
 +
'''sortOrder'''
 +
<div style="margin-left: 16px; margin-bottom: 8px;">
 +
Location of the job/entity/... 'within' the category. Lower number means more on top of the list. By default this is set 100.
 +
</div>
 +
 +
Here's an example with the gun dealer job. Note how both category and sortOrder are set at the bottom. Also mind the comma that's been added after the hasLicense line to accomodate for the new lines.
 +
 +
It's good practice to add a comma even after the last item. It helps to prevent quite a few "missing comma" errors.
 +
{{Code|1=
 +
TEAM_GUN = DarkRP.createJob("Gun Dealer", {
 +
color = Color(255, 140, 0, 255),
 +
model = "models/player/monk.mdl",
 +
description = [[A Gun Dealer is the only person who can sell guns to other people.
 +
Make sure you aren't caught selling illegal firearms to the public! You might get arrested!]],
 +
weapons = {},
 +
command = "gundealer",
 +
max = 2,
 +
salary = GAMEMODE.Config.normalsalary,
 +
admin = 0,
 +
vote = false,
 +
hasLicense = false,
 +
category = "Citizens",
 +
sortOrder = 100,
 +
})
 +
}}
 +
 +
Here's another example with the drug lab entity. Note how adding the category and sortOrder happens in exactly the same way as in the custom job.
 +
 +
{{Code|1=
 +
DarkRP.createEntity("Gun lab", {
 +
ent = "gunlab",
 +
model = "models/props_c17/TrapPropeller_Engine.mdl",
 +
price = 500,
 +
max = 1,
 +
cmd = "buygunlab",
 +
allowed = TEAM_GUN,
 +
category = "Other",
 +
sortOrder = 90,
 +
})
 +
}}
 +
 +
 +
Categories apply to:
 +
* jobs
 +
* entities
 +
* shipments
 +
* weapons
 +
* vehicles
 +
* ammo
  
 +
And all are done in the same way.
 
= Changing categories of default items =
 
= Changing categories of default items =

Revision as of 20:43, 21 March 2015


DarkRP 2.6.1 comes with quite a big change in the default F4 menu: categories. This page explains how to create categories, how to use them and how to change the categories of default items.

Note: Categories do NOT work for custom F4 menus unless the authors of these F4 menus explicitly add support for them. Until then the categories will NOT break those F4 menus.

Creating categories

There's a file in the DarkRPmod: 'lua/darkrp_customthings/categories.lua'. It might be that you don't have this file in your own DarkRPMod. In that case you can download it here:

https://github.com/FPtje/darkrpmodification/blob/master/lua/darkrp_customthings/categories.lua

Categories look like this:

DarkRP.createCategory{
	name = "Citizens", -- The name of the category.
	categorises = "jobs", -- What it categorises. MUST be one of "jobs", "entities", "shipments", "weapons", "vehicles", "ammo".
	startExpanded = true, -- Whether the category is expanded when you open the F4 menu.
	color = Color(0, 107, 0, 255), -- The color of the category header.
	canSee = function(ply) return true end, -- OPTIONAL: whether the player can see this category AND EVERYTHING IN IT.
	sortOrder = 100, -- OPTIONAL: With this you can decide where your category is. Low numbers to put it on top, high numbers to put it on the bottom. It's 100 by default.
}

Feel free to copy the above category, or the one below (which is without the explanation) into your categories.lua. Make sure to put it under the line at the bottom of the file.

DarkRP.createCategory{
	name = "Citizens",
	categorises = "jobs",
	startExpanded = true,
	color = Color(0, 107, 0, 255),
	canSee = function(ply) return true end,
	sortOrder = 100,
}

How to use categories

Custom jobs, vehicles, entities, shipments and the lot now have two fields: category and sortOrder. They are explained below

NOTE: The category of ALL jobs/shipments/entities/etc. will be set to "Other" UNLESS you change it!

category

The category it belongs to in the F4 menu. NOTE: This will throw an error if the category doesn't exist!

sortOrder

Location of the job/entity/... 'within' the category. Lower number means more on top of the list. By default this is set 100.

Here's an example with the gun dealer job. Note how both category and sortOrder are set at the bottom. Also mind the comma that's been added after the hasLicense line to accomodate for the new lines.

It's good practice to add a comma even after the last item. It helps to prevent quite a few "missing comma" errors.

TEAM_GUN = DarkRP.createJob("Gun Dealer", {
	color = Color(255, 140, 0, 255),
	model = "models/player/monk.mdl",
	description = [[A Gun Dealer is the only person who can sell guns to other people.
		Make sure you aren't caught selling illegal firearms to the public! You might get arrested!]],
	weapons = {},
	command = "gundealer",
	max = 2,
	salary = GAMEMODE.Config.normalsalary,
	admin = 0,
	vote = false,
	hasLicense = false,
	category = "Citizens",
	sortOrder = 100,
})

Here's another example with the drug lab entity. Note how adding the category and sortOrder happens in exactly the same way as in the custom job.

DarkRP.createEntity("Gun lab", {
	ent = "gunlab",
	model = "models/props_c17/TrapPropeller_Engine.mdl",
	price = 500,
	max = 1,
	cmd = "buygunlab",
	allowed = TEAM_GUN,
	category = "Other", 
	sortOrder = 90,
})


Categories apply to:

  • jobs
  • entities
  • shipments
  • weapons
  • vehicles
  • ammo

And all are done in the same way.

Changing categories of default items