Difference between revisions of "DarkRP:CustomEntityFields"

From Official DarkRP Wiki
Jump to navigation Jump to search
(Example with all fields)
(Field explanations)
Line 60: Line 60:
 
'''CustomCheckFailMsg'''
 
'''CustomCheckFailMsg'''
 
<div style="margin-left: 16px; margin-bottom: 8px;">
 
<div style="margin-left: 16px; margin-bottom: 8px;">
Custom message when someone tries and fails to get the entity.<br>
+
Custom message when someone tries and fails to get the entity. Can be either a string or a function(ply, entTable).<br>
 
See [[Donator_Job_configuration#Custom_fail_messages|here]].
 
See [[Donator_Job_configuration#Custom_fail_messages|here]].
 
</div>
 
</div>

Revision as of 22:06, 26 December 2014

Custom entity fields

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

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",
	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,
})

Field explanations

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.

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.

allowed

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

customCheck

See here for an example with donator jobs.

CustomCheckFailMsg

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.
Example:

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.

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