A condition type, such as 'health' or 'steamid', is registered with
Conditions:register_condition and defines how its parameters are chosen in the editor and
how it is checked against a player.
Summary
Hooks
Methods
Hooks
Implements hook OnPluginsLoaded
Runs the RegisterConditions hook so that plugins can register their conditions.
Methods
Checks whether the player satisfies a condition tree. Serverside only. A list of nodes passes if at least one of its nodes does (OR). A node passes if its own check passes and its list of child nodes, unless empty, passes as well (AND). An empty top-level list never passes, and neither does a node whose condition type is not registered, such as one saved by a plugin that is no longer loaded.
-- A specific player, or anyone with more than 50 health who holds a crowbar.
local allowed = Conditions:check(target, {
{ id = 'steamid', data = { operator = 'equal', steamid = 'STEAM_0:1:12345' }, childs = {} },
{ id = 'health', data = { operator = 'greater', health = 50 }, childs = {
{ id = 'active_weapon', data = { operator = 'equal', weapon = 'weapon_crowbar' },
childs = {} }
} }
})
Parameters
- target Player
- conditions List condition nodes, each a Map with id, data and childs, as returned by the get_conditions method of the fl_conditions panel
Returns
- Boolean
Returns all registered condition types.
Returns
- Map condition definitions keyed by condition id
Registers a condition type that can be picked in the conditions editor and evaluated with Conditions:check.
Conditions:register_condition('health', {
name = 'condition.health.name', -- phrase displayed in the 'add condition' menu
text = 'condition.health.text', -- phrase of the node, 'Health {operator} {health}'
icon = 'icon16/heart.png',
-- Operator set to pick from: 'equal', 'relational' or 'logical'.
-- Can also be a function(id, data, panel, menu) that sets panel.data.operator.
set_operator = 'relational',
-- Returns the arguments for the 'text' phrase.
get_args = function(panel, data)
local operator = util.operator_to_symbol(panel.data.operator) or ''
local parameter = panel.data.health or ''
return { operator = operator, health = parameter }
end,
-- Serverside. Receives the parameters that were stored in panel.data.
check = function(target, data)
if !data.operator or !data.health then return false end
return util.process_operator(data.operator, target:Health(), data.health)
end,
-- Clientside. Lets the user choose the parameters of the condition.
set_parameters = function(id, data, panel, menu, parent)
Derma_StringRequest(t(data.name), t'condition.health.message', '', function(text)
panel.data.health = tonumber(text)
panel.update()
end)
end
})
Parameters
- id String unique condition id
- data Map condition definition: name, text, icon, set_operator and the get_args(panel, data), check(target, data) and set_parameters(id, data, panel, menu, parent) functions