Difference between revisions of "DarkRP:CustomJobFields"

From Official DarkRP Wiki
Jump to navigation Jump to search
Line 36: Line 36:
 
cook = false,
 
cook = false,
 
hobo = false,
 
hobo = false,
 +
        category = "Other", -- The name of the category it is in. Note: the category must be created!
 +
        sortOrder = 100, -- The position of this thing in its category. Lower number means higher up.
  
 
CanPlayerSuicide = function(ply) return false end,
 
CanPlayerSuicide = function(ply) return false end,
Line 209: Line 211:
 
<div style="margin-left: 16px; margin-bottom: 8px;">
 
<div style="margin-left: 16px; margin-bottom: 8px;">
 
The ammo people spawn with.
 
The ammo people spawn with.
 +
 +
'''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! Please see [[DarkRP:Categories|the categories page]].
 +
 +
'''sortOrder'''
 +
<div style="margin-left: 16px; margin-bottom: 8px;">
 +
Location in the category. Lower number means more on top of the list. By default this is set 100.
 
</div>
 
</div>
  

Revision as of 20:01, 21 March 2015

This page is available in the following languages:
Данная версия страницы доступна на следующих языках:
Jarvis-flag 8010.png English | Russia-flag.png Русский


Custom job fields

You can create custom jobs in DarkRP. However, there are many things to fiddle with. This page explains every single "field".

Video Tutorials

Check out these two tutorials if you're new to creating DarkRP servers: DarkRP 2.5 Tutorial: Adding custom jobs to your setup and DarkRP 2.5 Tutorial: Custom Jobs Syntax. They cover the essentials of modding and creating custom jobs.

Example with all fields

Here's an example with all available fields filled in:

TEAM_EXAMPLE = DarkRP.createJob("Example team", {
	color = Color(255, 255, 255, 255),
	model = {
		"models/player/Group03/Female_01.mdl",
		"models/player/Group03/Female_02.mdl"
		},
	description = [[This text will serve as the description of
		this team.]],
	weapons = {"weapon_p2282"},
	command = "example",
	max = 0.7, -- at most 70% of the players can have this job. Set to a whole number to set an absolute limit.
	salary = 45,
	admin = 0,
	vote = false,
	hasLicense = false,
	NeedToChangeFrom = TEAM_CITIZEN,
	customCheck = function(ply) return ply:getDarkRPVar("money") > 10000 end,
	CustomCheckFailMsg = "You don't have enough money!", -- alternative: CustomCheckFailMsg = function(ply, jobTable) return ply:getDarkRPVar("money") < 5000 and "You're piss poor" or "You don't have enough money!" end,
	modelScale = 1.2,
	maxpocket = 20,
	maps = {"rp_downtown_v2", "gm_construct"},
	candemote = false,
	mayor = false,
	chief = false,
	medic = false,
	cook = false,
	hobo = false,
        category = "Other", -- The name of the category it is in. Note: the category must be created!
        sortOrder = 100, -- The position of this thing in its category. Lower number means higher up.

	CanPlayerSuicide = function(ply) return false end,
	PlayerCanPickupWeapon = function(ply, weapon) return true end,
	PlayerDeath = function(ply, weapon, killer) end,
	PlayerLoadout = function(ply) return true end,
	PlayerSelectSpawn = function(ply, spawn) end,
	PlayerSetModel = function(ply) return "models/player/Group03/Female_02.mdl" end,
	PlayerSpawn = function(ply) end,
	PlayerSpawnProp = function(ply, model) end,
	RequiresVote = function(ply, job) for k,v in pairs(player.GetAll()) do if IsValid(v) and v:IsAdmin() then return false end end return true end, -- People need to make a vote when there is no admin around
	ShowSpare1 = function(ply) end,
	ShowSpare2 = function(ply) end,
	canStartVote = function(ply) return ply:Distance(SomeNPC) < 200 end,
	canStartVoteReason = "You must be close to some NPC", -- alternative: canStartVoteReason = function(ply, jobTable) return ply:Distance(SomeNPC) > 5000 and "You're miles away from some NPC" or "You must be close to some NPC" end,
        buttonColor = Color(255, 255, 255, 255), -- The color of the button in the F4 menu
        label = "Super job", -- Optional: the text on the button in the F4 menu
        ammo = {
		["pistol"] = 60,
	},
})

Field explanations

color (required)

The color of the team in tab and other places.

model (required)

The model of the team. This can either be a string or a table of strings. Two examples: A string, players who have this job have ONE model, namely the one given in the string:

model = "models/player/Group03/Female_01.mdl"

A table, the model of the player holding this job is randomly chosen from the list of given models:

model = {
		"models/player/Group03/Female_01.mdl",
		"models/player/Group03/Female_02.mdl"
	}

description (required)

The description of a job shows up in the F4 menu when selecting the job. Describe what your job does and what the use of it is.

weapons (required)

The list of weapons people with this job spawn with (besides the default weapons) The following example means that the job spawns with the weapons in the list:

weapons = {"arrest_stick", "unarrest_stick", "weapon_deagle2", "stunstick", "door_ram", "weaponchecker"}

command (required)

What do you have to enter in chat to get this job? example: type /example in chat to get the example job

command = "example"

If the job requires voting, a command "/voteexample" is added.

Note: The "/" at the start of the command should be omitted.

max (required)

How many people can have this job at any given time. Set to a number between 0 and 1 to make it a percentage. E.g. max = 0.3 means at most 30% of the players can have this job. Set to a whole number to set an absolute limit.

salary (required)

The salary this job gets.

admin (required)

What (admin) access you need to get this job.

admin = 0 -- anyone can get this job
admin = 1 -- only admins can get this job
admin = 2 -- only superadmins can get this job

If you want to customize this further (with donators, moderators and whatnot), look at customCheck (scroll down)

vote

Do players need to create a vote to get this job? true for yes, false for no.

hasLicense

Does this job get a gun license for free? true for yes, false for no. It's useful to give the cops gun licenses.

NeedToChangeFrom

You can only get this job if you had a specific other job first. Example: You can only become a chief of police when you're already a CP:

NeedToChangeFrom = TEAM_POLICE

Example 2: You can only become a mayor if you're either a CP or a chief

NeedToChangeFrom = {TEAM_CHIEF, TEAM_POLICE}

customCheck

See here for an example with donator jobs.

CustomCheckFailMsg

Custom message when someone tries and fails to get the job. See here.

modelScale

How big are the players that have this job?

modelScale = 1 -- the default size
modelScale = 1.2 -- 120% of the default size
modelScale = 0.9 -- 90% of the default size.

Don't make it too big or too small, people will get trouble with jumping and crouching.

maxpocket

The amount of items that can fit in the pocket of people having this job. If not set, it will revert to the setting in config.lua, which is set to 10 by default.

maps

In what maps this job will be available. This is just a list of maps.

candemote

Can people who have this job be demoted? By default hobo's and citizens cannot be demoted because it has no use to demote them.

mayor

People with this job can do things the mayor can do (create a lottery, accept warrants etc.)

chief

People with this job can do things the chief can do.

medic

People with this job can do things the medic can do.

cook

People with this job can do things the cook can do.

hobo

People with this job can do things the hobo can do.

ammo

The ammo people spawn with.

category

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

sortOrder

Location in the category. Lower number means more on top of the list. By default this is set 100.

More advanced fields

These fields are all implemented by using a function. If you're thinking of editing DarkRP files (especially sv_gamemode_functions.lua!) first look at these functions. Always try to avoid having to edit DarkRP files.

CanPlayerSuicide

A function that decides whether players with this job can commit suicide. Arguments: Player ply

PlayerCanPickupWeapon

A function that decides whether players with this job can pick up a certain weapon Arguments: Player ply, Entity weapon

PlayerDeath

Called when a player dies Arguments: Player ply, Entity weapon, Entity killer

PlayerLoadout

Called when a player gets his weapons. Return true to prevent him from getting his default weapons! Arguments: Player ply

PlayerSelectSpawn

Called when a spawn is selected for this player. Arguments: Player ply, Entity spawn

PlayerSetModel

A function that decides what the model should be. ALWAYS return a model (string) if you implement this function. Arguments: Player ply

PlayerSpawn

Called when a player spawns Arguments: Player ply

PlayerSpawnProp

Called when a player attempts to spawn a prop Arguments: Player ply, string model

RequiresVote

Decides whether the player needs to make a vote to get the job. Note: overrides the vote field! (the vote field will have no effect when this is set)
Arguments: Player ply
Number team (DON'T use TEAM_BLA variables, that won't work!)
Example:

DescriptionPeople need to make a vote if there are three or more people who have this job. People DON'T need to make a vote if there are fewer than three people with this job.
Code
RequiresVote = function(ply, job) return #team.GetPlayers(job) >= 3 end

Another:

DescriptionVIPS can skip the vote
Code
RequiresVote = function(ply, job) return ply:GetNWString("usergroup") ~= "vip" end


ShowSpare1

Called when a player presses the F1 key Arguments: Player ply

ShowSpare2

Called when a player presses the F2 key Arguments: Player ply