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

Custom entity fields[edit]

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

Example with all fields[edit]

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

DarkRP.createEntity("Example entity", {
    ent = "money_printer",
    model = "models/props_c17/consolebox01a.mdl",
    price = 1000,
    max = 2,
    cmd = "buyexample",

    -- The following fields are OPTIONAL. If you do not need them, or do not need to change them from their defaults, REMOVE them.
    allowed = {TEAM_GUN, TEAM_MOB},
    customCheck = function(ply) return ply:GetUserGroup() == "donator" end,
    CustomCheckFailMsg = function(ply, entTable) return "You need to be a donator to buy this entity!" end,
    getPrice = function(ply, price) return ply:GetUserGroup() == "donator" and price * 0.9 or price end,
    getMax = function(ply) return ply:GetUserGroup() == "donator" and 10 or 2 end,
    spawn = function(ply, tr, tblEnt) return ents.Create("prop_physics") end, -- function to override spawning mechanics. MUST return an entity!
    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.
    allowTools = false, -- Whether players (including superadmins!) are allowed to use other tools than just remover. Defaults to false

Field explanations[edit]

ent (required)

The entity class name to spawn when the player buys this entity.

model (required)

The model the entity should use

price (required if getPrice field is not given)

The price of the entity.

max (required if getMax field is not given)

Sets the maximum of amount of these entities a player can buy.

Set this to 0 if you want no limit.

cmd (required)

What do you have to enter in chat to buy this entity?
Example: type /buyexample in chat to buy the example entity.

cmd = "buyexample"

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


The teams allowed to buy this entity.
If this field is not set then all jobs can buy the entity.


See here for an example with donator jobs.


Custom message when someone tries and fails to get the entity. Can be either a string or a function(ply, entTable).
See here.

getPrice (required if price field is not given)

Set this field to a function that returns the price. This is handy if you want the price to change under certain conditions (eg. for donators)
This function gets called with two arguments:

  • The player buying the entity.
  • The price set in the price field, if any.

Because the price field gets passed into the function, this getPrice field can be used in conjunction with the price field. This is handy if you want to apply a multiplier to the price. Do note that you should always return a value for all possible situations, even if it is just the price argument without modification, as this function will override the price field.

getPrice = function(ply, price) return ply:GetNWString("usergroup") == "donator" and price * 0.9 or price end

getMax (required if max field is not given)

Set this field to a function that returns the maximum amount of entities a player can buy. This is handy if you want the max to change under certain conditions (eg. for donators).

This function gets called with one argument: the player buying the entity.

Returning 0 from this function equates to infinite.

If both max and getMax are specified then getMax will take priority.


Use this to override spawn functionality. Use this when creating the entity is not a straightforward task. This function MUST return an entity!


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.


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